forum_helper.rb
1.79 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
module ForumHelper
def cms_label_for_new_children
_('New discussion topic')
end
def cms_label_for_edit
_('Configure forum')
end
def list_forum_posts(articles)
pagination = will_paginate(articles, {
:param_name => 'npage',
:prev_label => _('« Newer posts'),
:next_label => _('Older posts »')
})
content = [content_tag('tr',
content_tag('th', _('Discussion topic')) +
content_tag('th', _('Posts')) +
content_tag('th', _('Last post'))
)
]
artic_len = articles.length
articles.each_with_index{ |art,i|
css_add = [ 'position-'+(i+1).to_s() ]
position = (i%2 == 0) ? 'odd-post' : 'even-post'
css_add << 'first' if i == 0
css_add << 'last' if i == (artic_len-1)
css_add << 'not-published' if !art.published?
css_add << position
content << content_tag('tr',
content_tag('td', link_to(art.title, art.url)) +
content_tag('td', link_to(art.comments.count, art.url.merge(:anchor => 'comments_list'))) +
content_tag('td', last_topic_update(art)),
:class => 'forum-post ' + css_add.join(' '),
:id => "post-#{art.id}"
)
}
content_tag('table', content) + (pagination or '')
end
def last_topic_update(article)
last_update_at, last_update_by = (article.comments.count.zero? ? [article.updated_at, article.author] : [article.comments.last.created_at, article.comments.last.author])
time_ago_as_sentence(last_update_at) + ' ' + _('ago') + ' ' + _('by') + ' ' + link_to(last_update_by.name, last_update_by.url)
end
end