add SimpleForm.default_wrapper

This commit is contained in:
Lucas Mazza 2012-01-24 16:54:28 -02:00
parent bcc4f1eada
commit e506e60f6a
4 changed files with 7 additions and 2 deletions

View File

@ -49,6 +49,8 @@ SimpleForm.setup do |config|
# Check the Bootstrap docs (http://twitter.github.com/bootstrap) # Check the Bootstrap docs (http://twitter.github.com/bootstrap)
# to learn about the different styles for forms and inputs, # to learn about the different styles for forms and inputs,
# buttons and other elements. # buttons and other elements.
config.default_wrapper :bootstrap
config.wrappers :bootstrap, :tag => 'fieldset', :class => 'control-group', :error_class => 'error' do |b| config.wrappers :bootstrap, :tag => 'fieldset', :class => 'control-group', :error_class => 'error' do |b|
b.use :placeholder b.use :placeholder
b.use :label, :class => 'control-label' b.use :label, :class => 'control-label'

View File

@ -113,6 +113,9 @@ module SimpleForm
@@button_class = 'button' @@button_class = 'button'
## WRAPPER CONFIGURATION ## WRAPPER CONFIGURATION
# The default wrapper to be used by the FormBuilder.
mattr_accessor :default_wrapper
@@default_wrapper = :default
@@wrappers = {} @@wrappers = {}
# Retrieves a given wrapper # Retrieves a given wrapper

View File

@ -32,7 +32,7 @@ module SimpleForm
def initialize(*) #:nodoc: def initialize(*) #:nodoc:
super super
@defaults = options[:defaults] @defaults = options[:defaults]
@wrapper = SimpleForm.wrapper(options[:wrapper] || :default) @wrapper = SimpleForm.wrapper(options[:wrapper] || SimpleForm.default_wrapper)
end end
# Basic input helper, combines all components in the stack to generate # Basic input helper, combines all components in the stack to generate

View File

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