Merge branch 'bootstrap-generator'
This commit is contained in:
commit
2505d54a34
1
Gemfile
1
Gemfile
|
@ -2,6 +2,7 @@ source :rubygems
|
|||
|
||||
gemspec
|
||||
|
||||
gem 'railties', '~> 3.2.0'
|
||||
gem 'activemodel', '~> 3.2.0'
|
||||
gem 'actionpack', '~> 3.2.0'
|
||||
gem 'rake'
|
||||
|
|
11
Gemfile.lock
11
Gemfile.lock
|
@ -40,8 +40,17 @@ GEM
|
|||
rack (1.4.1)
|
||||
rack-cache (1.1)
|
||||
rack (>= 0.4)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.1)
|
||||
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)
|
||||
rbx-require-relative (0.0.5)
|
||||
rdoc (3.12)
|
||||
|
@ -55,6 +64,7 @@ GEM
|
|||
hike (~> 1.2)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
thor (0.14.6)
|
||||
tilt (1.3.3)
|
||||
tzinfo (0.3.31)
|
||||
|
||||
|
@ -65,6 +75,7 @@ DEPENDENCIES
|
|||
actionpack (~> 3.2.0)
|
||||
activemodel (~> 3.2.0)
|
||||
mocha
|
||||
railties (~> 3.2.0)
|
||||
rake
|
||||
rdoc
|
||||
ruby-debug
|
||||
|
|
|
@ -2,6 +2,7 @@ source :rubygems
|
|||
|
||||
gem 'simple_form', :path => '..'
|
||||
|
||||
gem 'railties', '~> 3.0.0'
|
||||
gem 'activemodel', '~> 3.0.0'
|
||||
gem 'actionpack', '~> 3.0.0'
|
||||
gem 'rake'
|
||||
|
|
|
@ -2,6 +2,7 @@ source :rubygems
|
|||
|
||||
gem 'simple_form', :path => '..'
|
||||
|
||||
gem 'railties', '~> 3.1.0'
|
||||
gem 'activemodel', '~> 3.1.0'
|
||||
gem 'actionpack', '~> 3.1.0'
|
||||
gem 'rake'
|
||||
|
|
|
@ -3,7 +3,8 @@ module SimpleForm
|
|||
class InstallGenerator < Rails::Generators::Base
|
||||
desc "Copy SimpleForm default files"
|
||||
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
|
||||
directory 'config'
|
||||
|
@ -13,6 +14,12 @@ module SimpleForm
|
|||
engine = options[:template_engine]
|
||||
copy_file "_form.html.#{engine}", "lib/templates/#{engine}/scaffold/_form.html.#{engine}"
|
||||
end
|
||||
|
||||
def show_readme
|
||||
if behavior == :invoke && options.bootstrap?
|
||||
readme "README"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
===============================================================================
|
||||
|
||||
Be sure to have a copy of the Bootstrap stylesheet available on your app,
|
||||
you can get in on http://twitter.github.com/bootstrap.
|
||||
|
||||
Inside your views, use the 'simple_form_for' with one of the Bootstrap form
|
||||
classes, '.form-horizontal', '.form-inline', '.form-search' or
|
||||
'.form-vertical', as the following:
|
||||
|
||||
= simple_form_for(@user, :html => {:class => 'form-horizontal' }) do |form|
|
||||
|
||||
===============================================================================
|
|
@ -45,6 +45,68 @@ SimpleForm.setup do |config|
|
|||
b.use :error, :tag => :span, :class => :error
|
||||
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.default_wrapper = :bootstrap
|
||||
|
||||
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.
|
||||
# config.error_method = :first
|
||||
|
|
@ -113,6 +113,9 @@ module SimpleForm
|
|||
@@button_class = 'button'
|
||||
|
||||
## WRAPPER CONFIGURATION
|
||||
# The default wrapper to be used by the FormBuilder.
|
||||
mattr_accessor :default_wrapper
|
||||
@@default_wrapper = :default
|
||||
@@wrappers = {}
|
||||
|
||||
# Retrieves a given wrapper
|
||||
|
|
|
@ -32,7 +32,7 @@ module SimpleForm
|
|||
def initialize(*) #:nodoc:
|
||||
super
|
||||
@defaults = options[:defaults]
|
||||
@wrapper = SimpleForm.wrapper(options[:wrapper] || :default)
|
||||
@wrapper = SimpleForm.wrapper(options[:wrapper] || SimpleForm.default_wrapper)
|
||||
end
|
||||
|
||||
# Basic input helper, combines all components in the stack to generate
|
||||
|
|
|
@ -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/, /config\.default_wrapper = :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__)
|
||||
require 'simple_form'
|
||||
|
||||
require "rails/generators/test_case"
|
||||
require 'generators/simple_form/install_generator'
|
||||
|
||||
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
||||
I18n.default_locale = :en
|
||||
|
||||
|
|
Loading…
Reference in New Issue