Add rudimentary support to wrapper_tag.

This commit is contained in:
José Valim 2009-12-10 00:34:45 -02:00
parent d9cc0a3f94
commit 02f716717a
3 changed files with 22 additions and 1 deletions

View File

@ -26,4 +26,8 @@ module SimpleForm
# Series of attemps to detect a default value method for collection
mattr_accessor :collection_value_methods
@@collection_value_methods = [ :id, :to_s ]
# You can wrap all inputs in a pre-defined tag. By default is nil.
mattr_accessor :wrapper_tag
@@wrapper_tag = nil
end

View File

@ -11,11 +11,19 @@ module SimpleForm
klass.new(self, attribute, input_type, options).generate
end
pieces.compact.join
wrap_content(pieces.compact.join)
end
private
def wrap_content(content)
if SimpleForm.wrapper_tag
@template.content_tag(SimpleForm.wrapper_tag, content)
else
content
end
end
def default_input_type(attribute, options)
return options[:as].to_sym if options[:as]
return :select if options[:collection]

View File

@ -128,4 +128,13 @@ class FormBuilderTest < ActionView::TestCase
with_form_for :name, :error => false
assert_no_select 'span.error'
end
test 'builder support wrapping around an specific tag' do
swap SimpleForm, :wrapper_tag => :p do
with_form_for :name
assert_select 'form p label[for=user_name]'
assert_select 'form p input#user_name.string'
end
end
end