bootstrap_form 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/potenza/bootstrap_form.png)](https://travis-ci.org/potenza/bootstrap_form)
2
+
1
3
  # BootstrapForm
2
4
 
3
5
  **BootstrapForm** is a form builder that makes it super easy to
@@ -112,7 +114,7 @@ that the entire control group will display an error if an associated
112
114
  validations fails:
113
115
 
114
116
  ```erb
115
- <%= f.control_group :skill_level, label: { text: 'Skill' } do %>
117
+ <%= f.control_group :skill_level, label: { text: 'Skill' }, help: 'This is optional' do %>
116
118
  <%= f.radio_button :skill_level, 0, label: 'Novice', checked: true %>
117
119
  <%= f.radio_button :skill_level, 1, label: 'Intermediate' %>
118
120
  <%= f.radio_button :skill_level, 2, label: 'Advanced' %>
@@ -175,19 +177,18 @@ You can prepend an input file with the `prepend` option:
175
177
  <%= f.text_field :twitter_username, prepend: '@' %>
176
178
  ```
177
179
 
178
- ### Submit buttons
180
+ ### Appending inputs
179
181
 
180
- This gem provides a few different options for submit buttons.
181
-
182
- You can use the `actions` helper, which wraps your submit button in a
183
- `.form-actions` class.
182
+ You can append an input file with the `append` option:
184
183
 
185
184
  ```erb
186
- <%= f.actions do %>
187
- <%= f.primary 'Create My Account' %>
188
- <% end %>
185
+ <%= f.text_field :amount, append: '.00' %>
189
186
  ```
190
187
 
188
+ ### Submit buttons
189
+
190
+ This gem provides a few different options for submit buttons.
191
+
191
192
  Here's a simple `primary` button (this applies the `.btn` and `.btn-primary` classes):
192
193
 
193
194
  ```erb
@@ -200,6 +201,15 @@ Here's a `secondary` submit button (applies just the `.btn` class):
200
201
  <%= f.secondary "Create My Account" %>
201
202
  ```
202
203
 
204
+ You can use the `actions` helper, which wraps your submit button in a
205
+ `.form-actions` class.
206
+
207
+ ```erb
208
+ <%= f.actions do %>
209
+ <%= f.primary 'Create My Account' %>
210
+ <% end %>
211
+ ```
212
+
203
213
  And if you don't want to use the `actions` helper, here's how you might
204
214
  style a `primary` button with horizontal-style forms:
205
215
 
@@ -213,9 +223,9 @@ style a `primary` button with horizontal-style forms:
213
223
 
214
224
  ### Custom Control Groups
215
225
 
216
- Sometimes you need to wrap a custom control in Bootstrap-style markup.
217
- This is mostly needed when using horizontal-style forms. You can use the
218
- `control_group` helper to do this:
226
+ Sometimes you need to wrap an element in Bootstrap-style markup.
227
+ This is mostly needed to align submit buttons when using horizontal-style
228
+ forms (also shown above):
219
229
 
220
230
  ```erb
221
231
  <%= bootstrap_form_for(@user, html: { class: 'form-horizontal' }) do |f| %>
@@ -248,6 +258,10 @@ classes, you can use the `alert_message` helper:
248
258
  <%= f.alert_message "Please fix the errors below." %>
249
259
  ```
250
260
 
251
- ## Credits
261
+ ## Contributors
262
+
263
+ https://github.com/potenza/bootstrap_form/graphs/contributors
264
+
265
+ ## License
252
266
 
253
- bootstrap_form is Copyright (c) 2013 Stephen Potenza (https://github.com/potenza) and is distributed under the MIT license.
267
+ MIT License. Copyright 2012-2013 Stephen Potenza (https://github.com/potenza)
@@ -19,12 +19,13 @@ module BootstrapForm
19
19
  define_method(method_name) do |name, *args|
20
20
  options = args.extract_options!.symbolize_keys!
21
21
 
22
- control_group(name, label: { text: options[:label] }) do
23
- help = object.errors[name].any? ? object.errors[name].join(', ') : options[:help]
24
- help = content_tag(@help_tag, class: @help_css) { help } if help
22
+ label = options.delete(:label)
23
+ help = options.delete(:help)
25
24
 
26
- args << options.except(:label, :help, :prepend)
27
- element = super(name, *args) + help
25
+ control_group(name, label: { text: label }, help: help) do
26
+
27
+ args << options.except(:prepend, :append)
28
+ element = super(name, *args)
28
29
 
29
30
  if prepend = options.delete(:prepend)
30
31
  element = content_tag(:div, class: 'input-prepend') do
@@ -32,6 +33,12 @@ module BootstrapForm
32
33
  end
33
34
  end
34
35
 
36
+ if append = options.delete(:append)
37
+ element = content_tag(:div, class: 'input-append') do
38
+ element + content_tag(:span, append, class: 'add-on')
39
+ end
40
+ end
41
+
35
42
  element
36
43
  end
37
44
  end
@@ -60,21 +67,31 @@ module BootstrapForm
60
67
  end
61
68
 
62
69
  def control_group(name = nil, options = {}, &block)
70
+ has_name = !(name.nil? || object.errors[name].empty?)
71
+
63
72
  options[:class] ||= 'control-group'
64
- options[:class] << ' error' if name && object.errors[name].any?
73
+ options[:class] << ' error' if has_name
74
+
75
+ label = options.delete(:label)
76
+ _help = options.delete(:help)
65
77
 
66
- content_tag(:div, options.except(:label)) do
78
+ content_tag(:div, options) do
67
79
  html = ''
68
80
 
69
- if attrs = options.delete(:label)
70
- attrs[:class] ||= 'control-label'
71
- attrs[:for] ||= '' if name.nil?
81
+ if label
82
+ label[:class] ||= 'control-label'
83
+ label[:for] ||= '' if name.nil?
72
84
 
73
- html << label(name, attrs[:text], attrs.except(:text))
85
+ html << label(name, label[:text], label.except(:text))
74
86
  end
75
87
 
76
88
  html << content_tag(:div, class: 'controls') do
77
- block.call.html_safe
89
+ controls = block.call
90
+
91
+ help = has_name ? object.errors[name].join(', ') : _help
92
+ controls << content_tag(@help_tag, help, class: @help_css) if help
93
+
94
+ controls.html_safe
78
95
  end
79
96
 
80
97
  html.html_safe
@@ -1,3 +1,3 @@
1
1
  module BootstrapForm
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -84,22 +84,22 @@ class BootstrapFormTest < ActionView::TestCase
84
84
  end
85
85
 
86
86
  test "date selects are wrapped correctly" do
87
- Timecop.freeze(Time.local(2012, 2, 3, 12, 0, 0)) do
87
+ Timecop.freeze(Time.utc(2012, 2, 3)) do
88
88
  expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><select id=\"user_misc_1i\" name=\"user[misc(1i)]\">\n<option value=\"2007\">2007</option>\n<option value=\"2008\">2008</option>\n<option value=\"2009\">2009</option>\n<option value=\"2010\">2010</option>\n<option value=\"2011\">2011</option>\n<option selected=\"selected\" value=\"2012\">2012</option>\n<option value=\"2013\">2013</option>\n<option value=\"2014\">2014</option>\n<option value=\"2015\">2015</option>\n<option value=\"2016\">2016</option>\n<option value=\"2017\">2017</option>\n</select>\n<select id=\"user_misc_2i\" name=\"user[misc(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"user_misc_3i\" name=\"user[misc(3i)]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n</div></div>}
89
89
  assert_equal expected, @builder.date_select(:misc)
90
90
  end
91
91
  end
92
92
 
93
93
  test "time selects are wrapped correctly" do
94
- Timecop.freeze(Time.local(2012, 2, 3, 12, 0, 0)) do
95
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc_1i\" name=\"user[misc(1i)]\" type=\"hidden\" value=\"2012\" />\n<input id=\"user_misc_2i\" name=\"user[misc(2i)]\" type=\"hidden\" value=\"2\" />\n<input id=\"user_misc_3i\" name=\"user[misc(3i)]\" type=\"hidden\" value=\"3\" />\n<select id=\"user_misc_4i\" name=\"user[misc(4i)]\">\n<option value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option selected=\"selected\" value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n</select>\n : <select id=\"user_misc_5i\" name=\"user[misc(5i)]\">\n<option selected=\"selected\" value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n<option value=\"32\">32</option>\n<option value=\"33\">33</option>\n<option value=\"34\">34</option>\n<option value=\"35\">35</option>\n<option value=\"36\">36</option>\n<option value=\"37\">37</option>\n<option value=\"38\">38</option>\n<option value=\"39\">39</option>\n<option value=\"40\">40</option>\n<option value=\"41\">41</option>\n<option value=\"42\">42</option>\n<option value=\"43\">43</option>\n<option value=\"44\">44</option>\n<option value=\"45\">45</option>\n<option value=\"46\">46</option>\n<option value=\"47\">47</option>\n<option value=\"48\">48</option>\n<option value=\"49\">49</option>\n<option value=\"50\">50</option>\n<option value=\"51\">51</option>\n<option value=\"52\">52</option>\n<option value=\"53\">53</option>\n<option value=\"54\">54</option>\n<option value=\"55\">55</option>\n<option value=\"56\">56</option>\n<option value=\"57\">57</option>\n<option value=\"58\">58</option>\n<option value=\"59\">59</option>\n</select>\n</div></div>}
94
+ Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
95
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><input id=\"user_misc_1i\" name=\"user[misc(1i)]\" type=\"hidden\" value=\"2012\" />\n<input id=\"user_misc_2i\" name=\"user[misc(2i)]\" type=\"hidden\" value=\"2\" />\n<input id=\"user_misc_3i\" name=\"user[misc(3i)]\" type=\"hidden\" value=\"3\" />\n<select id=\"user_misc_4i\" name=\"user[misc(4i)]\">\n<option value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option selected=\"selected\" value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n</select>\n : <select id=\"user_misc_5i\" name=\"user[misc(5i)]\">\n<option selected=\"selected\" value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n<option value=\"32\">32</option>\n<option value=\"33\">33</option>\n<option value=\"34\">34</option>\n<option value=\"35\">35</option>\n<option value=\"36\">36</option>\n<option value=\"37\">37</option>\n<option value=\"38\">38</option>\n<option value=\"39\">39</option>\n<option value=\"40\">40</option>\n<option value=\"41\">41</option>\n<option value=\"42\">42</option>\n<option value=\"43\">43</option>\n<option value=\"44\">44</option>\n<option value=\"45\">45</option>\n<option value=\"46\">46</option>\n<option value=\"47\">47</option>\n<option value=\"48\">48</option>\n<option value=\"49\">49</option>\n<option value=\"50\">50</option>\n<option value=\"51\">51</option>\n<option value=\"52\">52</option>\n<option value=\"53\">53</option>\n<option value=\"54\">54</option>\n<option value=\"55\">55</option>\n<option value=\"56\">56</option>\n<option value=\"57\">57</option>\n<option value=\"58\">58</option>\n<option value=\"59\">59</option>\n</select>\n</div></div>}
96
96
  assert_equal expected, @builder.time_select(:misc)
97
97
  end
98
98
  end
99
99
 
100
100
  test "datetime selects are wrapped correctly" do
101
- Timecop.freeze(Time.local(2012, 2, 3, 12, 0, 0)) do
102
- expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><select id=\"user_misc_1i\" name=\"user[misc(1i)]\">\n<option value=\"2007\">2007</option>\n<option value=\"2008\">2008</option>\n<option value=\"2009\">2009</option>\n<option value=\"2010\">2010</option>\n<option value=\"2011\">2011</option>\n<option selected=\"selected\" value=\"2012\">2012</option>\n<option value=\"2013\">2013</option>\n<option value=\"2014\">2014</option>\n<option value=\"2015\">2015</option>\n<option value=\"2016\">2016</option>\n<option value=\"2017\">2017</option>\n</select>\n<select id=\"user_misc_2i\" name=\"user[misc(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"user_misc_3i\" name=\"user[misc(3i)]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n &mdash; <select id=\"user_misc_4i\" name=\"user[misc(4i)]\">\n<option value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option selected=\"selected\" value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n</select>\n : <select id=\"user_misc_5i\" name=\"user[misc(5i)]\">\n<option selected=\"selected\" value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n<option value=\"32\">32</option>\n<option value=\"33\">33</option>\n<option value=\"34\">34</option>\n<option value=\"35\">35</option>\n<option value=\"36\">36</option>\n<option value=\"37\">37</option>\n<option value=\"38\">38</option>\n<option value=\"39\">39</option>\n<option value=\"40\">40</option>\n<option value=\"41\">41</option>\n<option value=\"42\">42</option>\n<option value=\"43\">43</option>\n<option value=\"44\">44</option>\n<option value=\"45\">45</option>\n<option value=\"46\">46</option>\n<option value=\"47\">47</option>\n<option value=\"48\">48</option>\n<option value=\"49\">49</option>\n<option value=\"50\">50</option>\n<option value=\"51\">51</option>\n<option value=\"52\">52</option>\n<option value=\"53\">53</option>\n<option value=\"54\">54</option>\n<option value=\"55\">55</option>\n<option value=\"56\">56</option>\n<option value=\"57\">57</option>\n<option value=\"58\">58</option>\n<option value=\"59\">59</option>\n</select>\n</div></div>}
101
+ Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do
102
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_misc\">Misc</label><div class=\"controls\"><select id=\"user_misc_1i\" name=\"user[misc(1i)]\">\n<option value=\"2007\">2007</option>\n<option value=\"2008\">2008</option>\n<option value=\"2009\">2009</option>\n<option value=\"2010\">2010</option>\n<option value=\"2011\">2011</option>\n<option selected=\"selected\" value=\"2012\">2012</option>\n<option value=\"2013\">2013</option>\n<option value=\"2014\">2014</option>\n<option value=\"2015\">2015</option>\n<option value=\"2016\">2016</option>\n<option value=\"2017\">2017</option>\n</select>\n<select id=\"user_misc_2i\" name=\"user[misc(2i)]\">\n<option value=\"1\">January</option>\n<option selected=\"selected\" value=\"2\">February</option>\n<option value=\"3\">March</option>\n<option value=\"4\">April</option>\n<option value=\"5\">May</option>\n<option value=\"6\">June</option>\n<option value=\"7\">July</option>\n<option value=\"8\">August</option>\n<option value=\"9\">September</option>\n<option value=\"10\">October</option>\n<option value=\"11\">November</option>\n<option value=\"12\">December</option>\n</select>\n<select id=\"user_misc_3i\" name=\"user[misc(3i)]\">\n<option value=\"1\">1</option>\n<option value=\"2\">2</option>\n<option selected=\"selected\" value=\"3\">3</option>\n<option value=\"4\">4</option>\n<option value=\"5\">5</option>\n<option value=\"6\">6</option>\n<option value=\"7\">7</option>\n<option value=\"8\">8</option>\n<option value=\"9\">9</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n</select>\n &mdash; <select id=\"user_misc_4i\" name=\"user[misc(4i)]\">\n<option value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option selected=\"selected\" value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n</select>\n : <select id=\"user_misc_5i\" name=\"user[misc(5i)]\">\n<option selected=\"selected\" value=\"00\">00</option>\n<option value=\"01\">01</option>\n<option value=\"02\">02</option>\n<option value=\"03\">03</option>\n<option value=\"04\">04</option>\n<option value=\"05\">05</option>\n<option value=\"06\">06</option>\n<option value=\"07\">07</option>\n<option value=\"08\">08</option>\n<option value=\"09\">09</option>\n<option value=\"10\">10</option>\n<option value=\"11\">11</option>\n<option value=\"12\">12</option>\n<option value=\"13\">13</option>\n<option value=\"14\">14</option>\n<option value=\"15\">15</option>\n<option value=\"16\">16</option>\n<option value=\"17\">17</option>\n<option value=\"18\">18</option>\n<option value=\"19\">19</option>\n<option value=\"20\">20</option>\n<option value=\"21\">21</option>\n<option value=\"22\">22</option>\n<option value=\"23\">23</option>\n<option value=\"24\">24</option>\n<option value=\"25\">25</option>\n<option value=\"26\">26</option>\n<option value=\"27\">27</option>\n<option value=\"28\">28</option>\n<option value=\"29\">29</option>\n<option value=\"30\">30</option>\n<option value=\"31\">31</option>\n<option value=\"32\">32</option>\n<option value=\"33\">33</option>\n<option value=\"34\">34</option>\n<option value=\"35\">35</option>\n<option value=\"36\">36</option>\n<option value=\"37\">37</option>\n<option value=\"38\">38</option>\n<option value=\"39\">39</option>\n<option value=\"40\">40</option>\n<option value=\"41\">41</option>\n<option value=\"42\">42</option>\n<option value=\"43\">43</option>\n<option value=\"44\">44</option>\n<option value=\"45\">45</option>\n<option value=\"46\">46</option>\n<option value=\"47\">47</option>\n<option value=\"48\">48</option>\n<option value=\"49\">49</option>\n<option value=\"50\">50</option>\n<option value=\"51\">51</option>\n<option value=\"52\">52</option>\n<option value=\"53\">53</option>\n<option value=\"54\">54</option>\n<option value=\"55\">55</option>\n<option value=\"56\">56</option>\n<option value=\"57\">57</option>\n<option value=\"58\">58</option>\n<option value=\"59\">59</option>\n</select>\n</div></div>}
103
103
  assert_equal expected, @builder.datetime_select(:misc)
104
104
  end
105
105
  end
@@ -134,6 +134,11 @@ class BootstrapFormTest < ActionView::TestCase
134
134
  assert_equal expected, @builder.text_field(:email, prepend: 'Gmail')
135
135
  end
136
136
 
137
+ test "adding append text" do
138
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><div class=\"input-append\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /><span class="add-on">Gmail</span></div></div></div>}
139
+ assert_equal expected, @builder.text_field(:email, append: 'Gmail')
140
+ end
141
+
137
142
  test "passing :help to a field displays it inline" do
138
143
  expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_email\">Email</label><div class=\"controls\"><input id=\"user_email\" name=\"user[email]\" size=\"30\" type=\"text\" value=\"steve@example.com\" /><span class=\"help-inline\">This is required</span></div></div>}
139
144
  assert_equal expected, @builder.text_field(:email, help: 'This is required')
@@ -198,7 +203,16 @@ class BootstrapFormTest < ActionView::TestCase
198
203
  assert_equal expected, output
199
204
  end
200
205
 
201
- test 'control_group renders the "error" class corrrectly when object is invalid' do
206
+ test 'control_group renders the :help corrrectly' do
207
+ output = @builder.control_group nil, help: 'Foobar' do
208
+ '<span>custom control here</span>'
209
+ end
210
+
211
+ expected = %{<div class="control-group"><div class="controls"><span>custom control here</span><span class="help-inline">Foobar</span></div></div>}
212
+ assert_equal expected, output
213
+ end
214
+
215
+ test 'control_group renders the "error" class and message corrrectly when object is invalid' do
202
216
  @user.email = nil
203
217
  @user.valid?
204
218
 
@@ -206,7 +220,7 @@ class BootstrapFormTest < ActionView::TestCase
206
220
  '<span>custom control here</span>'
207
221
  end
208
222
 
209
- expected = %{<div class="control-group error"><div class="controls"><span>custom control here</span></div></div>}
223
+ expected = %{<div class="control-group error"><div class="controls"><span>custom control here</span><span class="help-inline">can't be blank, is too short (minimum is 5 characters)</span></div></div>}
210
224
  assert_equal expected, output
211
225
  end
212
226
 
@@ -228,6 +242,16 @@ class BootstrapFormTest < ActionView::TestCase
228
242
  assert_equal expected, @builder.primary('Submit', disable_with: 'Saving...')
229
243
  end
230
244
 
245
+ test "secondary button contains the correct classes" do
246
+ expected = %{<input class=\"btn\" name=\"commit\" type=\"submit\" value=\"Submit\" />}
247
+ assert_equal expected, @builder.secondary('Submit')
248
+ end
249
+
250
+ test "secondary button with a disabled state" do
251
+ expected = %{<input class=\"btn\" data-disable-with="Saving..." name=\"commit\" type=\"submit\" value=\"Submit\" />}
252
+ assert_equal expected, @builder.secondary('Submit', disable_with: 'Saving...')
253
+ end
254
+
231
255
  test "passing :help :block to the form builder" do
232
256
  output = bootstrap_form_for(@user, help: :block) do |f|
233
257
  f.text_field(:email, help: 'This is required')
Binary file
@@ -1,30 +1,32 @@
1
1
   (0.1ms) select sqlite_version(*)
2
2
   (2.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
3
-  (0.1ms) PRAGMA index_list("schema_migrations")
4
-  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
5
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
3
+  (0.0ms) PRAGMA index_list("schema_migrations")
4
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
5
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
6
6
  Migrating to CreateUsers (20120106063521)
7
7
   (0.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "password" varchar(255), "comments" text, "status" varchar(255), "misc" varchar(255), "created_at" datetime, "updated_at" datetime)
8
8
   (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120106063521')
9
-  (0.3ms) select sqlite_version(*)
9
+  (0.2ms) select sqlite_version(*)
10
10
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
11
11
   (0.0ms) PRAGMA index_list("users")
12
-  (0.1ms) select sqlite_version(*)
13
-  (2.8ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
14
-  (0.4ms) PRAGMA index_list("schema_migrations")
15
-  (1.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
12
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
13
+ Migrating to CreateUsers (20120106063521)
14
+  (0.1ms) select sqlite_version(*)
16
15
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
16
+  (0.0ms) PRAGMA index_list("users")
17
+  (0.1ms) select sqlite_version(*)
18
+  (2.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
19
+  (0.0ms) PRAGMA index_list("schema_migrations")
20
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
21
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
17
22
  Migrating to CreateUsers (20120106063521)
18
23
   (0.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "password" varchar(255), "comments" text, "status" varchar(255), "misc" varchar(255), "created_at" datetime, "updated_at" datetime)
19
24
   (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120106063521')
20
25
   (0.2ms) select sqlite_version(*)
21
26
   (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
22
27
   (0.0ms) PRAGMA index_list("users")
23
-  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
28
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
29
+ Migrating to CreateUsers (20120106063521)
24
30
   (0.2ms) select sqlite_version(*)
25
-  (0.9ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "password" varchar(255), "comments" text, "status" varchar(255), "misc" varchar(255), "created_at" datetime, "updated_at" datetime) 
26
-  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
27
-  (0.0ms) PRAGMA index_list("schema_migrations")
28
-  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
29
-  (0.1ms) SELECT version FROM "schema_migrations"
30
-  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20120106063521')
31
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
32
+  (0.0ms) PRAGMA index_list("users")
@@ -0,0 +1,11 @@
1
+  (0.0ms) select sqlite_version(*)
2
+  (2.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
3
+  (0.0ms) PRAGMA index_list("schema_migrations")
4
+  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
5
+  (0.7ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
6
+ Migrating to CreateUsers (20120106063521)
7
+  (0.3ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255), "password" varchar(255), "comments" text, "status" varchar(255), "misc" varchar(255), "created_at" datetime, "updated_at" datetime)
8
+  (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES ('20120106063521')
9
+  (0.2ms) select sqlite_version(*)
10
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" 
11
+  (0.0ms) PRAGMA index_list("users")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
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: 2013-01-16 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails