Commit 7ebda17712a475497dd114d25feffe31ba1e5e70

Authored by Larissa Reis
1 parent f3027475

Adds optional html options to control_panel_buttons hotspot

  Plugins can set aditional html options like id, class or data
  attributes for control panel buttons.
app/helpers/profile_editor_helper.rb
@@ -141,8 +141,9 @@ module ProfileEditorHelper @@ -141,8 +141,9 @@ module ProfileEditorHelper
141 ) 141 )
142 end 142 end
143 143
144 - def control_panel_button(title, icon, url)  
145 - link_to title, url, :class => 'control-panel-%s' % icon 144 + def control_panel_button(title, icon, url, html_options = {})
  145 + html_options ||= {}
  146 + link_to title, url, html_options.merge(:class => 'control-panel-%s' % icon)
146 end 147 end
147 148
148 def unchangeable_privacy_field(profile) 149 def unchangeable_privacy_field(profile)
app/views/profile_editor/index.html.erb
@@ -73,7 +73,7 @@ @@ -73,7 +73,7 @@
73 <%= control_panel_button(_('Edit welcome page'), 'welcome-page', :action => 'welcome_page') if has_welcome_page %> 73 <%= control_panel_button(_('Edit welcome page'), 'welcome-page', :action => 'welcome_page') if has_welcome_page %>
74 74
75 <% @plugins.dispatch(:control_panel_buttons).each do |button| %> 75 <% @plugins.dispatch(:control_panel_buttons).each do |button| %>
76 - <%= control_panel_button(button[:title], button[:icon], button[:url]) %> 76 + <%= control_panel_button(button[:title], button[:icon], button[:url], button[:html_options]) %>
77 <% end %> 77 <% end %>
78 78
79 <% end %> 79 <% end %>
lib/noosfero/plugin.rb
@@ -253,10 +253,11 @@ class Noosfero::Plugin @@ -253,10 +253,11 @@ class Noosfero::Plugin
253 end 253 end
254 254
255 # -> Adds buttons to the control panel 255 # -> Adds buttons to the control panel
256 - # returns = { :title => title, :icon => icon, :url => url }  
257 - # title = name that will be displayed.  
258 - # icon = css class name (for customized icons include them in a css file).  
259 - # url = url or route to which the button will redirect. 256 + # returns = { :title => title, :icon => icon, :url => url }
  257 + # title = name that will be displayed.
  258 + # icon = css class name (for customized icons include them in a css file).
  259 + # url = url or route to which the button will redirect.
  260 + # html_options = aditional html options.
260 def control_panel_buttons 261 def control_panel_buttons
261 nil 262 nil
262 end 263 end
test/functional/profile_editor_controller_test.rb
@@ -941,7 +941,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -941,7 +941,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
941 941
942 class TestControlPanelButtons1 < Noosfero::Plugin 942 class TestControlPanelButtons1 < Noosfero::Plugin
943 def control_panel_buttons 943 def control_panel_buttons
944 - {:title => "Plugin1 button", :icon => 'plugin1_icon', :url => 'plugin1_url'} 944 + {:title => "Plugin1 button", :icon => 'plugin1_icon', :url => 'plugin1_url', :html_options => { :data => {extra: true} }}
945 end 945 end
946 end 946 end
947 class TestControlPanelButtons2 < Noosfero::Plugin 947 class TestControlPanelButtons2 < Noosfero::Plugin
@@ -955,8 +955,8 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase @@ -955,8 +955,8 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
955 955
956 get :index, :profile => profile.identifier 956 get :index, :profile => profile.identifier
957 957
958 - assert_tag :tag => 'a', :content => 'Plugin1 button', :attributes => {:class => /plugin1_icon/, :href => /plugin1_url/}  
959 - assert_tag :tag => 'a', :content => 'Plugin2 button', :attributes => {:class => /plugin2_icon/, :href => /plugin2_url/} 958 + assert_tag :tag => 'a', :content => 'Plugin1 button', :attributes => {:class => /plugin1_icon/, :href => /plugin1_url/, :'data-extra' => true}
  959 + assert_tag :tag => 'a', :content => 'Plugin2 button', :attributes => {:class => /plugin2_icon/, :href => /plugin2_url/, :'data-extra' => nil}
960 end 960 end
961 961
962 should 'add extra content provided by plugins on edit' do 962 should 'add extra content provided by plugins on edit' do