diff --git a/lib/noosfero/plugin/macro.rb b/lib/noosfero/plugin/macro.rb index e190575..1fdeb09 100644 --- a/lib/noosfero/plugin/macro.rb +++ b/lib/noosfero/plugin/macro.rb @@ -55,6 +55,7 @@ class Noosfero::Plugin::Macro content end + # This is the method the macros should override def parse(attrs, inner_html, source) raise end diff --git a/plugins/comment_group/lib/comment_group_plugin.rb b/plugins/comment_group/lib/comment_group_plugin.rb index 813baae..1a8b0e9 100644 --- a/plugins/comment_group/lib/comment_group_plugin.rb +++ b/plugins/comment_group/lib/comment_group_plugin.rb @@ -1,9 +1,6 @@ require_dependency 'comment_group_plugin/ext/article' require_dependency 'comment_group_plugin/ext/comment' -#FIXME See a better way to generalize this parameter. -ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-group_id'] - class CommentGroupPlugin < Noosfero::Plugin def self.plugin_name @@ -18,23 +15,6 @@ class CommentGroupPlugin < Noosfero::Plugin 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.identifier }} - 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] diff --git a/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb b/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb new file mode 100644 index 0000000..5c6ab48 --- /dev/null +++ b/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb @@ -0,0 +1,22 @@ +#FIXME See a better way to generalize this parameter. +ActionView::Base.sanitized_allowed_attributes += ['data-macro', 'data-macro-group_id'] + +class CommentGroupPlugin::AllowComment < Noosfero::Plugin::Macro + def self.configuration + { :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 + + #FIXME Make this test + def parse(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.identifier }} + end +end diff --git a/plugins/comment_group/test/unit/comment_group_plugin_test.rb b/plugins/comment_group/test/unit/comment_group_plugin_test.rb index 4eb2c74..a8279b1 100644 --- a/plugins/comment_group/test/unit/comment_group_plugin_test.rb +++ b/plugins/comment_group/test/unit/comment_group_plugin_test.rb @@ -10,16 +10,6 @@ class CommentGroupPluginTest < ActiveSupport::TestCase attr_reader :environment - should 'register comment_group_macro in environment' do - Environment.macros = {} - Environment.macros[environment.id] = {} - macros = Environment.macros[environment.id] - context = mock() - context.stubs(:environment).returns(environment) - plugin = CommentGroupPlugin.new(context) - assert_equal ['macro_display_comments'], macros.keys - end - should 'load_comments returns all the comments wihout group of an article passed as parameter' do article = fast_create(Article) c1 = fast_create(Comment, :source_id => article.id, :group_id => 1) @@ -52,30 +42,5 @@ class CommentGroupPluginTest < ActiveSupport::TestCase assert_equal [], [c2] - plugin.load_comments(article) assert_equal [], plugin.load_comments(article) - [c2] end - - should 'params of macro display comments configuration be an empty array' do - plugin = CommentGroupPlugin.new - assert_equal [], plugin.config_macro_display_comments[:params] - end - - should 'skip_dialog of macro display comments configuration be true' do - plugin = CommentGroupPlugin.new - assert plugin.config_macro_display_comments[:skip_dialog] - end - - should 'generator of macro display comments configuration be the makeCommentable function' do - plugin = CommentGroupPlugin.new - assert_equal 'makeCommentable();', plugin.config_macro_display_comments[:generator] - end - - should 'js_files of macro display comments configuration return comment_group.js' do - plugin = CommentGroupPlugin.new - assert_equal 'comment_group.js', plugin.config_macro_display_comments[:js_files] - end - - should 'css_files of macro display comments configuration return comment_group.css' do - plugin = CommentGroupPlugin.new - assert_equal 'comment_group.css', plugin.config_macro_display_comments[:css_files] - end end -- libgit2 0.21.2