content_viewer_helper.rb
1.26 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
module ContentViewerHelper
include BlogHelper
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 = article.display_title if article.kind_of?(UploadedFile) && article.image?
title = article.title if title.blank?
title = content_tag('h1', h(title), :class => 'title')
if article.belongs_to_blog?
unless args[:no_link]
title = content_tag('h1', link_to(article.name, article.url), :class => 'title')
end
title << content_tag('span', _("%s, by %s - %s") % [show_date(article.published_at), link_to(article.author.name, article.author.url), link_to_comments(article)], :class => 'created-at')
end
title
end
def article_to_html(article)
content = article.to_html(:page => params[:npage])
return self.instance_eval(&content) if content.kind_of?(Proc)
content
end
def link_to_comments(article)
link_to( number_of_comments(article), article.url.merge(:anchor => 'comments_list') )
end
def image_label(image)
text = image.title || image.abstract
text && (text.first(40) + (text.size > 40 ? '…' : ''))
end
end