diff --git a/app/helpers/blog_helper.rb b/app/helpers/blog_helper.rb index 754d385..6d829fe 100644 --- a/app/helpers/blog_helper.rb +++ b/app/helpers/blog_helper.rb @@ -14,4 +14,25 @@ module BlogHelper _('Edit blog') end + def list_posts(user, articles) + pagination = will_paginate(articles, { + :param_name => 'npage', + :prev_label => _('« Newer posts'), + :next_label => _('Older posts »') + }) + content = [] + articles.map{ |i| + css_add = '' + if i.published? || (user==i.profile) + css_add = '-not-published' if !i.published? + content << content_tag('div', display_post(i), :class => 'blog-post' + css_add, :id => "post-#{i.id}") + end + } + content.join("\n") + (pagination or '') + end + + def display_post(article) + article_title(article) + content_tag('p', article.to_html) + + content_tag('p', link_to( number_of_comments(article), article.url.merge(:form => 'opened', :anchor => 'comment_form') ), :class => 'metadata') + end end diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb index 6b3dcbc..7d2155a 100644 --- a/app/helpers/content_viewer_helper.rb +++ b/app/helpers/content_viewer_helper.rb @@ -1,6 +1,7 @@ module ContentViewerHelper include GetText + include BlogHelper def number_of_comments(article) n = article.comments.size @@ -24,37 +25,10 @@ module ContentViewerHelper title end - def list_posts(articles) - pagination = will_paginate(articles, { - :param_name => 'npage', - :page_links => false, - :prev_label => _('Newer posts »'), - :next_label => _('« Older posts') - }) - articles.map{ |i| content_tag('div', display_post(i), :class => 'blog-post', :id => "post-#{i.id}") }.join("\n") + - (pagination or '') - end - - def display_post(article) - article_title(article) + content_tag('p', article.to_html) + - content_tag('p', link_to( number_of_comments(article), article.url.merge(:form => 'opened', :anchor => 'comment_form') ), :class => 'metadata') - end - def article_to_html(article) - content = article.to_html + content = article.to_html(:page => params[:npage]) return self.instance_eval(&content) if content.kind_of?(Proc) - - if article.blog? - children = if article.filter and article.filter[:year] and article.filter[:month] - filter_date = DateTime.parse("#{article.filter[:year]}-#{article.filter[:month]}-01") - article.posts.paginate :page => params[:npage], :per_page => article.posts_per_page, :conditions => [ 'created_at between ? and ?', filter_date, filter_date + 1.month - 1.day ] - else - article.posts.paginate :page => params[:npage], :per_page => article.posts_per_page - end - content + (children.compact.empty? ? content_tag('em', _('(no posts)')) : list_posts(children)) - else - content - end + content end end diff --git a/app/models/article.rb b/app/models/article.rb index 9fbf25f..bcddb18 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -127,7 +127,7 @@ class Article < ActiveRecord::Base # The implementation in this class just provides the +body+ attribute as the # HTML. Other article types can override this method to provide customized # views of themselves. - def to_html + def to_html(options = {}) body end diff --git a/app/models/blog.rb b/app/models/blog.rb index 646d334..d0de39b 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb @@ -28,8 +28,8 @@ class Blog < Folder # FIXME isn't this too much including just to be able to generate some HTML? include ActionView::Helpers::TagHelper - def to_html - content_tag('div', body) + tag('hr') + def to_html(options = {}) + posts_list(options[:page]) end def folder? @@ -52,4 +52,16 @@ class Blog < Folder end end + def posts_list(npage) + article = self + children = if filter and filter[:year] and filter[:month] + filter_date = DateTime.parse("#{filter[:year]}-#{filter[:month]}-01") + posts.paginate :page => npage, :per_page => posts_per_page, :conditions => [ 'created_at between ? and ?', filter_date, filter_date + 1.month - 1.day ] + else + posts.paginate :page => npage, :per_page => posts_per_page + end + lambda do + render :file => 'content_viewer/blog_page', :locals => {:article => article, :children => children} + end + end end diff --git a/app/models/enterprise_homepage.rb b/app/models/enterprise_homepage.rb index 9b68f5e..d6908fc 100644 --- a/app/models/enterprise_homepage.rb +++ b/app/models/enterprise_homepage.rb @@ -20,7 +20,7 @@ class EnterpriseHomepage < Article include EnterpriseHomepageHelper include CatalogHelper - def to_html + def to_html(options ={}) products = self.profile.products display_profile_info(self.profile) + content_tag('div', self.body || '') + (self.profile.environment.enabled?('disable_products_for_enterprises') ? '' : display_products_list(self.profile, products)) diff --git a/app/models/event.rb b/app/models/event.rb index 2b0b8c8..1ee1f79 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -58,7 +58,7 @@ class Event < Article include ActionController::UrlWriter include DatesHelper - def to_html + def to_html(options = {}) result = '' html = Builder::XmlMarkup.new(:target => result) diff --git a/app/models/folder.rb b/app/models/folder.rb index 89e55b8..8198f55 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -34,7 +34,7 @@ class Folder < Article include FolderHelper include DatesHelper - def to_html + def to_html(options = {}) send(view_as) end diff --git a/app/models/rss_feed.rb b/app/models/rss_feed.rb index 9936786..67f8342 100644 --- a/app/models/rss_feed.rb +++ b/app/models/rss_feed.rb @@ -50,7 +50,7 @@ class RssFeed < Article validates_inclusion_of :feed_item_description, :in => [ 'body', 'abstract' ], :if => :feed_item_description # TODO - def to_html + def to_html(options = {}) end # RSS feeds have type =text/xml=. @@ -61,7 +61,7 @@ class RssFeed < Article include ActionController::UrlWriter def fetch_articles if parent && parent.blog? - return parent.posts.find(:all, :limit => self.limit, :order => 'id desc') + return parent.posts.find(:all, :conditions => ['published = ?', true], :limit => self.limit, :order => 'id desc') end articles = diff --git a/app/models/textile_article.rb b/app/models/textile_article.rb index 96947e3..895a540 100644 --- a/app/models/textile_article.rb +++ b/app/models/textile_article.rb @@ -8,7 +8,7 @@ class TextileArticle < TextArticle _('Accessible alternative for visually impaired users.') end - def to_html + def to_html(options ={}) RedCloth.new(self.body|| '').to_html end diff --git a/app/models/uploaded_file.rb b/app/models/uploaded_file.rb index 0937d00..bf8ad5f 100644 --- a/app/models/uploaded_file.rb +++ b/app/models/uploaded_file.rb @@ -50,7 +50,7 @@ class UploadedFile < Article # FIXME isn't this too much including just to be able to generate some HTML? include ActionView::Helpers::TagHelper - def to_html + def to_html(options = {}) tag('img', :src => public_filename, :class => css_class_name, :style => 'max-width: 100%') if image? end diff --git a/app/views/content_viewer/blog_page.rhtml b/app/views/content_viewer/blog_page.rhtml new file mode 100644 index 0000000..f1bda69 --- /dev/null +++ b/app/views/content_viewer/blog_page.rhtml @@ -0,0 +1,5 @@ +