lib/formtastic/helpers/fieldset_wrapper.rb in formtastic-2.0.2 vs lib/formtastic/helpers/fieldset_wrapper.rb in formtastic-2.1.0.beta1

- old
+ new

@@ -23,32 +23,37 @@ # f.inputs :title, :body, :author # First argument is a column => (no legend) def field_set_and_list_wrapping(*args, &block) #:nodoc: contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten html_options = args.extract_options! - legend = (html_options[:name] || '').to_s - legend %= parent_child_index(html_options[:parent]) if html_options[:parent] - legend = template.content_tag(:legend, template.content_tag(:span, Formtastic::Util.html_safe(legend))) unless legend.blank? - if block_given? contents = if template.respond_to?(:is_haml?) && template.is_haml? template.capture_haml(&block) else template.capture(&block) end end # Ruby 1.9: String#to_s behavior changed, need to make an explicit join. contents = contents.join if contents.respond_to?(:join) + + legend = field_set_legend(html_options) fieldset = template.content_tag(:fieldset, Formtastic::Util.html_safe(legend) << template.content_tag(:ol, Formtastic::Util.html_safe(contents)), html_options.except(:builder, :parent, :name) ) fieldset end + def field_set_legend(html_options) + legend = (html_options[:name] || '').to_s + legend %= parent_child_index(html_options[:parent]) if html_options[:parent] + legend = template.content_tag(:legend, template.content_tag(:span, Formtastic::Util.html_safe(legend))) unless legend.blank? + legend + end + # Gets the nested_child_index value from the parent builder. It returns a hash with each # association that the parent builds. def parent_child_index(parent) #:nodoc: # Could be {"post[authors_attributes]"=>0} or { :authors => 0 } duck = parent[:builder].instance_variable_get('@nested_child_index') @@ -70,6 +75,6 @@ i = (duck[key] || duck[child]).to_i + 1 end end end -end \ No newline at end of file +end