Permalink
Browse files

Added I18n-support for fieldset legends/titles (i.e. :name/:title for…

… inputs-builder).

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent c33b38d commit 34e8d2f0e36b699a41fb560a8edbbaa10b71ba7d @grimen grimen committed with josevalim Jul 18, 2009
Showing with 44 additions and 9 deletions.
  1. +5 −1 lib/formtastic.rb
  2. +39 −8 spec/formtastic_spec.rb
View
@@ -979,6 +979,9 @@ def required_or_optional_string(required) #:nodoc:
# 'Task #3' and so on.
#
def field_set_and_list_wrapping(html_options, contents='', &block) #:nodoc:
+ html_options[:name] ||= html_options.delete(:title)
+ html_options[:name] = localized_attribute_string(html_options[:name], html_options[:name], :title) if html_options[:name].is_a?(Symbol)
+
legend = html_options.delete(:name).to_s
legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
legend = template.content_tag(:legend, template.content_tag(:span, legend)) unless legend.blank?
@@ -1213,7 +1216,8 @@ def localized_attribute_string(attr_name, attr_value, i18n_key)
if attr_value.is_a?(String)
attr_value
else
- use_i18n = attr_value.nil? ? @@i18n_lookups_by_default : attr_value
+ use_i18n = attr_value.nil? ? @@i18n_lookups_by_default : (attr_value != false)
+
if use_i18n
model_name = @object.class.name.underscore
action_name = template.params[:action].to_s rescue ''
View
@@ -2574,18 +2574,49 @@ def custom(arg1, arg2, options = {})
end
end
- describe 'when a :name option is provided' do
- before do
- @legend_text = "Advanced options"
-
- semantic_form_for(@new_post) do |builder|
- builder.inputs :name => @legend_text do
+ describe 'when a :name or :title option is provided' do
+ describe 'and is a string' do
+ before do
+ @legend_text = "Advanced options"
+ @legend_text_using_title = "Advanced options 2"
+ semantic_form_for(@new_post) do |builder|
+ builder.inputs :name => @legend_text do
+ end
+ builder.inputs :title => @legend_text_using_title do
+ end
end
end
+
+ it 'should render a fieldset with a legend inside the form' do
+ output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
+ output_buffer.should have_tag("form fieldset legend", /#{@legend_text_using_title}/)
+ end
end
+
+ describe 'and is a symbol' do
+ before do
+ @localized_legend_text = "Localized advanced options"
+ @localized_legend_text_using_title = "Localized advanced options 2"
+ I18n.backend.store_translations :en, :formtastic => {
+ :titles => {
+ :post => {
+ :advanced_options => @localized_legend_text,
+ :advanced_options_2 => @localized_legend_text_using_title
+ }
+ }
+ }
+ semantic_form_for(@new_post) do |builder|
+ builder.inputs :name => :advanced_options do
+ end
+ builder.inputs :title => :advanced_options_2 do
+ end
+ end
+ end
- it 'should render a fieldset inside the form' do
- output_buffer.should have_tag("form fieldset legend", /#{@legend_text}/)
+ it 'should render a fieldset with a localized legend inside the form' do
+ output_buffer.should have_tag("form fieldset legend", /#{@localized_legend_text}/)
+ output_buffer.should have_tag("form fieldset legend", /#{@localized_legend_text_using_title}/)
+ end
end
end

0 comments on commit 34e8d2f

Please sign in to comment.