From 337fce04f32515015344be850a10d5729721ce34 Mon Sep 17 00:00:00 2001 From: Lauro Caetano Date: Fri, 4 Apr 2014 19:10:50 -0300 Subject: [PATCH] Translate the attributes prefixed with _html to keep the html markup. --- lib/simple_form/inputs/base.rb | 4 ++++ test/inputs/string_input_test.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/simple_form/inputs/base.rb b/lib/simple_form/inputs/base.rb index 524c9273..414d40ec 100644 --- a/lib/simple_form/inputs/base.rb +++ b/lib/simple_form/inputs/base.rb @@ -178,10 +178,14 @@ module SimpleForm model_names.shift lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}" + lookups << :"#{joined_model_names}.#{lookup_action}.#{reflection_or_attribute_name}_html" lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}" + lookups << :"#{joined_model_names}.#{reflection_or_attribute_name}_html" end lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}" + lookups << :"defaults.#{lookup_action}.#{reflection_or_attribute_name}_html" lookups << :"defaults.#{reflection_or_attribute_name}" + lookups << :"defaults.#{reflection_or_attribute_name}_html" lookups << default t(lookups.shift, scope: :"#{i18n_scope}.#{namespace}", default: lookups).presence diff --git a/test/inputs/string_input_test.rb b/test/inputs/string_input_test.rb index a67a56e1..d3e3034f 100644 --- a/test/inputs/string_input_test.rb +++ b/test/inputs/string_input_test.rb @@ -115,6 +115,15 @@ class StringInputTest < ActionView::TestCase end end + test 'input should translate a key prefixed with _html and return the html markup' do + store_translations(:en, simple_form: { labels: { user: { + name_html: 'Name' + } } }) do + with_input_for @user, :name, :string + assert_select 'label b', 'Name' + end + end + [:email, :url, :search, :tel].each do |type| test "input should allow type #{type}" do with_input_for @user, :name, type