Fix not working feed display for home settings public view. Modify blog javascript so that we can define how many feed entries we want to display. Change default number of entries to 3 as suggested by Leslie and Chris.
Patch by: Pawel Solyga
--- a/app/soc/content/js/blog-080819.js Mon Nov 17 12:18:09 2008 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/* Copyright 2008 the Melange authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-function BlogPreview(container) {
- this.container_ = container;
-}
-
-BlogPreview.prototype.show = function(url, title, title_link) {
- var feed = new google.feeds.Feed(url);
- var preview = this;
- feed.load(function(result) {
- preview.render_(result, title, title_link);
- });
-}
-
-BlogPreview.prototype.render_ = function(result, title, title_link) {
- if (!result.feed || !result.feed.entries) return;
- while (this.container_.firstChild) {
- this.container_.removeChild(this.container_.firstChild);
- }
-
- var blog = this.createDiv_(this.container_, "blog");
- var header = this.createElement_("h2", blog, "");
- if (!title) {
- title = result.feed.title;
- }
- if (!title_link) {
- title_link = result.feed.link;
- }
- this.createLink_(header, title_link, title);
-
- for (var i = 0; i < result.feed.entries.length; i++) {
- var entry = result.feed.entries[i];
- var div = this.createDiv_(blog, "entry");
- var linkDiv = this.createDiv_(div, "title");
- this.createLink_(linkDiv, entry.link, entry.title);
- if (entry.author) {
- this.createDiv_(div, "author", "Posted by " + entry.author);
- }
- this.createDiv_(div, "snippet", entry.contentSnippet);
- }
-}
-
-BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
- return this.createElement_("div", parent, className, opt_text);
-}
-
-BlogPreview.prototype.createLink_ = function(parent, href, text) {
- var link = this.createElement_("a", parent, "", text);
- link.href = href;
- return link;
-}
-
-BlogPreview.prototype.createElement_ = function(tagName, parent, className,
- opt_text) {
- var div = document.createElement(tagName);
- div.className = className;
- parent.appendChild(div);
- if (opt_text) {
- div.appendChild(document.createTextNode(opt_text));
- }
- return div;
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/content/js/blog-081117.js Mon Nov 17 22:12:34 2008 +0000
@@ -0,0 +1,77 @@
+/* Copyright 2008 the Melange authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function BlogPreview(container) {
+ this.container_ = container;
+}
+
+BlogPreview.prototype.show = function(url, entries_num, title, title_link) {
+ var feed = new google.feeds.Feed(url);
+ var preview = this;
+ feed.setNumEntries(entries_num)
+ feed.load(function(result) {
+ preview.render_(result, title, title_link);
+ });
+}
+
+BlogPreview.prototype.render_ = function(result, title, title_link) {
+ if (!result.feed || !result.feed.entries) return;
+ while (this.container_.firstChild) {
+ this.container_.removeChild(this.container_.firstChild);
+ }
+
+ var blog = this.createDiv_(this.container_, "blog");
+ var header = this.createElement_("h2", blog, "");
+ if (!title) {
+ title = result.feed.title;
+ }
+ if (!title_link) {
+ title_link = result.feed.link;
+ }
+ this.createLink_(header, title_link, title);
+
+ for (var i = 0; i < result.feed.entries.length; i++) {
+ var entry = result.feed.entries[i];
+ var div = this.createDiv_(blog, "entry");
+ var linkDiv = this.createDiv_(div, "title");
+ this.createLink_(linkDiv, entry.link, entry.title);
+ if (entry.author) {
+ this.createDiv_(div, "author", "Posted by " + entry.author);
+ }
+ this.createDiv_(div, "snippet", entry.contentSnippet);
+ }
+}
+
+BlogPreview.prototype.createDiv_ = function(parent, className, opt_text) {
+ return this.createElement_("div", parent, className, opt_text);
+}
+
+BlogPreview.prototype.createLink_ = function(parent, href, text) {
+ var link = this.createElement_("a", parent, "", text);
+ link.href = href;
+ return link;
+}
+
+BlogPreview.prototype.createElement_ = function(tagName, parent, className,
+ opt_text) {
+ var div = document.createElement(tagName);
+ div.className = className;
+ parent.appendChild(div);
+ if (opt_text) {
+ div.appendChild(document.createTextNode(opt_text));
+ }
+ return div;
+}
+
--- a/app/soc/templates/soc/home/public.html Mon Nov 17 12:18:09 2008 +0000
+++ b/app/soc/templates/soc/home/public.html Mon Nov 17 22:12:34 2008 +0000
@@ -14,16 +14,16 @@
{% endcomment %}
{% block scripts %}
-{% if home_settings.feed_url %}
+{% if entity.feed_url %}
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
- <script type="text/javascript" src="/soc/content/js/blog-080819.js"></script>
+ <script type="text/javascript" src="/soc/content/js/blog-081117.js"></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var blog = new BlogPreview(document.getElementById("blog"));
- blog.show("{{ home_settings.feed_url }}");
+ blog.show("{{ entity.feed_url }}", 3);
}
google.setOnLoadCallback(initialize);
@@ -56,7 +56,7 @@
This is the default home page can be edited via Settings.
{% endblock %}
{% endif %}
- {% if home_settings.feed_url %}
+ {% if entity.feed_url %}
<div id="blog"></div>
{% endif %}
{% endblock %}