bootstrap_forms 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52a07c0b5800f1cf485f3fc14a4a0bed1875b362
4
+ data.tar.gz: 5d3026f949c7fbcfca51d167394b6935fde259ca
5
+ SHA512:
6
+ metadata.gz: 197254e010f62e86ce62660f0b1653e27f21b171aa7267aa5f440814a4a9d62ac8b7f271c9b17037616f2ef29a7f30da1f7138136811991052c9ad44624c8155
7
+ data.tar.gz: 0abc20f96bb0944190add8e957e6fd8e6627f786c1c1c2e2ac5216673f164b0f572bb394096f6229d63972732d95377566d6ff1081e264a77b3c9e80e07e184e
@@ -0,0 +1,12 @@
1
+ CHANGELOG
2
+ =========
3
+ v4.0.1
4
+ ------
5
+ - Fix critical UI bug when displaying radio/checkbox collections (@sshaw)
6
+
7
+ v4.0.0
8
+ ------
9
+ - Created a CHANGELOG
10
+ - **WARN**: Dropped support for 1.8/ree
11
+ - **WARN**: Removed tests for Ruby 1.9.1 and 1.9.2 (blame Capybara)
12
+ - **WARN**: License changed to Apache 2.0
data/README.md CHANGED
@@ -103,6 +103,12 @@ You can set the `:inline` option to build inline radios.
103
103
  = f.radio_buttons :published, { "Published" => true, "Unpublished" => false }, { :inline => true }
104
104
  ```
105
105
 
106
+ You can set radio options by passing a hash instead of a value:
107
+
108
+ ```haml
109
+ = f.radio_buttons :published, { "Published" => true, "Unpublished" => {:value => false, :disabled => true} }
110
+ ```
111
+
106
112
  Ruby 1.8 doesn't guarantee hashes are ordered. If you care, pass in nested arrays or `ActiveSupport::OrderedHash`.
107
113
 
108
114
  Uneditable Input
@@ -108,11 +108,20 @@ module BootstrapForms
108
108
  label_field + input_div do
109
109
  klasses = 'radio'
110
110
  klasses << ' inline' if @field_options.delete(:inline) == true
111
- values.map do |text, value|
111
+
112
+ buttons = values.map do |text, value|
113
+ radio_options = @field_options
114
+ if value.is_a? Hash
115
+ radio_options = radio_options.merge(value)
116
+ value = radio_options.delete(:value)
117
+ end
118
+
112
119
  label("#{@name}_#{value}", :class => klasses) do
113
- extras { radio_button(name, value, @field_options) + text }
120
+ radio_button(name, value, radio_options) + text
114
121
  end
115
- end.join.html_safe
122
+ end.join('')
123
+ buttons << extras
124
+ buttons.html_safe
116
125
  end
117
126
  end
118
127
  end
@@ -123,18 +132,20 @@ module BootstrapForms
123
132
  @args = args
124
133
 
125
134
  control_group_div do
126
- label_field + extras do
127
- content_tag(:div, :class => 'controls') do
128
- options = @field_options.merge(required_attribute)
129
- records.collect do |record|
130
- options[:id] = "#{object_name}_#{attribute}_#{record.send(record_id)}"
131
- checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), [object.send(attribute)].flatten.include?(record.send(record_id)), options)
132
-
133
- content_tag(:label, :class => ['checkbox', ('inline' if @field_options[:inline])].compact) do
134
- checkbox + content_tag(:span, record.send(record_name))
135
- end
136
- end.join('').html_safe
137
- end
135
+ label_field + input_div do
136
+ options = @field_options.except(*BOOTSTRAP_OPTIONS).merge(required_attribute)
137
+ # Since we're using check_box_tag() we may have to lookup the instance ourselves
138
+ instance = object || @template.instance_variable_get("@#{object_name}")
139
+ boxes = records.collect do |record|
140
+ options[:id] = "#{object_name}_#{attribute}_#{record.send(record_id)}"
141
+ checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), [instance.send(attribute)].flatten.include?(record.send(record_id)), options)
142
+
143
+ content_tag(:label, :class => ['checkbox', ('inline' if @field_options[:inline])].compact) do
144
+ checkbox + record.send(record_name)
145
+ end
146
+ end.join('')
147
+ boxes << extras
148
+ boxes.html_safe
138
149
  end
139
150
  end
140
151
  end
@@ -145,18 +156,16 @@ module BootstrapForms
145
156
  @args = args
146
157
 
147
158
  control_group_div do
148
- label_field + extras do
149
- content_tag(:div, :class => 'controls') do
150
- options = @field_options.merge(required_attribute)
151
- records.collect do |record|
152
- options[:id] = "#{object_name}_#{attribute}_#{record.send(record_id)}"
153
- radiobutton = radio_button_tag("#{object_name}[#{attribute}]", record.send(record_id), object.send(attribute) == record.send(record_id), options)
154
-
155
- content_tag(:label, :class => ['radio', ('inline' if @field_options[:inline])].compact) do
156
- radiobutton + content_tag(:span, record.send(record_name))
157
- end
158
- end.join('').html_safe
159
- end
159
+ label_field + input_div do
160
+ options = @field_options.merge(required_attribute)
161
+ buttons = records.collect do |record|
162
+ radiobutton = radio_button(attribute, record.send(record_id), options)
163
+ content_tag(:label, :class => ['radio', ('inline' if @field_options[:inline])].compact) do
164
+ radiobutton + record.send(record_name)
165
+ end
166
+ end.join('')
167
+ buttons << extras
168
+ buttons.html_safe
160
169
  end
161
170
  end
162
171
  end
@@ -220,7 +229,6 @@ module BootstrapForms
220
229
  end
221
230
 
222
231
  private
223
-
224
232
  def field_options(args)
225
233
  if @options
226
234
  @options.slice(:namespace, :index).merge(args)
@@ -1,6 +1,8 @@
1
1
  module BootstrapForms
2
2
  module Helpers
3
3
  module Wrappers
4
+ BOOTSTRAP_OPTIONS = [ :label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append, :append_button, :control_group ]
5
+
4
6
  private
5
7
  def control_group_div(&block)
6
8
  field_errors = error_string
@@ -141,6 +143,9 @@ module BootstrapForms
141
143
  tag_options[:type] = 'button'
142
144
  tag_options[:class] = 'btn'
143
145
  tag_options.merge! button_options
146
+ when 'error', 'success', 'warning'
147
+ element = :span
148
+ tag_options[:class] = "help-inline #{method_name}-message"
144
149
  else
145
150
  element = :span
146
151
  tag_options[:class] = 'help-inline'
@@ -161,7 +166,7 @@ module BootstrapForms
161
166
  end
162
167
 
163
168
  def objectify_options(options)
164
- super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append, :append_button, :control_group)
169
+ super.except(*BOOTSTRAP_OPTIONS)
165
170
  end
166
171
  end
167
172
  end
@@ -1,3 +1,3 @@
1
1
  module BootstrapForms
2
- VERSION = '4.0.0'
2
+ VERSION = '4.0.1'
3
3
  end
@@ -83,25 +83,25 @@ describe 'BootstrapForms::FormBuilder' do
83
83
  end
84
84
 
85
85
  it 'have error message on field' do
86
- @builder.text_field('name').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">Name is invalid</span></div></div>"
86
+ @builder.text_field('name').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline error-message\">Name is invalid</span></div></div>"
87
87
  end
88
88
 
89
89
  it "joins passed error message and validation errors with ', '" do
90
- @builder.text_field('name', :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This is an error!, Name is invalid</span></div></div>"
90
+ @builder.text_field('name', :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline error-message\">This is an error!, Name is invalid</span></div></div>"
91
91
  end
92
92
  end
93
-
93
+
94
94
  context "errors with translations" do
95
95
  before(:all) { I18n.backend.store_translations I18n.locale, {:errors => {:format => "%{message}", :messages => {:invalid => "Nope"}}} }
96
96
  after(:all) { I18n.backend.reload! }
97
-
97
+
98
98
  before(:each) do
99
99
  @project.errors.add('name')
100
100
  @result = @builder.error_messages
101
101
  end
102
-
102
+
103
103
  it 'use i18n format on field error message' do
104
- @builder.text_field('name').should match /<span class="help-inline">Nope<\/span>/
104
+ @builder.text_field('name').should match /<span class="help-inline error-message">Nope<\/span>/
105
105
  end
106
106
  end
107
107
 
@@ -153,7 +153,8 @@ describe 'BootstrapForms::FormBuilder' do
153
153
 
154
154
  context 'setup builder with a symbol' do
155
155
  before(:each) do
156
- @template = ActionView::Base.new
156
+ @project = Project.new
157
+ @template = ActionView::Base.new(nil, :item => @project)
157
158
  @template.output_buffer = ''
158
159
  @builder = BootstrapForms::FormBuilder.new(:item, nil, @template, {}, proc {})
159
160
  end
@@ -80,6 +80,20 @@ shared_examples 'a bootstrap form' do
80
80
  it 'adds inline class' do
81
81
  @builder.radio_buttons(:name, @options, {:inline => true}).should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio inline\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio inline\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label></div></div>"
82
82
  end
83
+
84
+ it 'adds block help' do
85
+ @builder.radio_buttons(:name, @options, :help_block => "Help me!").should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\" for=\"item_name_1\"><input id=\"item_name_1\" name=\"item[name]\" type=\"radio\" value=\"1\" />One</label><label class=\"radio\" for=\"item_name_2\"><input id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two</label><span class=\"help-block\">Help me!</span></div></div>"
86
+ end
87
+
88
+ describe "with disabled option" do
89
+ before do
90
+ @options = {'One' => '1', 'Two' => {:value => '2', :disabled => true}}
91
+ end
92
+
93
+ it 'adds the disabled attribute' do
94
+ @builder.radio_buttons(:name, @options).should include("<input disabled=\"disabled\" id=\"item_name_2\" name=\"item[name]\" type=\"radio\" value=\"2\" />Two<")
95
+ end
96
+ end
83
97
  end
84
98
 
85
99
  (%w{email file number password range search text url }.map{|field| ["#{field}_field",field]} + [['telephone_field', 'tel'], ['phone_field', 'tel']]).each do |field, type|
@@ -113,6 +127,34 @@ shared_examples 'a bootstrap form' do
113
127
  end # field
114
128
  end # fields
115
129
 
130
+ describe 'collection_radio_buttons' do
131
+ before do
132
+ @options = [ [["foo", "Foo"], ["bar", "Bar"]], :first, :last ]
133
+ end
134
+
135
+ it 'generates wrapped input' do
136
+ @builder.collection_radio_buttons(:name, *@options).should eq "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\"><input id=\"item_name_foo\" name=\"item[name]\" type=\"radio\" value=\"foo\" />Foo</label><label class=\"radio\"><input id=\"item_name_bar\" name=\"item[name]\" type=\"radio\" value=\"bar\" />Bar</label></div></div>"
137
+ end
138
+
139
+ it 'adds block help' do
140
+ @builder.collection_radio_buttons(:name, *@options, :help_block => "Help me!").should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"radio\"><input id=\"item_name_foo\" name=\"item[name]\" type=\"radio\" value=\"foo\" />Foo</label><label class=\"radio\"><input id=\"item_name_bar\" name=\"item[name]\" type=\"radio\" value=\"bar\" />Bar</label><span class=\"help-block\">Help me!</span></div></div>"
141
+ end
142
+ end
143
+
144
+ describe 'collection_check_boxes' do
145
+ before do
146
+ @options = [ [["foo", "Foo"], ["bar", "Bar"]], :first, :last ]
147
+ end
148
+
149
+ it 'generates wrapped input' do
150
+ @builder.collection_check_boxes(:name, *@options).should eq "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"checkbox\"><input id=\"item_name_foo\" name=\"item[name][]\" type=\"checkbox\" value=\"foo\" />Foo</label><label class=\"checkbox\"><input id=\"item_name_bar\" name=\"item[name][]\" type=\"checkbox\" value=\"bar\" />Bar</label></div></div>"
151
+ end
152
+
153
+ it 'adds block help' do
154
+ @builder.collection_check_boxes(:name, *@options, :help_block => "Help me!").should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><label class=\"checkbox\"><input id=\"item_name_foo\" name=\"item[name][]\" type=\"checkbox\" value=\"foo\" />Foo</label><label class=\"checkbox\"><input id=\"item_name_bar\" name=\"item[name][]\" type=\"checkbox\" value=\"bar\" />Bar</label><span class=\"help-block\">Help me!</span></div></div>"
155
+ end
156
+ end
157
+
116
158
  describe 'collection select' do
117
159
  before(:each) do
118
160
  @result = @builder.collection_select(:name, [["foo", "Foo"]], :first, :last)
@@ -196,19 +238,19 @@ shared_examples 'a bootstrap form' do
196
238
  end
197
239
 
198
240
  it 'adds error message and class' do
199
- @builder.text_field(:name, :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This is an error!</span></div></div>"
241
+ @builder.text_field(:name, :error => 'This is an error!').should == "<div class=\"control-group error\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline error-message\">This is an error!</span></div></div>"
200
242
  end
201
243
 
202
244
  it 'adds error message, class and appended text' do
203
- @builder.text_field(:name, :error => 'This is an error!', :append => 'test').should == "<div class=\"control-group error\"><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\" /><span class=\"add-on\">test</span></div><span class=\"help-inline\">This is an error!</span></div></div>"
245
+ @builder.text_field(:name, :error => 'This is an error!', :append => 'test').should == "<div class=\"control-group error\"><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\" /><span class=\"add-on\">test</span></div><span class=\"help-inline error-message\">This is an error!</span></div></div>"
204
246
  end
205
247
 
206
248
  it 'adds success message and class' do
207
- @builder.text_field(:name, :success => 'This checked out OK').should == "<div class=\"control-group success\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">This checked out OK</span></div></div>"
249
+ @builder.text_field(:name, :success => 'This checked out OK').should == "<div class=\"control-group success\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline success-message\">This checked out OK</span></div></div>"
208
250
  end
209
251
 
210
252
  it 'adds warning message and class' do
211
- @builder.text_field(:name, :warning => 'Take a look at this...').should == "<div class=\"control-group warning\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline\">Take a look at this...</span></div></div>"
253
+ @builder.text_field(:name, :warning => 'Take a look at this...').should == "<div class=\"control-group warning\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /><span class=\"help-inline warning-message\">Take a look at this...</span></div></div>"
212
254
  end
213
255
 
214
256
  it 'prepends passed text' do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
5
- prerelease:
4
+ version: 4.0.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Seth Vargo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-30 00:00:00.000000000 Z
11
+ date: 2013-08-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec-rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: capybara
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,23 +41,20 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rails
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: country_select
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -94,33 +83,29 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: sqlite3
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: fuubar
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - '>='
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - '>='
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description: Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating
@@ -132,6 +117,7 @@ extra_rdoc_files: []
132
117
  files:
133
118
  - .gitignore
134
119
  - .travis.yml
120
+ - CHANGELOG.md
135
121
  - Gemfile
136
122
  - LICENSE
137
123
  - README.md
@@ -200,27 +186,26 @@ files:
200
186
  - spec/support/shared_context.rb
201
187
  homepage: https://github.com/sethvargo/bootstrap_forms
202
188
  licenses: []
189
+ metadata: {}
203
190
  post_install_message:
204
191
  rdoc_options: []
205
192
  require_paths:
206
193
  - lib
207
194
  required_ruby_version: !ruby/object:Gem::Requirement
208
- none: false
209
195
  requirements:
210
- - - ! '>='
196
+ - - '>='
211
197
  - !ruby/object:Gem::Version
212
198
  version: 1.9.1
213
199
  required_rubygems_version: !ruby/object:Gem::Requirement
214
- none: false
215
200
  requirements:
216
- - - ! '>='
201
+ - - '>='
217
202
  - !ruby/object:Gem::Version
218
203
  version: '0'
219
204
  requirements: []
220
205
  rubyforge_project:
221
- rubygems_version: 1.8.23
206
+ rubygems_version: 2.0.3
222
207
  signing_key:
223
- specification_version: 3
208
+ specification_version: 4
224
209
  summary: Bootstrap Forms makes Twitter's Bootstrap on Rails easy!
225
210
  test_files:
226
211
  - spec/dummy/Rakefile