diff options
author | rizwanreza <rizwanreza@gmail.com> | 2009-08-08 22:21:25 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-08-08 22:21:32 +0100 |
commit | 5786395760f1e1906c878df4023cac3741e66e87 (patch) | |
tree | a85a8c2dd8c5a3803103c52d1b04d7f0e6801025 /actionpack | |
parent | 761283ffdb5750f8a38e2ed67891d2b2b9152d7f (diff) | |
download | rails-5786395760f1e1906c878df4023cac3741e66e87.tar.gz rails-5786395760f1e1906c878df4023cac3741e66e87.tar.bz2 rails-5786395760f1e1906c878df4023cac3741e66e87.zip |
Allow content_tag options to take an array [#1741 state:resolved] [rizwanreza, Nick Quaranto]
Example:
content_tag('p', "limelight", :class => ["song", "play"])
# => <p class="song play">limelight</p>
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/helpers/tag_helper.rb | 16 | ||||
-rw-r--r-- | actionpack/test/template/tag_helper_test.rb | 13 |
2 files changed, 20 insertions, 9 deletions
diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index eea797abb5..ff5a2134ff 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -134,16 +134,14 @@ module ActionView def tag_options(options, escape = true) unless options.blank? attrs = [] - if escape - options.each_pair do |key, value| - if BOOLEAN_ATTRIBUTES.include?(key) - attrs << %(#{key}="#{key}") if value - else - attrs << %(#{key}="#{escape_once(value)}") if !value.nil? - end + options.each_pair do |key, value| + if BOOLEAN_ATTRIBUTES.include?(key) + attrs << %(#{key}="#{key}") if value + elsif !value.nil? + final_value = value.is_a?(Array) ? value.join(" ") : value + final_value = escape_once(final_value) if escape + attrs << %(#{key}="#{final_value}") end - else - attrs = options.map { |key, value| %(#{key}="#{value}") } end " #{attrs.sort * ' '}" unless attrs.empty? end diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb index ef88cae5b8..2aa3d5b5fa 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -71,6 +71,19 @@ class TagHelperTest < ActionView::TestCase assert_equal '<p><b>Hello</b></p>', output_buffer end + def test_content_tag_with_escaped_array_class + str = content_tag('p', "limelight", :class => ["song", "play>"]) + assert_equal "<p class=\"song play>\">limelight</p>", str + + str = content_tag('p', "limelight", :class => ["song", "play"]) + assert_equal "<p class=\"song play\">limelight</p>", str + end + + def test_content_tag_with_unescaped_array_class + str = content_tag('p', "limelight", {:class => ["song", "play>"]}, false) + assert_equal "<p class=\"song play>\">limelight</p>", str + end + def test_cdata_section assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>") end |