content_viewer_helper.rb
1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module ContentViewerHelper
include GetText
def number_of_comments(article)
n = article.comments.size
if n == 0
_('No comments yet')
else
n_('One comment', '%{comments} comments', n) % { :comments => n }
end
end
def article_title(article, args = {})
title = content_tag('h1', article.title, :class => 'title')
if article.belongs_to_blog?
unless args[:no_link]
title = content_tag('h3', link_to(article.name, article.url), :class => 'title')
end
title << content_tag('span', _("%s, by %s" % [show_date(article.created_at), article.profile.name]), :class => 'created-at')
end
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)
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
article.to_html + (children.compact.empty? ? content_tag('em', _('(no posts)')) : list_posts(children))
else
article.to_html
end
end
end