Getting rid of the internal components option.

This commit is contained in:
José Valim 2011-09-03 09:01:47 +02:00
parent 25a13a9e32
commit f8a9bae534
4 changed files with 15 additions and 45 deletions

View File

@ -86,14 +86,7 @@ module SimpleForm
# given SimpleForm.time_zone_priority and SimpleForm.country_priority are used respectivelly.
#
def input(attribute_name, options={}, &block)
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
if block_given?
SimpleForm.components.render SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block)
else
SimpleForm.components.render find_mapping(input_type).new(self, attribute_name, column, input_type, options)
end
SimpleForm.components.render find_input(attribute_name, options, &block)
end
alias :attribute :input
@ -113,8 +106,7 @@ module SimpleForm
#
def input_field(attribute_name, options={})
options[:input_html] = options.except(:as, :collection, :label_method, :value_method)
options.merge!(:components => [:input], :wrapper => false)
input(attribute_name, options)
SimpleForm::Wrappers::Root.new(:input, :wrapper => false).render find_input(attribute_name, options)
end
# Helper for dealing with association selects/radios, generating the
@ -296,6 +288,18 @@ module SimpleForm
private
# Find an input based on the attribute name.
def find_input(attribute_name, options={}, &block) #:nodoc:
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
if block_given?
SimpleForm::Inputs::BlockInput.new(self, attribute_name, column, input_type, options, &block)
else
find_mapping(input_type).new(self, attribute_name, column, input_type, options)
end
end
# Attempt to guess the better input type given the defined options. By
# default alwayls fallback to the user :as option, or to a :select when a
# collection is given.

View File

@ -12,7 +12,7 @@ module SimpleForm
@defaults[:class] = Array.wrap(@defaults[:class])
end
def render(input, components = self.components)
def render(input)
content = "".html_safe
options = input.options

View File

@ -5,14 +5,6 @@ module SimpleForm
super(:wrapper, *args)
end
def render(input)
if components = input.options[:components]
super(input, SimpleForm::Wrappers.wrap(components))
else
super
end
end
private
def wrap(input, options, content)

View File

@ -104,32 +104,6 @@ class InputTest < ActionView::TestCase
end
end
test 'input should render components according to an optional :components option' do
with_input_for @user, :name, :string, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :age, :integer, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :active, :boolean, :components => [:label, :input]
assert_select 'label + input'
with_input_for @user, :description, :text, :components => [:input, :label]
assert_select 'textarea + label'
with_input_for @user, :password, :password, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :name, :file, :components => [:input, :label]
assert_select 'input + label'
with_input_for @user, :country, :country, :components => [:input, :label]
assert_select 'select + label'
with_input_for @user, :time_zone, :time_zone, :components => [:input, :label]
assert_select 'select + label'
end
# StringInput
test 'input should map text field to string attribute' do
with_input_for @user, :name, :string