Move hint to new wrappers API.

This commit is contained in:
José Valim 2011-09-02 20:45:17 +02:00
parent f62667ce61
commit 98d7c6f627
4 changed files with 14 additions and 18 deletions

View File

@ -8,24 +8,12 @@ module SimpleForm
private
def enabled_hint
template.content_tag(hint_tag, hint_text, hint_html_options) unless hint_text.blank?
(options[:hint] || translate(:hints)).presence
end
def disabled_hint
nil
end
def hint_tag
options[:hint_tag] || SimpleForm.hint_tag
end
def hint_text
@hint_text ||= options[:hint] || translate(:hints)
end
def hint_html_options
html_options_for(:hint, [SimpleForm.hint_class])
end
end
end
end

View File

@ -250,7 +250,9 @@ module SimpleForm
column = find_attribute_column(attribute_name)
input_type = default_input_type(attribute_name, column, options)
end
SimpleForm::Inputs::Base.new(self, attribute_name, column, input_type, options).hint
SimpleForm::Wrappers.find(:hint).
render(SimpleForm::Inputs::Base.new(self, attribute_name, column, input_type, options))
end
# Creates a default label tag for the given attribute. You can give a label

View File

@ -3,7 +3,9 @@ module SimpleForm
autoload :Many, 'simple_form/wrappers/many'
autoload :Root, 'simple_form/wrappers/root'
autoload :Single, 'simple_form/wrappers/single'
autoload :Anonym, 'simple_form/wrappers/anonym'
# TODO: Test the anonym case
def self.find(name)
SimpleForm.components.find { |c| c.namespace == name } || SingleForm::Wrappers::Anonym.new(name)
end
@ -13,6 +15,8 @@ module SimpleForm
case item
when :error
Single.new(:error, :tag => SimpleForm.error_tag, :class => SimpleForm.error_class)
when :hint
Single.new(:hint, :tag => SimpleForm.hint_tag, :class => SimpleForm.hint_class)
else
item
end

View File

@ -5,7 +5,7 @@ class HintTest < ActionView::TestCase
def with_hint_for(object, attribute_name, type, options={}, &block)
with_concat_form_for(object) do |f|
options[:reflection] = Association.new(Company, :company, {}) if options.delete(:setup_association)
SimpleForm::Inputs::Base.new(f, attribute_name, nil, type, options).hint.to_s
f.hint attribute_name, options.merge(:as => type)
end
end
@ -21,8 +21,10 @@ class HintTest < ActionView::TestCase
test 'hint uses the current component tag set' do
swap SimpleForm, :hint_tag => :p do
with_hint_for @user, :name, :string, :hint => 'Use with care...'
assert_select 'p.hint', 'Use with care...'
swap SimpleForm, :components => [:hint] do
with_hint_for @user, :name, :string, :hint => 'Use with care...'
assert_select 'p.hint', 'Use with care...'
end
end
end
@ -68,7 +70,7 @@ class HintTest < ActionView::TestCase
end
test 'hint should be able to pass html options' do
with_hint_for @user, :name, :string, :hint => 'Yay!', :hint_html => { :id => 'hint', :class => 'yay' }
with_hint_for @user, :name, :string, :hint => 'Yay!', :id => 'hint', :class => 'yay'
assert_select 'span#hint.hint.yay'
end
end