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 141 )
142 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 147 end
147 148  
148 149 def unchangeable_privacy_field(profile)
... ...
app/views/profile_editor/index.html.erb
... ... @@ -73,7 +73,7 @@
73 73 <%= control_panel_button(_('Edit welcome page'), 'welcome-page', :action => 'welcome_page') if has_welcome_page %>
74 74  
75 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 77 <% end %>
78 78  
79 79 <% end %>
... ...
lib/noosfero/plugin.rb
... ... @@ -253,10 +253,11 @@ class Noosfero::Plugin
253 253 end
254 254  
255 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 261 def control_panel_buttons
261 262 nil
262 263 end
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -941,7 +941,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
941 941  
942 942 class TestControlPanelButtons1 < Noosfero::Plugin
943 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 945 end
946 946 end
947 947 class TestControlPanelButtons2 < Noosfero::Plugin
... ... @@ -955,8 +955,8 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
955 955  
956 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 960 end
961 961  
962 962 should 'add extra content provided by plugins on edit' do
... ...