From d23f49c6da3b0e0b603841ee6f262adbee21a1ab Mon Sep 17 00:00:00 2001 From: Laurent Arnoud Date: Mon, 4 Oct 2010 22:23:57 +0200 Subject: [PATCH] Add content_append option for to_label_tag. Sometime we just need to add ":" at the end of a label. If you are using the same translation for activemodel attribute and label, you don't have to duplicate views labels keys. Signed-off-by: Laurent Arnoud --- actionpack/lib/action_view/helpers/form_helper.rb | 2 ++ actionpack/test/template/form_helper_test.rb | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 3cd8b02..aa34abf 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -894,6 +894,8 @@ module ActionView content ||= method_name.humanize + content << options.delete('content_append') if options['content_append'] + label_tag(name_and_id["id"], content, options) end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 8809e51..58edc0c 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -185,6 +185,17 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal('', label(:post, :title) { "The title, please:" }) end + def test_label_with_content_append + assert_dom_equal('', label(:post, :body, nil, :content_append => ':')) + end + + def test_label_with_content_append_and_locale + old_locale, I18n.locale = I18n.locale, :label + assert_dom_equal('', label(:post, :body, nil, :content_append => ':')) + ensure + I18n.locale = old_locale + end + def test_text_field assert_dom_equal( '', text_field("post", "title") @@ -761,7 +772,7 @@ class FormHelperTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - + def test_form_for_with_search_field # Test case for bug which would emit an "object" attribute # when used with form_for using a search_field form helper -- 1.7.1