From 27c69ce236669ff543fc28a5514727316b703d0c Mon Sep 17 00:00:00 2001 From: rizwanreza Date: Sat, 8 Aug 2009 23:01:05 +0300 Subject: [PATCH] content_tag modified to support hashes as block --- actionpack/lib/action_view/helpers/tag_helper.rb | 26 +++++++++++++++------ actionpack/test/template/tag_helper_test.rb | 8 ++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index eea797a..64a39cf 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -134,16 +134,26 @@ 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? + options.each_pair do |key, value| + if BOOLEAN_ATTRIBUTES.include?(key) + attrs << %(#{key}="#{key}") if value + else + if !value.nil? + if value.is_a?(Array) + if escape + attrs << %(#{key}="#{escape_once(value.join(" "))}") + else + attrs << %(#{key}="#{value.join(" ")}") + end + else + if escape + attrs << %(#{key}="#{escape_once(value)}") + else + attrs << %(#{key}="#{value}") + end + end end 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..90b3d81 100644 --- a/actionpack/test/template/tag_helper_test.rb +++ b/actionpack/test/template/tag_helper_test.rb @@ -64,6 +64,14 @@ class TagHelperTest < ActionView::TestCase content_tag("p") { content_tag("b", "Hello") }, output_buffer end + + def test_content_tag_with_hash + str = '' + {'tom' => 'admin', 'jim' => 'user'}.each do |nick, role| + str << content_tag(:span, nick, :class => ["nickname", role]) + end + assert_dom_equal %(jimtom), str + end def test_content_tag_nested_in_content_tag_in_erb __in_erb_template = true -- 1.6.2.2