From 346f79a21963ab5a594fccb1ac45aefa0db6cc75 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 26 Jan 2012 18:20:41 -0200 Subject: [PATCH] Generate nested boolean style by default for bootstrap --- .../config/initializers/simple_form.rb.tt | 23 +++++++++++++------ lib/simple_form.rb | 4 ++-- test/generators/simple_form_generator_test.rb | 6 +++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt b/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt index bc89e2d5..2c7ed6b9 100644 --- a/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt +++ b/lib/generators/simple_form/templates/config/initializers/simple_form.rb.tt @@ -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 diff --git a/lib/simple_form.rb b/lib/simple_form.rb index 199e30f2..438aebc9 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -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 diff --git a/test/generators/simple_form_generator_test.rb b/test/generators/simple_form_generator_test.rb index c522346a..0e11c584 100644 --- a/test/generators/simple_form_generator_test.rb +++ b/test/generators/simple_form_generator_test.rb @@ -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|