Commit 285132735eb400bc6929dd83a24d4a55841d8b94

Authored by Aurélio A. Heckert
1 parent 540a657f

support to add css class without replace original on button_bar

app/helpers/application_helper.rb
... ... @@ -260,7 +260,10 @@ module ApplicationHelper
260 260 end
261 261  
262 262 def button_bar(options = {}, &block)
263   - concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), { :class => 'button-bar' }.merge(options)))
  263 + options[:class].nil? ?
  264 + options[:class]='button-bar' :
  265 + options[:class]+=' button-bar'
  266 + concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), options))
264 267 end
265 268  
266 269 VIEW_EXTENSIONS = %w[.rhtml .html.erb]
... ...
test/unit/application_helper_test.rb
... ... @@ -657,7 +657,37 @@ class ApplicationHelperTest < ActiveSupport::TestCase
657 657 assert_not_nil add_zoom_to_images
658 658 end
659 659  
  660 + should 'envelop a html with button-bar div' do
  661 + result = button_bar { '<b>foo</b>' }
  662 + assert_equal '<div class="button-bar"><b>foo</b>'+
  663 + '<br style=\'clear: left;\' /></div>', result
  664 + end
  665 +
  666 + should 'add more classes to button-bar envelope' do
  667 + result = button_bar :class=>'test' do
  668 + '<b>foo</b>'
  669 + end
  670 + assert_equal '<div class="test button-bar"><b>foo</b>'+
  671 + '<br style=\'clear: left;\' /></div>', result
  672 + end
  673 +
  674 + should 'add more attributes to button-bar envelope' do
  675 + result = button_bar :id=>'bt1' do
  676 + '<b>foo</b>'
  677 + end
  678 + assert_equal '<div class="button-bar" id="bt1"><b>foo</b>'+
  679 + '<br style=\'clear: left;\' /></div>', result
  680 + end
  681 +
660 682 protected
661 683 include NoosferoTestHelper
662 684  
  685 + def capture
  686 + yield
  687 + end
  688 +
  689 + def concat(str)
  690 + str
  691 + end
  692 +
663 693 end
... ...