Skip to content
This repository has been archived by the owner on Apr 14, 2018. It is now read-only.

Commit

Permalink
bug fix for simple_form passing an array into options['class']
Browse files Browse the repository at this point in the history
  • Loading branch information
phallstrom committed Jan 18, 2013
1 parent bf32211 commit d6c1476
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
source "http://rubygems.org"

group :test do
gem 'rails', '> 3.2.0'
end

# Specify your gem's dependencies in form_helper_css.gemspec
gemspec
4 changes: 4 additions & 0 deletions lib/form_helper_css/form_helper_css.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module TagHelper
def css_options_for_tag(name, options={})
name = name.to_sym
options = options.stringify_keys
class_was_array = options['class'].is_a?(Array)
options['class'] = options['class'].join(' ') if class_was_array
if FORM_HELPER_CSS_OPTIONS[:append] == false && options.has_key?('class')
options['class'] = options['class'].split(' ') if class_was_array
return options
elsif name == :input and options['type']
return options if (options['type'] == 'hidden')
Expand All @@ -30,6 +33,7 @@ def css_options_for_tag(name, options={})
if options['class']
options['class'] = options['class'].to_s.strip.split(/\s+/).uniq.join(' ') # de-dup the class list
end
options['class'] = options['class'].split(' ') if class_was_array
options
end

Expand Down
2 changes: 1 addition & 1 deletion lib/form_helper_css/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FormHelperCss
VERSION = "0.0.1"
VERSION = "0.0.2"
end
7 changes: 6 additions & 1 deletion test/form_helper_css_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_tag_helper
assert_equal '<br />', tag(:br)
assert_equal '<p></p>', content_tag(:p, '')
assert_equal '<input type="text" />', tag(:input, :type => 'text', :class => nil)
assert_equal '<textarea></textarea>', content_tag(:textarea, '', :class => nil)
assert_equal "<textarea>\n</textarea>", content_tag(:textarea, '', :class => nil)
end

def test_url_helper
Expand Down Expand Up @@ -66,6 +66,11 @@ def test_form_tag_helper_with_class_and_append
assert_match 'class="foo text"', text_field_tag('text', nil, :class => 'foo')
end

def test_css_options_for_tag_with_class_array
ActionView::Helpers::TagHelper::FORM_HELPER_CSS_OPTIONS.merge!(:append => true)
assert_equal ['foo', 'bar', 'checkbox'], css_options_for_tag('input', :type => 'checkbox', :class => ['foo', :bar])['class']
end


def test_form_helper
assert_match 'class="checkbox"', check_box(:object, :field)
Expand Down

0 comments on commit d6c1476

Please sign in to comment.