Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make f.inputs return just the fieldset and not the whole template.

Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information...
commit aba144d0d5ea18712a03b6e70d4860e261cbade0 1 parent a721d06
@josevalim josevalim authored justinfrench committed
Showing with 16 additions and 15 deletions.
  1. +9 −14 lib/formtastic.rb
  2. +7 −1 spec/formtastic_spec.rb
View
23 lib/formtastic.rb
@@ -777,21 +777,16 @@ def required_or_optional_string(required) #:nodoc:
def field_set_and_list_wrapping(field_set_html_options, contents = '', &block) #:nodoc:
legend_text = field_set_html_options.delete(:name)
legend = legend_text.blank? ? "" : template.content_tag(:legend, template.content_tag(:span, legend_text))
- if block_given?
- contents = template.capture(&block)
- template.concat(
- template.content_tag(:fieldset,
- legend + template.content_tag(:ol, contents),
- field_set_html_options
- )
- )
- else
- template.content_tag(:fieldset,
- legend + template.content_tag(:ol, contents),
- field_set_html_options
- )
- end
+ contents = template.capture(&block) if block_given?
+
+ fieldset = template.content_tag(:fieldset,
+ legend + template.content_tag(:ol, contents),
+ field_set_html_options
+ )
+
+ template.concat(fieldset) if block_given?
+ fieldset
end
# For methods that have a database column, take a best guess as to what the inout method
View
8 spec/formtastic_spec.rb
@@ -2195,13 +2195,19 @@ def custom(arg1, arg2, options = {})
describe 'when no options are provided' do
before do
+ output_buffer.replace 'before_builder' # clear the output buffer and sets before_builder
semantic_form_for(@new_post) do |builder|
- builder.inputs do
+ @inputs_output = builder.inputs do
concat('hello')
end
end
end
+ it 'should output just the content wrapped in inputs, not the whole template' do
+ output_buffer.should =~ /before_builder/
+ @inputs_output.should_not =~ /before_builder/
+ end
+
it 'should render a fieldset inside the form, with a class of "inputs"' do
output_buffer.should have_tag("form fieldset.inputs")
end
Please sign in to comment.
Something went wrong with that request. Please try again.