From 285132735eb400bc6929dd83a24d4a55841d8b94 Mon Sep 17 00:00:00 2001 From: Aurélio A. Heckert Date: Mon, 25 Mar 2013 18:43:46 -0300 Subject: [PATCH] support to add css class without replace original on button_bar --- app/helpers/application_helper.rb | 5 ++++- test/unit/application_helper_test.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index db14797..3900a02 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -260,7 +260,10 @@ module ApplicationHelper end def button_bar(options = {}, &block) - concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), { :class => 'button-bar' }.merge(options))) + options[:class].nil? ? + options[:class]='button-bar' : + options[:class]+=' button-bar' + concat(content_tag('div', capture(&block) + tag('br', :style => 'clear: left;'), options)) end VIEW_EXTENSIONS = %w[.rhtml .html.erb] diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 0efbddf..e1f7390 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -657,7 +657,37 @@ class ApplicationHelperTest < ActiveSupport::TestCase assert_not_nil add_zoom_to_images end + should 'envelop a html with button-bar div' do + result = button_bar { 'foo' } + assert_equal '
foo'+ + '
', result + end + + should 'add more classes to button-bar envelope' do + result = button_bar :class=>'test' do + 'foo' + end + assert_equal '
foo'+ + '
', result + end + + should 'add more attributes to button-bar envelope' do + result = button_bar :id=>'bt1' do + 'foo' + end + assert_equal '
foo'+ + '
', result + end + protected include NoosferoTestHelper + def capture + yield + end + + def concat(str) + str + end + end -- libgit2 0.21.2