Generate nested boolean style by default for bootstrap

This commit is contained in:
Carlos Antonio da Silva 2012-01-26 18:20:41 -02:00
parent fe8e36ab91
commit 346f79a219
3 changed files with 22 additions and 11 deletions

View File

@ -44,13 +44,19 @@ SimpleForm.setup do |config|
b.use :hint, :tag => :span, :class => :hint
b.use :error, :tag => :span, :class => :error
end
<% if options.bootstrap? %>
<% if options.bootstrap? %>
# Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
# Check the Bootstrap docs (http://twitter.github.com/bootstrap)
# to learn about the different styles for forms and inputs,
# buttons and other elements.
config.default_wrapper = :bootstrap
# Define the way to render check boxes / radio buttons with labels.
# Defaults to :nested for bootstrap config.
# :inline => input + label
# :nested => label > input
config.boolean_style = :nested
config.wrappers :bootstrap, :tag => 'fieldset', :class => 'control-group', :error_class => 'error' do |b|
b.use :placeholder
b.use :label, :class => 'control-label'
@ -84,7 +90,15 @@ SimpleForm.setup do |config|
input.use :error, :tag => 'span', :class => 'help-inline'
end
end
<% end %>
<% else %>
# The default wrapper to be used by the FormBuilder.
config.default_wrapper = :default
# Define the way to render check boxes / radio buttons with labels.
# :inline => input + label
# :nested => label > input
config.boolean_style = :inline
<% end %>
# Method used to tidy up errors.
# config.error_method = :first
@ -118,11 +132,6 @@ SimpleForm.setup do |config|
# You can define the class to use on all labels. Default is nil.
# config.label_class = nil
# Define the way to render checkboxes with labels. Defaults to :inline.
# :inline => input + label
# :nested => label > input
# config.boolean_style = :inline
# You can define the class to use on all forms. Default is simple_form.
# config.form_class = :simple_form

View File

@ -61,8 +61,8 @@ module SimpleForm
mattr_accessor :label_class
@@label_class = nil
# Define the way to render checkboxes with labels. Defaults to :inline.
# :inline => input + label
# Define the way to render check boxes / radio buttons with labels.
# :inline => input + label (default)
# :nested => label > input
mattr_accessor :boolean_style
@@boolean_style = :inline

View File

@ -13,12 +13,14 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
test 'generates the simple_form initializer' do
run_generator
assert_file 'config/initializers/simple_form.rb'
assert_file 'config/initializers/simple_form.rb',
/config\.default_wrapper = :default/, /config\.boolean_style = :inline/
end
test 'generates the simple_form initializer with the bootstrap wrappers' do
run_generator %w(--bootstrap)
assert_file 'config/initializers/simple_form.rb', /config\.wrappers :bootstrap/, /config\.default_wrapper = :bootstrap/
assert_file 'config/initializers/simple_form.rb', /config\.wrappers :bootstrap/,
/config\.default_wrapper = :bootstrap/, /config\.boolean_style = :nested/
end
%W(erb haml slim).each do |engine|