blog_helper.rb
1.27 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
module BlogHelper
def custom_options_for_article(article)
@article = article
hidden_field_tag('article[published]', 1) +
hidden_field_tag('article[accept_comments]', 0)
end
def cms_label_for_new_children
_('New post')
end
def cms_label_for_edit
_('Edit blog')
end
def list_posts(user, articles)
pagination = will_paginate(articles, {
:param_name => 'npage',
:prev_label => _('« Newer posts'),
:next_label => _('Older posts »')
})
content = []
artic_len = articles.length
articles.each_with_index{ |art,i|
css_add = [ 'position-'+(i+1).to_s() ]
if art.published? || (user==art.profile)
css_add << 'first' if i == 0
css_add << 'last' if i == (artic_len-1)
css_add << 'not-published' if !art.published?
content << content_tag('div',
display_post(art) + '<br style="clear:both"/>',
:class => 'blog-post ' + css_add.join(' '),
:id => "post-#{art.id}")
end
}
content.join("\n<hr class='sep-posts'/>\n") + (pagination or '')
end
def display_post(article)
html = article.to_html
html = content_tag('p', html) if ! html.include?('</p>')
article_title(article) + html
end
end