bootstrap_forms 2.0.5 → 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,13 +2,13 @@ Bootstrap Forms
2
2
  ===============
3
3
  [![Build Status](https://secure.travis-ci.org/sethvargo/bootstrap_forms.png?branch=master)](http://travis-ci.org/sethvargo/bootstrap_forms)
4
4
 
5
- Bootstrap Forms is a nice Rails generator that makes working with [Bootstrap (by Twitter)](http://twitter.github.com/bootstrap) even easier on Rails.
5
+ Bootstrap Forms is a nice Rails generator that makes working with [Bootstrap (by Twitter)](http://twitter.github.com/bootstrap) even easier on Rails.
6
6
 
7
7
  Forms with Bootstrap are crowded with additional layout markup. While it's necessary, you shouldn't have to type it every time you create a form! That's why I created Bootstrap Forms.
8
8
 
9
9
  Bootstrap 2.0 Compliant!
10
10
  ------------------------
11
- A super special thanks to [vincenzor](https://github.com/vincenzor) for updating `bootstrap_forms` to comply with the new methods and features in Twitter Bootstrap 2.0.
11
+ A super special thanks to [vincenzor](https://github.com/vincenzor) for updating `bootstrap_forms` to comply with the new methods and features in Twitter Bootstrap 2.0.
12
12
 
13
13
  To get these new features, ensure you are using `bootstrap_forms ~> 2.0.0`.
14
14
 
@@ -105,7 +105,7 @@ Bootstrap Forms also adds a default actions panel when you call `f.submit`:
105
105
  ```haml
106
106
  = f.submit
107
107
  ```
108
-
108
+
109
109
  generates:
110
110
 
111
111
  ```html
@@ -134,42 +134,54 @@ You can add as many options to any form helper tag. If they are interpreted by B
134
134
  <tr>
135
135
  <th>help_inline</th>
136
136
  <td>Add inline help text</td>
137
- <td>= f.text_field :name, :help_inline => 'help me!'</td>
137
+ <td><tt>= f.text_field :name, :help_inline => 'help me!'</td></td>
138
138
  </tr>
139
139
  <tr>
140
140
  <th>help_block</th>
141
141
  <td>Add block help text (below)</td>
142
- <td>= f.text_field :name, :help_block => 'help me!'</td>
142
+ <td><tt>= f.text_field :name, :help_block => 'help me!'</td></td>
143
143
  </tr>
144
144
  <tr>
145
145
  <th>error</th>
146
146
  <td>Styles the field as error (red)</td>
147
- <td>= f.text_field :name, :error => 'This is an error!'</td>
147
+ <td><tt>= f.text_field :name, :error => 'This is an error!'</td></td>
148
148
  </tr>
149
149
  <tr>
150
150
  <th>success</th>
151
151
  <td>Styles the field as success (green)</td>
152
- <td>= f.text_field :name, :success => 'This checked out OK'</td>
152
+ <td><tt>= f.text_field :name, :success => 'This checked out OK'</td></td>
153
153
  </tr>
154
154
  <tr>
155
155
  <th>warning</th>
156
156
  <td>Styles the field as warning (yellow)</td>
157
- <td>= f.text_field :name, :warning => 'Take a look at this...'</td>
157
+ <td><tt>= f.text_field :name, :warning => 'Take a look at this...'</td></td>
158
158
  </tr>
159
159
  <tr>
160
160
  <th>prepend</th>
161
161
  <td>Adds special text to the front of the input</td>
162
- <td>= f.text_field :name, :prepend => '@'</td>
162
+ <td><tt>= f.text_field :name, :prepend => '@'</td></td>
163
163
  </tr>
164
164
  <tr>
165
165
  <th>append</th>
166
166
  <td>Adds special text at the end of the input</td>
167
- <td>= f.text_field :name, :append => '@'</td>
167
+ <td><tt>= f.text_field :name, :append => '@'</td></td>
168
+ </tr>
169
+ <tr>
170
+ <th>append_button</th>
171
+ <td>
172
+ Adds the given button to the end of the input. The value is a hash.<br/>
173
+ :label is the button label<br/>
174
+ :icon adds an icon before the label<br/>
175
+ :class has a default value of 'btn'<br/>
176
+ :type has a default value of 'button'<br/>
177
+ Any other entries are passed directly to Rails's tag helper.
178
+ </td>
179
+ <td><tt>= f.text_field :name, :append_button => { :label => 'Button label', :icon => 'icon-plus', :type => 'button' }</td></td>
168
180
  </tr>
169
181
  <tr>
170
182
  <th>label</th>
171
183
  <td>Customize the field's label. Pass false to have no label.</td>
172
- <td>= f.text_field :name, :label => 'Other name'</td>
184
+ <td><tt>= f.text_field :name, :label => 'Other name'</td></td>
173
185
  </tr>
174
186
  </table>
175
187
 
@@ -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.5'
6
+ s.version = '2.0.6'
7
7
  s.author = 'Seth Vargo'
8
8
  s.email = 'sethvargo@gmail.com'
9
9
  s.homepage = 'https://github.com/sethvargo/bootstrap_forms'
@@ -35,10 +35,10 @@ module BootstrapForms
35
35
 
36
36
  def input_div(&block)
37
37
  content_tag(:div, :class => 'controls') do
38
- if @field_options[:append] || @field_options[:prepend]
38
+ if @field_options[:append] || @field_options[:prepend] || @field_options[:append_button]
39
39
  klass = []
40
40
  klass << 'input-prepend' if @field_options[:prepend]
41
- klass << 'input-append' if @field_options[:append]
41
+ klass << 'input-append' if @field_options[:append] || @field_options[:append_button]
42
42
  content_tag(:div, :class => klass, &block)
43
43
  else
44
44
  yield if block_given?
@@ -65,30 +65,49 @@ module BootstrapForms
65
65
  {}
66
66
  end
67
67
 
68
- %w(help_inline error success warning help_block append prepend).each do |method_name|
68
+ %w(help_inline error success warning help_block append append_button prepend).each do |method_name|
69
69
  define_method(method_name) do |*args|
70
70
  return '' unless value = @field_options[method_name.to_sym]
71
+
72
+ escape = true
73
+ tag_options = {}
71
74
  case method_name
72
75
  when 'help_block'
73
76
  element = :p
74
- klass = 'help-block'
77
+ tag_options[:class] = 'help-block'
75
78
  when 'append', 'prepend'
76
79
  element = :span
77
- klass = 'add-on'
80
+ tag_options[:class] = 'add-on'
81
+ when 'append_button'
82
+ element = :button
83
+ button_options = value
84
+ value = ''
85
+
86
+ if button_options.has_key? :icon
87
+ value << content_tag(:i, '', { :class => button_options.delete(:icon) })
88
+ value << ' '
89
+ escape = false
90
+ end
91
+
92
+ value << button_options.delete(:label)
93
+
94
+ tag_options[:type] = 'button'
95
+ tag_options[:class] = 'btn'
96
+ tag_options.merge! button_options
78
97
  else
79
98
  element = :span
80
- klass = 'help-inline'
99
+ tag_options[:class] = 'help-inline'
81
100
  end
82
- content_tag(element, value, :class => klass)
101
+ content_tag(element, value, tag_options, escape)
83
102
  end
84
103
  end
85
104
 
86
105
  def extras(&block)
87
- [prepend, (yield if block_given?), append, help_inline, error, success, warning, help_block].join('').html_safe
106
+ [prepend, (yield if block_given?), append, append_button, help_inline, error, success, warning, help_block].join('').html_safe
88
107
  end
89
108
 
90
109
  def objectify_options(options)
91
- super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append)
110
+ super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append, :append_button)
92
111
  end
93
112
  end
94
113
  end
@@ -142,6 +142,22 @@ 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
+
146
+ it 'appends button with default values' do
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
+ end
149
+
150
+ it 'appends button and overrides class and type' do
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
+ end
153
+
154
+ it 'appends button with custom attributes' do
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
+ end
157
+
158
+ it 'appends button with an icon' do
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
+ end
145
161
  end
146
162
 
147
163
  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.5
4
+ version: 2.0.6
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-15 00:00:00.000000000 Z
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
@@ -195,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
195
  version: '0'
196
196
  segments:
197
197
  - 0
198
- hash: -4298855100164431662
198
+ hash: 2313446882174708142
199
199
  required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  none: false
201
201
  requirements:
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  version: '0'
205
205
  segments:
206
206
  - 0
207
- hash: -4298855100164431662
207
+ hash: 2313446882174708142
208
208
  requirements: []
209
209
  rubyforge_project:
210
210
  rubygems_version: 1.8.24