bootstrap-generators 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (20) hide show
  1. data/README.md +17 -0
  2. data/lib/bootstrap-generators.rb +2 -0
  3. data/lib/bootstrap/generators/version.rb +1 -1
  4. data/lib/bootstrap/helpers/form_builder.rb +26 -0
  5. data/lib/generators/bootstrap/install/install_generator.rb +22 -0
  6. data/lib/generators/bootstrap/install/templates/app/inputs/boolean_input.rb +12 -0
  7. data/lib/generators/bootstrap/install/templates/app/inputs/collection_input.rb +12 -0
  8. data/lib/generators/bootstrap/install/templates/app/inputs/date_time_input.rb +16 -0
  9. data/lib/generators/bootstrap/install/templates/app/inputs/file_input.rb +16 -0
  10. data/lib/generators/bootstrap/install/templates/app/inputs/numeric_input.rb +16 -0
  11. data/lib/generators/bootstrap/install/templates/app/inputs/password_input.rb +16 -0
  12. data/lib/generators/bootstrap/install/templates/app/inputs/string_input.rb +16 -0
  13. data/lib/generators/bootstrap/install/templates/app/inputs/text_input.rb +16 -0
  14. data/lib/generators/bootstrap/install/templates/config/initializers/simple_form.rb +94 -0
  15. data/lib/generators/bootstrap/install/templates/{lib/templates/erb/scaffold → form_builders/form_builder}/_form.html.erb +3 -3
  16. data/lib/generators/bootstrap/install/templates/{lib/templates/haml/scaffold → form_builders/form_builder}/_form.html.haml +1 -1
  17. data/lib/generators/bootstrap/install/templates/form_builders/simple_form/_form.html.erb +18 -0
  18. data/lib/generators/bootstrap/install/templates/form_builders/simple_form/_form.html.haml +13 -0
  19. data/test/lib/generators/bootstrap/install_generator_test.rb +26 -0
  20. metadata +24 -12
data/README.md CHANGED
@@ -6,8 +6,25 @@ Add it to your Gemfile:
6
6
 
7
7
  `gem 'bootstrap-generators'`
8
8
 
9
+ By default Bootstrap Generators requires SimpleForm. Add the dependency on your Gemfile:
10
+
11
+ `gem 'simple_form', '~> 1.5'`
12
+
13
+ If you don't want to use SimpleForm, and instead use the default Rails form builder, just call the install generator with `--form_builder=form_builder`.
14
+
9
15
  Run the generator:
10
16
 
11
17
  `rails generate bootstrap:install`
12
18
 
13
19
  Once you've done that, any time you generate a controller or scaffold, you'll get [Bootstrap](http://twitter.github.com/bootstrap/) templates.
20
+
21
+ ## Form builders
22
+
23
+ ### Default Rails form builder
24
+
25
+ `rails generate bootstrap:install --form_builder=form_builder`
26
+
27
+ ### SimpleForm
28
+
29
+ `rails generate bootstrap:install --form_builder=simple_form`
30
+
@@ -1,4 +1,5 @@
1
1
  require 'rails'
2
+ require 'bootstrap/helpers/form_builder'
2
3
 
3
4
  module Bootstrap
4
5
  module Generators
@@ -13,3 +14,4 @@ module Bootstrap
13
14
  end
14
15
  end
15
16
  end
17
+
@@ -1,5 +1,5 @@
1
1
  module Bootstrap
2
2
  module Generators
3
- VERSION = "0.0.6"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,26 @@
1
+ require 'action_view'
2
+
3
+ module Bootstrap
4
+ module Helpers
5
+ class FormBuilder < ActionView::Helpers::FormBuilder
6
+ def text_field(method, options = {:class => "xxlarge"})
7
+ super
8
+ end
9
+
10
+ def text_area(method, options = {:class => "xxlarge"})
11
+ super
12
+ end
13
+
14
+ def password_field(method, options = {:class => "xxlarge"})
15
+ super
16
+ end
17
+
18
+ def submit(value=nil, options={:class => "btn primary"})
19
+ super
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ ActionView::Base.default_form_builder = Bootstrap::Helpers::FormBuilder
26
+
@@ -6,6 +6,7 @@ module Bootstrap
6
6
  desc "Copy BootstrapGenerators default files"
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
  class_option :layout, :desc => "Bootstrap layout templates (hero, fluid or container-app)", :default => "hero", :type => :string
9
+ class_option :form_builder, :desc => "Select your form builder (form_builder or simple_form)", :default => "simple_form", :type => :string
9
10
 
10
11
  class_option :template_engine
11
12
 
@@ -13,6 +14,26 @@ module Bootstrap
13
14
  directory "lib/templates/#{options[:template_engine]}"
14
15
  end
15
16
 
17
+ def copy_form_builder
18
+ if options[:form_builder].nil?
19
+ copy_file "form_builders/form_builder/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}"
20
+ else
21
+ copy_file "form_builders/#{options[:form_builder]}/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}"
22
+ end
23
+ end
24
+
25
+ def copy_simple_form_inputs
26
+ if options[:form_builder] == "simple_form"
27
+ directory 'app'
28
+ end
29
+ end
30
+
31
+ def copy_simple_form_config
32
+ if options[:form_builder] == "simple_form"
33
+ directory 'config'
34
+ end
35
+ end
36
+
16
37
  def create_layout
17
38
  template "layouts/#{options[:layout]}.html.#{options[:template_engine]}", "app/views/layouts/application.html.#{options[:template_engine]}"
18
39
  copy_file "layouts/#{options[:layout]}.css.scss", "app/assets/stylesheets/bootstrap-generators.css.scss"
@@ -21,3 +42,4 @@ module Bootstrap
21
42
  end
22
43
  end
23
44
  end
45
+
@@ -0,0 +1,12 @@
1
+ class BooleanInput < SimpleForm::Inputs::BooleanInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\"><ul class=\"inputs-list\"><li><label>#{content}</label></li></ul></div>".html_safe
10
+ end
11
+ end
12
+
@@ -0,0 +1,12 @@
1
+ class CollectionInput < SimpleForm::Inputs::CollectionInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+ end
12
+
@@ -0,0 +1,16 @@
1
+ class DateTimeInput < SimpleForm::Inputs::DateTimeInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+
12
+ def input_html_classes
13
+ super.unshift("small")
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ class FileInput < SimpleForm::Inputs::FileInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+
12
+ def input_html_classes
13
+ super.unshift("xxlarge")
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ class NumericInput < SimpleForm::Inputs::NumericInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+
12
+ def input_html_classes
13
+ super.unshift("xxlarge")
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ class PasswordInput < SimpleForm::Inputs::PasswordInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+
12
+ def input_html_classes
13
+ super.unshift("xxlarge")
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ class StringInput < SimpleForm::Inputs::StringInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+
12
+ def input_html_classes
13
+ super.unshift("xxlarge")
14
+ end
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ class TextInput < SimpleForm::Inputs::TextInput
2
+ def label_input
3
+ content = "".html_safe
4
+ [ :input, :error, :hint ].each do |component|
5
+ next if options[component] == false
6
+ rendered = send(component)
7
+ content.safe_concat rendered.to_s if rendered
8
+ end
9
+ (options[:label] == false ? "" : label) + "<div class=\"input\">#{content}</div>".html_safe
10
+ end
11
+
12
+ def input_html_classes
13
+ super.unshift("xxlarge")
14
+ end
15
+ end
16
+
@@ -0,0 +1,94 @@
1
+ # Use this setup block to configure all options available in SimpleForm.
2
+ SimpleForm.setup do |config|
3
+ # Components used by the form builder to generate a complete input. You can remove
4
+ # any of them, change the order, or even add your own components to the stack.
5
+ config.components = [ :placeholder, :label_input ]
6
+
7
+ # Default tag used on hints.
8
+ # config.hint_tag = :span
9
+
10
+ # CSS class to add to all hint tags.
11
+ config.hint_class = "help-block"
12
+
13
+ # CSS class used on errors.
14
+ config.error_class = "help-inline"
15
+
16
+ # Default tag used on errors.
17
+ # config.error_tag = :span
18
+
19
+ # Method used to tidy up errors.
20
+ # config.error_method = :first
21
+
22
+ # Default tag used for error notification helper.
23
+ # config.error_notification_tag = :p
24
+
25
+ # CSS class to add for error notification helper.
26
+ # config.error_notification_class = :error_notification
27
+
28
+ # ID to add for error notification helper.
29
+ # config.error_notification_id = nil
30
+
31
+ # You can wrap all inputs in a pre-defined tag.
32
+ # config.wrapper_tag = :div
33
+
34
+ # CSS class to add to all wrapper tags.
35
+ config.wrapper_class = :clearfix
36
+
37
+ # CSS class to add to the wrapper if the field has errors.
38
+ config.wrapper_error_class = :error
39
+
40
+ # You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
41
+ # config.collection_wrapper_tag = nil
42
+
43
+ # You can wrap each item in a collection of radio/check boxes with a tag, defaulting to span.
44
+ # config.item_wrapper_tag = :span
45
+
46
+ # Series of attempts to detect a default label method for collection.
47
+ # config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
48
+
49
+ # Series of attempts to detect a default value method for collection.
50
+ # config.collection_value_methods = [ :id, :to_s ]
51
+
52
+ # How the label text should be generated altogether with the required text.
53
+ # config.label_text = lambda { |label, required| "#{required} #{label}" }
54
+
55
+ # You can define the class to use on all labels. Default is nil.
56
+ # config.label_class = nil
57
+
58
+ # You can define the class to use on all forms. Default is simple_form.
59
+ # config.form_class = :"form-stacked"
60
+
61
+ # Whether attributes are required by default (or not). Default is true.
62
+ # config.required_by_default = true
63
+
64
+ # Tell browsers whether to use default HTML5 validations (novalidate option).
65
+ # Default is enabled.
66
+ config.browser_validations = false
67
+
68
+ # Determines whether HTML5 types (:email, :url, :search, :tel) and attributes
69
+ # (e.g. required) are used or not. True by default.
70
+ # Having this on in non-HTML5 compliant sites can cause odd behavior in
71
+ # HTML5-aware browsers such as Chrome.
72
+ # config.html5 = true
73
+
74
+ # Custom mappings for input types. This should be a hash containing a regexp
75
+ # to match as key, and the input type that will be used when the field name
76
+ # matches the regexp as value.
77
+ # config.input_mappings = { /count/ => :integer }
78
+
79
+ # Collection of methods to detect if a file type was given.
80
+ # config.file_methods = [ :mounted_as, :file?, :public_filename ]
81
+
82
+ # Default priority for time_zone inputs.
83
+ # config.time_zone_priority = nil
84
+
85
+ # Default priority for country inputs.
86
+ # config.country_priority = nil
87
+
88
+ # Default size for text inputs.
89
+ # config.default_input_size = 50
90
+
91
+ # When false, do not use translations for labels, hints or placeholders.
92
+ # config.translate = true
93
+ end
94
+
@@ -15,11 +15,11 @@
15
15
  <div class="clearfix">
16
16
  <%%= f.label :<%= attribute.name %> %>
17
17
  <div class="input">
18
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => "<%= [:datetime_select, :date_select].include?(attribute.field_type) ? 'small' : 'xxlarge' %>" %>
18
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
19
19
  </div>
20
20
  </div>
21
21
  <% end -%>
22
22
  <div class="actions">
23
- <%%= f.submit :class => "btn primary" %>
23
+ <%%= f.submit %>
24
24
  </div>
25
- <%% end %>
25
+ <%% end %>
@@ -11,7 +11,7 @@
11
11
  .clearfix
12
12
  = f.label :<%= attribute.name %>
13
13
  .input
14
- = f.<%= attribute.field_type %> :<%= attribute.name %>, :class => "<%= [:datetime_select, :date_select].include?(attribute.field_type) ? 'small' : 'xxlarge' %>"
14
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
15
15
  <% end -%>
16
16
  .actions
17
17
  = f.submit :class => 'btn primary'
@@ -0,0 +1,18 @@
1
+ <%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div class="alert-message error">
4
+ <%%= f.error_notification %>
5
+ </div>
6
+ <%% end %>
7
+
8
+ <div class="inputs">
9
+ <%- attributes.each do |attribute| -%>
10
+ <%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
11
+ <%- end -%>
12
+ </div>
13
+
14
+ <div class="actions">
15
+ <%%= f.button :submit, :class => "btn primary" %>
16
+ </div>
17
+ <%% end %>
18
+
@@ -0,0 +1,13 @@
1
+ = simple_form_for(@<%= singular_table_name %>) do |f|
2
+ -if @<%= singular_table_name %>.errors.any?
3
+ .alert-message.error
4
+ = f.error_notification
5
+
6
+ .inputs
7
+ <%- attributes.each do |attribute| -%>
8
+ = f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %>
9
+ <%- end -%>
10
+
11
+ .actions
12
+ = f.button :submit, :class => "btn primary"
13
+
@@ -82,4 +82,30 @@ class Bootstrap::Generators::InstallGeneratorTest < ::Rails::Generators::TestCas
82
82
 
83
83
  assert_file "app/views/layouts/application.html.haml"
84
84
  end
85
+
86
+ test "should create erb form partial with simple_form form builder" do
87
+ run_generator %w(--form-builder simple_form)
88
+
89
+ assert_file "lib/templates/erb/scaffold/_form.html.erb"
90
+ end
91
+
92
+ test "should create haml form partial with simple_form form builder" do
93
+ run_generator %w(--form-builder simple_form --template-engine haml)
94
+
95
+ assert_file "lib/templates/haml/scaffold/_form.html.haml"
96
+ end
97
+
98
+ test "should copy inputs when simple_form form builder selected" do
99
+ run_generator %w(--form-builder simple_form)
100
+
101
+ %w(boolean collection date_time file numeric password string text).each { |input|
102
+ assert_file "app/inputs/#{input}_input.rb"
103
+ }
104
+ end
105
+
106
+ test "should copy config when simple_form form builder selected" do
107
+ run_generator %w(--form-builder simple_form)
108
+
109
+ assert_file "config/initializers/simple_form.rb"
110
+ end
85
111
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap-generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-20 00:00:00.000000000Z
12
+ date: 2011-10-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &2152225480 !ruby/object:Gem::Requirement
16
+ requirement: &2157041520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152225480
24
+ version_requirements: *2157041520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: test-unit
27
- requirement: &2152224800 !ruby/object:Gem::Requirement
27
+ requirement: &2157040700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152224800
35
+ version_requirements: *2157040700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &2152223280 !ruby/object:Gem::Requirement
38
+ requirement: &2157036900 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152223280
46
+ version_requirements: *2157036900
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: railties
49
- requirement: &2152222000 !ruby/object:Gem::Requirement
49
+ requirement: &2157025620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2152222000
57
+ version_requirements: *2157025620
58
58
  description: Bootstrap-generators provides Twitter Bootstrap generators for Rails
59
59
  3. Bootstrap is a toolkit from Twitter designed to kickstart development of webapps
60
60
  and sites. Checkout http://twitter.github.com/bootstrap.
@@ -73,8 +73,22 @@ files:
73
73
  - lib/bootstrap/generators/engine.rb
74
74
  - lib/bootstrap/generators/railtie.rb
75
75
  - lib/bootstrap/generators/version.rb
76
+ - lib/bootstrap/helpers/form_builder.rb
76
77
  - lib/generators/bootstrap/install/install_generator.rb
78
+ - lib/generators/bootstrap/install/templates/app/inputs/boolean_input.rb
79
+ - lib/generators/bootstrap/install/templates/app/inputs/collection_input.rb
80
+ - lib/generators/bootstrap/install/templates/app/inputs/date_time_input.rb
81
+ - lib/generators/bootstrap/install/templates/app/inputs/file_input.rb
82
+ - lib/generators/bootstrap/install/templates/app/inputs/numeric_input.rb
83
+ - lib/generators/bootstrap/install/templates/app/inputs/password_input.rb
84
+ - lib/generators/bootstrap/install/templates/app/inputs/string_input.rb
85
+ - lib/generators/bootstrap/install/templates/app/inputs/text_input.rb
77
86
  - lib/generators/bootstrap/install/templates/bootstrap-generators.js
87
+ - lib/generators/bootstrap/install/templates/config/initializers/simple_form.rb
88
+ - lib/generators/bootstrap/install/templates/form_builders/form_builder/_form.html.erb
89
+ - lib/generators/bootstrap/install/templates/form_builders/form_builder/_form.html.haml
90
+ - lib/generators/bootstrap/install/templates/form_builders/simple_form/_form.html.erb
91
+ - lib/generators/bootstrap/install/templates/form_builders/simple_form/_form.html.haml
78
92
  - lib/generators/bootstrap/install/templates/layouts/container-app.css.scss
79
93
  - lib/generators/bootstrap/install/templates/layouts/container-app.html.erb
80
94
  - lib/generators/bootstrap/install/templates/layouts/container-app.html.haml
@@ -85,13 +99,11 @@ files:
85
99
  - lib/generators/bootstrap/install/templates/layouts/hero.html.erb
86
100
  - lib/generators/bootstrap/install/templates/layouts/hero.html.haml
87
101
  - lib/generators/bootstrap/install/templates/lib/templates/erb/controller/view.html.erb
88
- - lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/_form.html.erb
89
102
  - lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/edit.html.erb
90
103
  - lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/index.html.erb
91
104
  - lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/new.html.erb
92
105
  - lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/show.html.erb
93
106
  - lib/generators/bootstrap/install/templates/lib/templates/haml/controller/view.html.haml
94
- - lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/_form.html.haml
95
107
  - lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/edit.html.haml
96
108
  - lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/index.html.haml
97
109
  - lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/new.html.haml