Merge pull request #681 from balexand/zurb_foundation_3
Support for Zurb Foundation 3
This commit is contained in:
commit
95c1370aa4
10
README.md
10
README.md
|
@ -47,6 +47,16 @@ For more information see the generator output, our
|
|||
|
||||
**NOTE**: **SimpleForm** integration requires Twitter Bootstrap version 2.0 or higher.
|
||||
|
||||
### Zurb Foundation 3
|
||||
|
||||
To generate wrappers that are compatible with [Zurb Foundation 3](http://foundation.zurb.com/), pass the `foundation` option to the generator, like this:
|
||||
|
||||
`rails generate simple_form:install --foundation`
|
||||
|
||||
Please note that the Foundation wrapper does not support the `:hint` option by default. In order to enable hints, please uncomment the appropriate line in `config/initializers/simple_form_foundation.rb`. You will need to provide your own CSS styles for hints.
|
||||
|
||||
Please see the [instructions on how to install Foundation in a Rails app](http://foundation.zurb.com/docs/rails.php).
|
||||
|
||||
## Usage
|
||||
|
||||
**SimpleForm** was designed to be customized as you need to. Basically it's a stack of components that
|
||||
|
|
|
@ -5,12 +5,13 @@ module SimpleForm
|
|||
source_root File.expand_path('../templates', __FILE__)
|
||||
class_option :template_engine, :desc => 'Template engine to be invoked (erb, haml or slim).'
|
||||
class_option :bootstrap, :type => :boolean, :desc => 'Add the Twitter Bootstrap wrappers to the SimpleForm initializer.'
|
||||
class_option :foundation, :type => :boolean, :desc => 'Add the Zurb Foundation 3 wrappers to the SimpleForm initializer.'
|
||||
|
||||
def info_bootstrap
|
||||
return if options.bootstrap?
|
||||
puts "SimpleForm 2 supports Twitter bootstrap. In case you want to " \
|
||||
"generate bootstrap configuration, please re-run this " \
|
||||
"generator passing --bootstrap as option."
|
||||
return if options.bootstrap? || options.foundation?
|
||||
puts "SimpleForm 2 supports Twitter Bootstrap and Zurb Foundation 3. If you want "\
|
||||
"a configuration that is compatible with one of these frameworks, then please " \
|
||||
"re-run this generator with --bootstrap or --foundation as an option."
|
||||
end
|
||||
|
||||
def copy_config
|
||||
|
@ -18,6 +19,8 @@ module SimpleForm
|
|||
|
||||
if options[:bootstrap]
|
||||
template "config/initializers/simple_form_bootstrap.rb"
|
||||
elsif options[:foundation]
|
||||
template "config/initializers/simple_form_foundation.rb"
|
||||
end
|
||||
|
||||
directory 'config/locales'
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Use this setup block to configure all options available in SimpleForm.
|
||||
SimpleForm.setup do |config|
|
||||
config.wrappers :foundation, :class => :input, :hint_class => :field_with_hint, :error_class => :error do |b|
|
||||
b.use :html5
|
||||
b.use :placeholder
|
||||
b.optional :maxlength
|
||||
b.optional :pattern
|
||||
b.optional :min_max
|
||||
b.optional :readonly
|
||||
b.use :label_input
|
||||
b.use :error, :wrap_with => { :tag => :small }
|
||||
|
||||
# Uncomment the following line to enable hints. The line is commented out by default since Foundation
|
||||
# does't provide styles for hints. You will need to provide your own CSS styles for hints.
|
||||
# b.use :hint, :wrap_with => { :tag => :span, :class => :hint }
|
||||
end
|
||||
|
||||
# CSS class to add for error notification helper.
|
||||
config.error_notification_class = 'alert-box alert'
|
||||
|
||||
# The default wrapper to be used by the FormBuilder.
|
||||
config.default_wrapper = :foundation
|
||||
end
|
|
@ -25,6 +25,14 @@ class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
|||
/config\.default_wrapper = :bootstrap/
|
||||
end
|
||||
|
||||
test 'generates the simple_form initializer with the foundation wrappers' do
|
||||
run_generator %w(--foundation)
|
||||
assert_file 'config/initializers/simple_form.rb',
|
||||
/config\.default_wrapper = :default/, /config\.boolean_style = :nested/
|
||||
assert_file 'config/initializers/simple_form_foundation.rb', /config\.wrappers :foundation/,
|
||||
/config\.default_wrapper = :foundation/
|
||||
end
|
||||
|
||||
%W(erb haml slim).each do |engine|
|
||||
test "generates the scaffold template when using #{engine}" do
|
||||
run_generator ['-e', engine]
|
||||
|
|
Loading…
Reference in New Issue