From cbf85eb207d7de18be758111aefc5cb94f2ea781 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Sat, 8 Aug 2009 17:10:26 -0400 Subject: [PATCH] Adding support for an array passed into tag_options. Based off Tomasz Mazur's patch. --- actionpack/lib/action_view/helpers/tag_helper.rb | 16 +++++++--------- actionpack/test/template/tag_helper_test.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index eea797a..ff5a213 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 ef88cae..3f785c6 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -15,6 +15,16 @@ class TagHelperTest < ActionView::TestCase assert_match /class="elsewhere"/, str end + def test_tag_options_with_escaped_array + str = content_tag('p', "limelight", :class => ["song", "play>"]) + assert_match /class="song play>"/, str + end + + def test_tag_options_with_unescaped_array + str = content_tag('p', "limelight", {:class => ["song", "play>"]}, false) + assert_match /class="song play>"/, str + end + def test_tag_options_rejects_nil_option assert_equal "

", tag("p", :ignored => nil) end -- 1.6.1.2