add the `--bootstrap` option to the simple_form:install generator
This commit is contained in:
parent
67da8d8861
commit
bcc4f1eada
1
Gemfile
1
Gemfile
|
@ -2,6 +2,7 @@ source :rubygems
|
||||||
|
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
|
gem 'railties', '~> 3.2.0'
|
||||||
gem 'activemodel', '~> 3.2.0'
|
gem 'activemodel', '~> 3.2.0'
|
||||||
gem 'actionpack', '~> 3.2.0'
|
gem 'actionpack', '~> 3.2.0'
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
|
|
11
Gemfile.lock
11
Gemfile.lock
|
@ -40,8 +40,17 @@ GEM
|
||||||
rack (1.4.1)
|
rack (1.4.1)
|
||||||
rack-cache (1.1)
|
rack-cache (1.1)
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
|
rack-ssl (1.3.2)
|
||||||
|
rack
|
||||||
rack-test (0.6.1)
|
rack-test (0.6.1)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
|
railties (3.2.0)
|
||||||
|
actionpack (= 3.2.0)
|
||||||
|
activesupport (= 3.2.0)
|
||||||
|
rack-ssl (~> 1.3.2)
|
||||||
|
rake (>= 0.8.7)
|
||||||
|
rdoc (~> 3.4)
|
||||||
|
thor (~> 0.14.6)
|
||||||
rake (0.9.2.2)
|
rake (0.9.2.2)
|
||||||
rbx-require-relative (0.0.5)
|
rbx-require-relative (0.0.5)
|
||||||
rdoc (3.12)
|
rdoc (3.12)
|
||||||
|
@ -55,6 +64,7 @@ GEM
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
tilt (~> 1.1, != 1.3.0)
|
tilt (~> 1.1, != 1.3.0)
|
||||||
|
thor (0.14.6)
|
||||||
tilt (1.3.3)
|
tilt (1.3.3)
|
||||||
tzinfo (0.3.31)
|
tzinfo (0.3.31)
|
||||||
|
|
||||||
|
@ -65,6 +75,7 @@ DEPENDENCIES
|
||||||
actionpack (~> 3.2.0)
|
actionpack (~> 3.2.0)
|
||||||
activemodel (~> 3.2.0)
|
activemodel (~> 3.2.0)
|
||||||
mocha
|
mocha
|
||||||
|
railties (~> 3.2.0)
|
||||||
rake
|
rake
|
||||||
rdoc
|
rdoc
|
||||||
ruby-debug
|
ruby-debug
|
||||||
|
|
|
@ -2,6 +2,7 @@ source :rubygems
|
||||||
|
|
||||||
gem 'simple_form', :path => '..'
|
gem 'simple_form', :path => '..'
|
||||||
|
|
||||||
|
gem 'railties', '~> 3.0.0'
|
||||||
gem 'activemodel', '~> 3.0.0'
|
gem 'activemodel', '~> 3.0.0'
|
||||||
gem 'actionpack', '~> 3.0.0'
|
gem 'actionpack', '~> 3.0.0'
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
|
|
|
@ -2,6 +2,7 @@ source :rubygems
|
||||||
|
|
||||||
gem 'simple_form', :path => '..'
|
gem 'simple_form', :path => '..'
|
||||||
|
|
||||||
|
gem 'railties', '~> 3.1.0'
|
||||||
gem 'activemodel', '~> 3.1.0'
|
gem 'activemodel', '~> 3.1.0'
|
||||||
gem 'actionpack', '~> 3.1.0'
|
gem 'actionpack', '~> 3.1.0'
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
|
|
|
@ -3,7 +3,8 @@ module SimpleForm
|
||||||
class InstallGenerator < Rails::Generators::Base
|
class InstallGenerator < Rails::Generators::Base
|
||||||
desc "Copy SimpleForm default files"
|
desc "Copy SimpleForm default files"
|
||||||
source_root File.expand_path('../templates', __FILE__)
|
source_root File.expand_path('../templates', __FILE__)
|
||||||
class_option :template_engine
|
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.'
|
||||||
|
|
||||||
def copy_config
|
def copy_config
|
||||||
directory 'config'
|
directory 'config'
|
||||||
|
|
|
@ -44,6 +44,66 @@ SimpleForm.setup do |config|
|
||||||
b.use :error, :tag => :span, :class => :error
|
b.use :error, :tag => :span, :class => :error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
<% 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.wrappers :bootstrap, :tag => 'fieldset', :class => 'control-group', :error_class => 'error' do |b|
|
||||||
|
b.use :placeholder
|
||||||
|
b.use :label, :class => 'control-label'
|
||||||
|
b.use :tag => 'div', :class => 'controls' do |ba|
|
||||||
|
ba.use :input
|
||||||
|
ba.use :error, :tag => 'span', :class => 'help-inline'
|
||||||
|
ba.use :hint, :tag => 'p', :class => 'help-block'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
config.wrappers :checkbox, :tag => 'fieldset', :class => 'control-group', :error_class => 'error' do |b|
|
||||||
|
b.use :placeholder
|
||||||
|
b.use :label, :class => 'control-label'
|
||||||
|
b.use :tag => 'div', :class => 'controls' do |ba|
|
||||||
|
ba.use :tag => 'label', :class => 'checkbox' do |bb|
|
||||||
|
bb.use :input
|
||||||
|
end
|
||||||
|
ba.use :error, :tag => 'span', :class => 'help-inline'
|
||||||
|
ba.use :hint, :tag => 'p', :class => 'help-block'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
config.wrappers :inline_checkbox, :tag => 'span', :error_class => 'error' do |b|
|
||||||
|
b.use :placeholder
|
||||||
|
b.use :input
|
||||||
|
b.use :label_text
|
||||||
|
b.use :error, :tag => 'span', :class => 'help-inline'
|
||||||
|
b.use :hint, :tag => 'p', :class => 'help-block'
|
||||||
|
end
|
||||||
|
|
||||||
|
config.wrappers :prepend, :tag => 'fieldset', :class => "control-group", :error_class => 'error' do |b|
|
||||||
|
b.use :placeholder
|
||||||
|
b.use :label, :class => 'control-label'
|
||||||
|
b.use :hint, :tag => 'span', :class => 'help-block'
|
||||||
|
b.use :tag => 'div', :class => 'controls' do |input|
|
||||||
|
input.use :tag => 'div', :class => 'input-prepend' do |prepend|
|
||||||
|
prepend.use :input
|
||||||
|
end
|
||||||
|
input.use :error, :tag => 'span', :class => 'help-inline'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
config.wrappers :append, :tag => 'fieldset', :class => "control-group", :error_class => 'error' do |b|
|
||||||
|
b.use :placeholder
|
||||||
|
b.use :label, :class => 'control-label'
|
||||||
|
b.use :hint, :tag => 'span', :class => 'help-block'
|
||||||
|
b.use :tag => 'div', :class => 'controls' do |input|
|
||||||
|
input.use :tag => 'div', :class => 'input-append' do |append|
|
||||||
|
append.use :input
|
||||||
|
end
|
||||||
|
input.use :error, :tag => 'span', :class => 'help-inline'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
<% end %>
|
||||||
|
|
||||||
# Method used to tidy up errors.
|
# Method used to tidy up errors.
|
||||||
# config.error_method = :first
|
# config.error_method = :first
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SimpleFormGeneratorTest < Rails::Generators::TestCase
|
||||||
|
tests SimpleForm::Generators::InstallGenerator
|
||||||
|
destination File.expand_path('../../tmp', __FILE__)
|
||||||
|
setup :prepare_destination
|
||||||
|
|
||||||
|
test 'generates example locale file' do
|
||||||
|
run_generator
|
||||||
|
assert_file 'config/locales/simple_form.en.yml'
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'generates the simple_form initializer' do
|
||||||
|
run_generator
|
||||||
|
assert_file 'config/initializers/simple_form.rb'
|
||||||
|
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/
|
||||||
|
end
|
||||||
|
|
||||||
|
%W(erb haml slim).each do |engine|
|
||||||
|
test "generates the scaffold template when using #{engine}" do
|
||||||
|
run_generator ['-e', engine]
|
||||||
|
assert_file "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,6 +22,9 @@ end
|
||||||
$:.unshift File.expand_path("../../lib", __FILE__)
|
$:.unshift File.expand_path("../../lib", __FILE__)
|
||||||
require 'simple_form'
|
require 'simple_form'
|
||||||
|
|
||||||
|
require "rails/generators/test_case"
|
||||||
|
require 'generators/simple_form/install_generator'
|
||||||
|
|
||||||
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
||||||
I18n.default_locale = :en
|
I18n.default_locale = :en
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue