bootstrap_forms 2.0.6 → 2.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
- source "http://rubygems.org"
2
-
3
- gemspec
1
+ source :rubygems
2
+ gemspec
data/README.markdown CHANGED
@@ -183,6 +183,11 @@ You can add as many options to any form helper tag. If they are interpreted by B
183
183
  <td>Customize the field's label. Pass false to have no label.</td>
184
184
  <td><tt>= f.text_field :name, :label => 'Other name'</td></td>
185
185
  </tr>
186
+ <tr>
187
+ <th>control_group</th>
188
+ <td>Pass false to remove the control group and controls HTML, leaving only the label and input, wrapped in a plain div</td>
189
+ <td><tt>= f.text_field :name, :control_group => false</tt></td>
190
+ </tr>
186
191
  </table>
187
192
 
188
193
  Internationalization/Custom Errors
@@ -201,6 +206,15 @@ en:
201
206
 
202
207
  Obviously you can also change to a different `lang.yml` file and use the same syntax.
203
208
 
209
+ Nested Forms
210
+ ------------
211
+ Bootstrap Forms works with [Ryan Bates' nested_form](https://github.com/ryanb/nested_form) out of the box. Just add `nested_form` to you Gemfile and `bootstrap_forms` will automatically add a builder for you:
212
+
213
+ ```haml
214
+ = bootstrap_nested_form_for @model do |f|
215
+
216
+ ```
217
+
204
218
  Contributing
205
219
  ------------
206
220
  I'm pretty dam active on github. Fork and submit a pull request. Most of my pull requests are merged the same day. Make sure you:
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'bootstrap_forms'
6
- s.version = '2.0.6'
6
+ s.version = '2.0.8'
7
7
  s.author = 'Seth Vargo'
8
8
  s.email = 'sethvargo@gmail.com'
9
9
  s.homepage = 'https://github.com/sethvargo/bootstrap_forms'
@@ -3,4 +3,4 @@ en:
3
3
  errors:
4
4
  header: "There were errors that prevented this %{model} from being saved:"
5
5
  buttons:
6
- cancel: 'Cancel'
6
+ cancel: 'Cancel'
@@ -3,4 +3,4 @@ it:
3
3
  errors:
4
4
  header: "Alcuni errori hanno impedito il salvataggio di %{model}:"
5
5
  buttons:
6
- cancel: 'Cancella'
6
+ cancel: 'Cancella'
@@ -8,4 +8,4 @@ module BootstrapForms
8
8
  autoload :Helpers
9
9
  mattr_accessor(:default_form_builder)
10
10
  self.default_form_builder = BootstrapForms::FormBuilder
11
- end
11
+ end
@@ -5,7 +5,8 @@ module BootstrapForms
5
5
  ActiveSupport.on_load(:action_view) do
6
6
  include BootstrapForms::Helpers::FormHelper
7
7
  include BootstrapForms::Helpers::FormTagHelper
8
-
8
+ include BootstrapForms::Helpers::NestedFormHelper
9
+
9
10
  # Do not wrap errors in the extra div
10
11
  ::ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
11
12
  html_tag
@@ -14,4 +15,4 @@ module BootstrapForms
14
15
  end
15
16
  end
16
17
  end
17
- end
18
+ end
@@ -2,6 +2,7 @@ module BootstrapForms
2
2
  module Helpers
3
3
  autoload :FormHelper, 'bootstrap_forms/helpers/form_helper'
4
4
  autoload :FormTagHelper, 'bootstrap_forms/helpers/form_tag_helper'
5
+ autoload :NestedFormHelper, 'bootstrap_forms/helpers/nested_form_helper'
5
6
  autoload :Wrappers, 'bootstrap_forms/helpers/wrappers'
6
7
  end
7
- end
8
+ end
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'nested_form/builder_mixin'
3
+
4
+ module NestedForm
5
+ class TwitterBootstrapBuilder < ::BootstrapForms::FormBuilder
6
+ include ::NestedForm::BuilderMixin
7
+ end
8
+ end
9
+
10
+ module BootstrapForms
11
+ module Helpers
12
+ module NestedFormHelper
13
+ def bootstrap_nested_form_for(*args, &block)
14
+ options = args.extract_options!.reverse_merge(:builder => NestedForm::TwitterBootstrapBuilder)
15
+ form_for(*(args << options), &block) << after_nested_form_callbacks
16
+ end
17
+ end
18
+ end
19
+ end
20
+ rescue LoadError => e
21
+ module BootstrapForms
22
+ module Helpers
23
+ module NestedFormHelper
24
+ def bootstrap_nested_form_for(*args, &block)
25
+ raise 'nested_form was not found. Is it in your Gemfile?'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -10,12 +10,16 @@ module BootstrapForms
10
10
  @field_options[:error] = field_errors
11
11
  end
12
12
 
13
- klasses = ['control-group']
13
+ klasses = []
14
+ klasses << 'control-group' unless @field_options[:control_group] == false
14
15
  klasses << 'error' if @field_options[:error]
15
16
  klasses << 'success' if @field_options[:success]
16
17
  klasses << 'warning' if @field_options[:warning]
17
18
 
18
- content_tag(:div, :class => klasses, &block)
19
+ control_group_options = {}
20
+ control_group_options[:class] = klasses if !klasses.empty?
21
+
22
+ content_tag(:div, control_group_options, &block)
19
23
  end
20
24
 
21
25
  def error_string
@@ -34,26 +38,39 @@ module BootstrapForms
34
38
  end
35
39
 
36
40
  def input_div(&block)
37
- content_tag(:div, :class => 'controls') do
38
- if @field_options[:append] || @field_options[:prepend] || @field_options[:append_button]
39
- klass = []
40
- klass << 'input-prepend' if @field_options[:prepend]
41
- klass << 'input-append' if @field_options[:append] || @field_options[:append_button]
42
- content_tag(:div, :class => klass, &block)
43
- else
44
- yield if block_given?
41
+ content_options = {}
42
+ content_options[:class] = 'controls'
43
+ if @field_options[:control_group] == false
44
+ @field_options.delete :control_group
45
+ write_input_div(&block)
46
+ else
47
+ content_tag(:div, :class => 'controls') do
48
+ write_input_div(&block)
45
49
  end
46
50
  end
47
51
  end
48
52
 
53
+ def write_input_div(&block)
54
+ if @field_options[:append] || @field_options[:prepend] || @field_options[:append_button]
55
+ klass = []
56
+ klass << 'input-prepend' if @field_options[:prepend]
57
+ klass << 'input-append' if @field_options[:append] || @field_options[:append_button]
58
+ content_tag(:div, :class => klass, &block)
59
+ else
60
+ yield if block_given?
61
+ end
62
+ end
63
+
49
64
  def label_field(&block)
50
65
  if @field_options[:label] == '' || @field_options[:label] == false
51
66
  return ''.html_safe
52
67
  else
68
+ label_options = {}
69
+ label_options[:class] = 'control-label' unless @field_options[:control_group] == false
53
70
  if respond_to?(:object)
54
- label(@name, block_given? ? block : @field_options[:label], :class => 'control-label')
71
+ label(@name, block_given? ? block : @field_options[:label], label_options)
55
72
  else
56
- label_tag(@name, block_given? ? block : @field_options[:label], :class => 'control-label')
73
+ label_tag(@name, block_given? ? block : @field_options[:label], label_options)
57
74
  end
58
75
  end
59
76
  end
@@ -68,7 +85,7 @@ module BootstrapForms
68
85
  %w(help_inline error success warning help_block append append_button prepend).each do |method_name|
69
86
  define_method(method_name) do |*args|
70
87
  return '' unless value = @field_options[method_name.to_sym]
71
-
88
+
72
89
  escape = true
73
90
  tag_options = {}
74
91
  case method_name
@@ -82,15 +99,15 @@ module BootstrapForms
82
99
  element = :button
83
100
  button_options = value
84
101
  value = ''
85
-
102
+
86
103
  if button_options.has_key? :icon
87
104
  value << content_tag(:i, '', { :class => button_options.delete(:icon) })
88
105
  value << ' '
89
106
  escape = false
90
107
  end
91
-
108
+
92
109
  value << button_options.delete(:label)
93
-
110
+
94
111
  tag_options[:type] = 'button'
95
112
  tag_options[:class] = 'btn'
96
113
  tag_options.merge! button_options
@@ -107,7 +124,7 @@ module BootstrapForms
107
124
  end
108
125
 
109
126
  def objectify_options(options)
110
- super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append, :append_button)
127
+ super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append, :append_button, :control_group)
111
128
  end
112
129
  end
113
130
  end
@@ -142,22 +142,30 @@ shared_examples 'a bootstrap form' do
142
142
  it 'prepends and appends passed text' do
143
143
  @builder.text_field(:name, :append => '@', :prepend => '#').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend input-append\"><span class=\"add-on\">\#</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"add-on\">@</span></div></div></div>"
144
144
  end
145
-
145
+
146
146
  it 'appends button with default values' do
147
147
  @builder.text_field(:name, :append_button => { :label => 'button label' }).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><button class=\"btn\" type=\"button\">button label</button></div></div></div>"
148
148
  end
149
-
149
+
150
150
  it 'appends button and overrides class and type' do
151
151
  @builder.text_field(:name, :append_button => { :label => 'Danger!', :class => 'btn btn-danger', :type => 'submit' }).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><button class=\"btn btn-danger\" type=\"submit\">Danger!</button></div></div></div>"
152
152
  end
153
-
153
+
154
154
  it 'appends button with custom attributes' do
155
155
  @builder.text_field(:name, :append_button => { :label => 'button label', :data => { :custom_1 => 'value 1', :custom_2 => 'value 2' } }).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><button class=\"btn\" data-custom-1=\"value 1\" data-custom-2=\"value 2\" type=\"button\">button label</button></div></div></div>"
156
156
  end
157
-
157
+
158
158
  it 'appends button with an icon' do
159
159
  @builder.text_field(:name, :append_button => { :label => 'button label', :icon => 'icon-plus icon-white' }).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-append\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><button class=\"btn\" type=\"button\"><i class=\"icon-plus icon-white\"></i> button label</button></div></div></div>"
160
160
  end
161
+
162
+ it "does not add control group" do
163
+ @builder.text_field(:name, :control_group => false).should == "<div><label for=\"item_name\">Name</label><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /></div>"
164
+ end
165
+
166
+ it "does not add control group attribute to html if :control_group is true" do
167
+ @builder.text_field(:name, :control_group => true).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /></div></div>"
168
+ end
161
169
  end
162
170
 
163
171
  context 'label option' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-20 00:00:00.000000000 Z
12
+ date: 2012-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
@@ -132,6 +132,7 @@ files:
132
132
  - lib/bootstrap_forms/helpers.rb
133
133
  - lib/bootstrap_forms/helpers/form_helper.rb
134
134
  - lib/bootstrap_forms/helpers/form_tag_helper.rb
135
+ - lib/bootstrap_forms/helpers/nested_form_helper.rb
135
136
  - lib/bootstrap_forms/helpers/wrappers.rb
136
137
  - spec/dummy/Rakefile
137
138
  - spec/dummy/app/assets/javascripts/application.js
@@ -195,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
196
  version: '0'
196
197
  segments:
197
198
  - 0
198
- hash: 2313446882174708142
199
+ hash: -810555499159365620
199
200
  required_rubygems_version: !ruby/object:Gem::Requirement
200
201
  none: false
201
202
  requirements:
@@ -204,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  version: '0'
205
206
  segments:
206
207
  - 0
207
- hash: 2313446882174708142
208
+ hash: -810555499159365620
208
209
  requirements: []
209
210
  rubyforge_project:
210
211
  rubygems_version: 1.8.24