comment_group_macro_plugin.rb
1.5 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
require_dependency 'comment_group_macro_plugin/ext/article'
require_dependency 'comment_group_macro_plugin/ext/comment'
#FIXME See a better way to generalize this parameter.
ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-group_id']
class CommentGroupMacroPlugin < Noosfero::Plugin
def self.plugin_name
"Comment Group"
end
def self.plugin_description
_("A plugin that display comment groups.")
end
def load_comments(article)
article.comments.without_spam.without_group.as_thread
end
#FIXME make this test
def macro_display_comments(params, inner_html, source)
group_id = params[:group_id].to_i
article = source
count = article.group_comments.without_spam.in_group(group_id).count
lambda {render :partial => 'plugins/comment_group_macro/views/comment_group.rhtml', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile }}
end
def macro_methods
'macro_display_comments'
end
def config_macro_display_comments
{ :params => [], :skip_dialog => true, :generator => 'makeCommentable();', :js_files => 'comment_group.js', :icon_path => '/designs/icons/tango/Tango/16x16/emblems/emblem-system.png', :css_files => 'comment_group.css' }
end
def comment_form_extra_contents(args)
comment = args[:comment]
group_id = comment.group_id || args[:group_id]
lambda {
hidden_field_tag('comment[group_id]', group_id) if group_id
}
end
end