From 0b0ad50dca1dda82d6cace8af02712f891372363 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Fri, 30 Aug 2013 15:20:08 -0300 Subject: [PATCH] Added a way to include a comment action outside menu --- app/helpers/comment_helper.rb | 5 ++++- app/views/comment/_comment.rhtml | 14 +------------- app/views/comment/_comment_actions.rhtml | 21 +++++++++++++++++++++ test/unit/comment_helper_test.rb | 14 +++++++++++--- 4 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 app/views/comment/_comment_actions.rhtml diff --git a/app/helpers/comment_helper.rb b/app/helpers/comment_helper.rb index e6095a7..5156256 100644 --- a/app/helpers/comment_helper.rb +++ b/app/helpers/comment_helper.rb @@ -25,7 +25,10 @@ module CommentHelper def comment_actions(comment) url = url_for(:profile => profile.identifier, :controller => :comment, :action => :check_actions, :id => comment.id) links = links_for_comment_actions(comment) - content_tag(:li, link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url), :class=> 'vcard') unless links.empty? + links_submenu = links.select{|link| link[:action_bar].nil? || !link[:action_bar]} + links_action_bar = links - links_submenu + links_submenu = links_submenu.collect {|link| link.slice(:link)} + render :partial => 'comment/comment_actions', :locals => {:links_submenu => links_submenu, :links_action_bar => links_action_bar, :url => url, :comment => comment} end private diff --git a/app/views/comment/_comment.rhtml b/app/views/comment/_comment.rhtml index e7fb23b..1da1081 100644 --- a/app/views/comment/_comment.rhtml +++ b/app/views/comment/_comment.rhtml @@ -32,19 +32,7 @@
-
    -
    - <%= comment_actions(comment) %> -
    -
- <% unless comment.spam? %> - <%= link_to_function '', - "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, - :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', - :id => 'comment-reply-to-' + comment.id.to_s, - :title => _('Reply') - %> - <% end %> + <%= comment_actions(comment) %>
diff --git a/app/views/comment/_comment_actions.rhtml b/app/views/comment/_comment_actions.rhtml new file mode 100644 index 0000000..ae04c88 --- /dev/null +++ b/app/views/comment/_comment_actions.rhtml @@ -0,0 +1,21 @@ +
    + <% if !links_submenu.empty? %> +
    +
  • + <%= link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links_submenu.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url) %> +
  • +
    + <% end %> +
+
+ <% unless comment.spam? %> + <%= link_to_function '', + "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, + :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', + :id => 'comment-reply-to-' + comment.id.to_s + %> + <% end %> + <% links_action_bar.collect do |link| %> + <%= link[:link] %> + <% end %> +
diff --git a/test/unit/comment_helper_test.rb b/test/unit/comment_helper_test.rb index 479c7f7..c9cce31 100644 --- a/test/unit/comment_helper_test.rb +++ b/test/unit/comment_helper_test.rb @@ -21,14 +21,14 @@ class CommentHelperTest < ActiveSupport::TestCase article = Article.new(:profile => profile) comment = Comment.new(:article => article) menu = comment_actions(comment) - assert menu + assert_match /class=\"comment-actions\"/, menu end should 'do not show menu if it has no actions' do comment = Comment.new self.stubs(:links_for_comment_actions).returns([]) menu = comment_actions(comment) - assert !menu + assert_no_match /class=\"comment-actions\"/, menu end should 'do not show menu if it has nil actions only' do @@ -38,7 +38,7 @@ class CommentHelperTest < ActiveSupport::TestCase self.stubs(:link_for_edit).returns(nil) self.stubs(:link_for_remove).returns(nil) menu = comment_actions(comment) - assert !menu + assert_no_match /class=\"comment-actions\"/, menu end should 'include actions of plugins in menu' do @@ -131,6 +131,14 @@ class CommentHelperTest < ActiveSupport::TestCase assert link end + should 'include actions of plugins in action bar' do + comment = Comment.new + plugin_action = {:link => 'plugin_action', :action_bar => true} + @plugins.stubs(:dispatch).returns([plugin_action]) + html = comment_actions(comment) + assert_match /plugin_action/, Hpricot(html).search('.comments-action-bar').html + end + def link_to_function(content, url, options = {}) link_to(content, url, options) end -- libgit2 0.21.2