From 2abe3d2cd92e5ee55c39f1b4062ccf60043105f7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 9 Jul 2005 17:28:35 +0000 Subject: Added that nil options are not included in tags, so tag("p", :ignore => nil) now returns

not

but that tag("p", :ignore => "") still includes it #1465 [michael@schuerig.de] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1789 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ actionpack/lib/action_view/helpers/tag_helper.rb | 5 +++-- actionpack/test/template/form_helper_test.rb | 6 +++--- actionpack/test/template/form_tag_helper_test.rb | 4 ++-- actionpack/test/template/javascript_helper_test.rb | 2 +- actionpack/test/template/tag_helper_test.rb | 8 ++++++++ 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index d373c02a64..8b418ac92b 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added that nil options are not included in tags, so tag("p", :ignore => nil) now returns

not

but that tag("p", :ignore => "") still includes it #1465 [michael@schuerig.de] + * Fixed that UrlHelper#link_to_unless/link_to_if used html_escape on the name if no link was to be applied. This is unnecessary and breaks its use with images #1649 [joergd@pobox.com] * Added even more goodies to script.aculo.us #1677 [Thomas Fuchs] diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index 1753ef9acf..40fd72d23f 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -24,8 +24,9 @@ module ActionView private def tag_options(options) - unless options.empty? - " " + options.symbolize_keys.map { |key, value| + cleaned_options = options.reject { |key, value| value.nil? } + unless cleaned_options.empty? + " " + cleaned_options.symbolize_keys.map { |key, value| %(#{key}="#{html_escape(value.to_s)}") }.sort.join(" ") end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index b76f21d80b..1b9df865f3 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -37,7 +37,7 @@ class FormHelperTest < Test::Unit::TestCase '', password_field("post", "title") ) assert_equal( - '', password_field("person", "name") + '', password_field("person", "name") ) end @@ -71,7 +71,7 @@ class FormHelperTest < Test::Unit::TestCase check_box("post", "secret") ) assert_equal( - '', + '', check_box("post", "secret" ,{"checked"=>"checked"}) ) @post.secret = true @@ -80,7 +80,7 @@ class FormHelperTest < Test::Unit::TestCase check_box("post", "secret") ) end - + def test_check_box_with_explicit_checked_and_unchecked_values @post.secret = "on" assert_equal( diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb index 7a666271c1..6295aa91b6 100644 --- a/actionpack/test/template/form_tag_helper_test.rb +++ b/actionpack/test/template/form_tag_helper_test.rb @@ -22,7 +22,7 @@ class FormTagHelperTest < Test::Unit::TestCase end def test_form_tag - actual = form_tag + actual = form_tag expected = %(

) assert_equal expected, actual end @@ -41,7 +41,7 @@ class FormTagHelperTest < Test::Unit::TestCase def test_password_field_tag actual = password_field_tag - expected = %() + expected = %() assert_equal expected, actual end diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index fdcce49efa..a1fcdde16d 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -88,7 +88,7 @@ class JavaScriptHelperTest < Test::Unit::TestCase def test_text_field_with_auto_complete assert_match "