Commit 0b0ad50dca1dda82d6cace8af02712f891372363
1 parent
04962ef3
Exists in
master
and in
28 other branches
Added a way to include a comment action outside menu
Showing
4 changed files
with
37 additions
and
17 deletions
Show diff stats
app/helpers/comment_helper.rb
... | ... | @@ -25,7 +25,10 @@ module CommentHelper |
25 | 25 | def comment_actions(comment) |
26 | 26 | url = url_for(:profile => profile.identifier, :controller => :comment, :action => :check_actions, :id => comment.id) |
27 | 27 | links = links_for_comment_actions(comment) |
28 | - 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? | |
28 | + links_submenu = links.select{|link| link[:action_bar].nil? || !link[:action_bar]} | |
29 | + links_action_bar = links - links_submenu | |
30 | + links_submenu = links_submenu.collect {|link| link.slice(:link)} | |
31 | + render :partial => 'comment/comment_actions', :locals => {:links_submenu => links_submenu, :links_action_bar => links_action_bar, :url => url, :comment => comment} | |
29 | 32 | end |
30 | 33 | |
31 | 34 | private | ... | ... |
app/views/comment/_comment.rhtml
... | ... | @@ -32,19 +32,7 @@ |
32 | 32 | |
33 | 33 | <div class="comment-details"> |
34 | 34 | <div class="comment-header"> |
35 | - <ul> | |
36 | - <div class="comment-actions"> | |
37 | - <%= comment_actions(comment) %> | |
38 | - </div> | |
39 | - </ul> | |
40 | - <% unless comment.spam? %> | |
41 | - <%= link_to_function '', | |
42 | - "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, | |
43 | - :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', | |
44 | - :id => 'comment-reply-to-' + comment.id.to_s, | |
45 | - :title => _('Reply') | |
46 | - %> | |
47 | - <% end %> | |
35 | + <%= comment_actions(comment) %> | |
48 | 36 | </div> |
49 | 37 | |
50 | 38 | <div class="comment-created-at"> | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +<ul> | |
2 | + <% if !links_submenu.empty? %> | |
3 | + <div class="comment-actions"> | |
4 | + <li class="vcard"> | |
5 | + <%= link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{links_submenu.to_json}); return false", :class => 'menu-submenu-trigger comment-trigger', :url => url) %> | |
6 | + </li> | |
7 | + </div> | |
8 | + <% end %> | |
9 | +</ul> | |
10 | +<div class="comments-action-bar"> | |
11 | + <% unless comment.spam? %> | |
12 | + <%= link_to_function '', | |
13 | + "var f = add_comment_reply_form(this, %s); f.find('comment_title, textarea').val(''); return false" % comment.id, | |
14 | + :class => 'comment-footer comment-footer-link comment-footer-hide comment-actions-reply button', | |
15 | + :id => 'comment-reply-to-' + comment.id.to_s | |
16 | + %> | |
17 | + <% end %> | |
18 | + <% links_action_bar.collect do |link| %> | |
19 | + <%= link[:link] %> | |
20 | + <% end %> | |
21 | +</div> | ... | ... |
test/unit/comment_helper_test.rb
... | ... | @@ -21,14 +21,14 @@ class CommentHelperTest < ActiveSupport::TestCase |
21 | 21 | article = Article.new(:profile => profile) |
22 | 22 | comment = Comment.new(:article => article) |
23 | 23 | menu = comment_actions(comment) |
24 | - assert menu | |
24 | + assert_match /class=\"comment-actions\"/, menu | |
25 | 25 | end |
26 | 26 | |
27 | 27 | should 'do not show menu if it has no actions' do |
28 | 28 | comment = Comment.new |
29 | 29 | self.stubs(:links_for_comment_actions).returns([]) |
30 | 30 | menu = comment_actions(comment) |
31 | - assert !menu | |
31 | + assert_no_match /class=\"comment-actions\"/, menu | |
32 | 32 | end |
33 | 33 | |
34 | 34 | should 'do not show menu if it has nil actions only' do |
... | ... | @@ -38,7 +38,7 @@ class CommentHelperTest < ActiveSupport::TestCase |
38 | 38 | self.stubs(:link_for_edit).returns(nil) |
39 | 39 | self.stubs(:link_for_remove).returns(nil) |
40 | 40 | menu = comment_actions(comment) |
41 | - assert !menu | |
41 | + assert_no_match /class=\"comment-actions\"/, menu | |
42 | 42 | end |
43 | 43 | |
44 | 44 | should 'include actions of plugins in menu' do |
... | ... | @@ -131,6 +131,14 @@ class CommentHelperTest < ActiveSupport::TestCase |
131 | 131 | assert link |
132 | 132 | end |
133 | 133 | |
134 | + should 'include actions of plugins in action bar' do | |
135 | + comment = Comment.new | |
136 | + plugin_action = {:link => 'plugin_action', :action_bar => true} | |
137 | + @plugins.stubs(:dispatch).returns([plugin_action]) | |
138 | + html = comment_actions(comment) | |
139 | + assert_match /plugin_action/, Hpricot(html).search('.comments-action-bar').html | |
140 | + end | |
141 | + | |
134 | 142 | def link_to_function(content, url, options = {}) |
135 | 143 | link_to(content, url, options) |
136 | 144 | end | ... | ... |