bootstrap_form 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  bootstrap_form
2
2
  ==============
3
3
 
4
- Provides a rails form builder that makes it simple to use Twitter Bootstrap 2.0 forms.
4
+ bootstrap_form is a rails form builder that makes it super easy to create beautiful-looking forms using Twitter Bootstrap 2.0
5
5
 
6
6
 
7
7
  Requirements
@@ -35,8 +35,24 @@ error messages.
35
35
  Usage
36
36
  -----
37
37
 
38
- This is an example of the default form style, which stacks the labels on
39
- top of the inputs and places helper text to the right of the field:
38
+ <%= bootstrap_form_for(@user) do |f| %>
39
+ ...
40
+ <% end %>
41
+
42
+ This plugin provides the following form helpers:
43
+
44
+ * text_field
45
+ * text_area
46
+ * password_field
47
+ * select
48
+ * collection_select
49
+ * file_field
50
+ * date_select
51
+ * check_box
52
+
53
+ These form helpers accept the same options as the Rails form
54
+ helpers with the addition of two options `label` and `help`. Here's an
55
+ example form that also uses the `actions` helper for the submit button:
40
56
 
41
57
  <%= bootstrap_form_for(@user) do |f| %>
42
58
  <%= f.alert_message "Please fix the errors below." %>
@@ -44,6 +60,7 @@ top of the inputs and places helper text to the right of the field:
44
60
  <%= f.text_field :email, autofocus: :true %>
45
61
  <%= f.password_field :password, help: 'Must be at least 6 characters long' %>
46
62
  <%= f.password_field :password_confirmation, label: 'Confirm Password' %>
63
+ <%= f.check_box :terms, label: 'I agree to the Terms of Service' %>
47
64
 
48
65
  <%= f.actions do %>
49
66
  <%= f.primary 'Sign Up' %>
@@ -53,17 +70,23 @@ top of the inputs and places helper text to the right of the field:
53
70
  ![Example Form](https://github.com/potenza/bootstrap_form/raw/master/examples/example_form.png)
54
71
 
55
72
 
73
+ Options
74
+ -------
75
+
56
76
  To use a horizontal-style form with labels to the left of the inputs,
57
77
  add the `.form-horizontal` class:
58
78
 
59
79
  <%= bootstrap_form_for(@user, html: { class: 'form-horizontal' }) do |f| %>
60
80
 
61
-
62
81
  To place helper text underneath the fields, pass the option `help:
63
82
  :block`:
64
83
 
65
84
  <%= bootstrap_form_for(@user, help: block) do |f| %>
66
85
 
86
+ Here's an example of a horizontal-style form with block helpers:
87
+
88
+ ![Example Form](https://github.com/potenza/bootstrap_form/raw/master/examples/example_horizontal_block_form.png)
89
+
67
90
 
68
91
  Validation Errors
69
92
  -----------------
@@ -13,7 +13,7 @@ module BootstrapForm
13
13
  end
14
14
  end
15
15
 
16
- %w{text_field text_area password_field collection_select file_field date_select}.each do |method_name|
16
+ %w{text_field text_area password_field collection_select file_field date_select select}.each do |method_name|
17
17
  define_method(method_name) do |name, *args|
18
18
  options = args.extract_options!.symbolize_keys!
19
19
  content_tag :div, class: "control-group#{(' error' if object.errors[name].any?)}" do
@@ -6,7 +6,7 @@ module BootstrapForm
6
6
  # add .form-vertical class if it's not horizontal
7
7
  options[:html] = {} unless options.has_key?(:html)
8
8
  css = options[:html].fetch(:class, '')
9
- options[:html][:class] = "#{css} form-vertical" unless css.match /horizontal/
9
+ options[:html][:class] = "#{css} form-vertical" unless css.match /form-horizontal/
10
10
 
11
11
  temporarily_disable_field_error_proc do
12
12
  form_for(object, options, &block)
@@ -1,3 +1,3 @@
1
1
  module BootstrapForm
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -45,7 +45,12 @@ class BootstrapFormTest < ActionView::TestCase
45
45
  assert_equal expected, @builder.text_area(:comments)
46
46
  end
47
47
 
48
- test "selects are wrapped correctly" do
48
+ test "selects are wrapped correctly (select)" do
49
+ expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_status\">Status</label><div class=\"controls\"><select id=\"user_status\" name=\"user[status]\"><option value=\"1\">activated</option>\n<option value=\"2\">blocked</option></select></div></div>}
50
+ assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]])
51
+ end
52
+
53
+ test "selects are wrapped correctly (collection_select)" do
49
54
  expected = %{<div class=\"control-group\"><label class=\"control-label\" for=\"user_status\">Status</label><div class=\"controls\"><select id=\"user_status\" name=\"user[status]\"></select></div></div>}
50
55
  assert_equal expected, @builder.collection_select(:status, [], :id, :name)
51
56
  end
@@ -56,8 +61,10 @@ class BootstrapFormTest < ActionView::TestCase
56
61
  end
57
62
 
58
63
  test "date selects are wrapped correctly" do
59
- 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>}
60
- assert_equal expected, @builder.date_select(:misc)
64
+ Timecop.freeze(new_time = Time.local(2012, 2, 3, 12, 0, 0)) do
65
+ 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>}
66
+ assert_equal expected, @builder.date_select(:misc)
67
+ end
61
68
  end
62
69
 
63
70
  test "check_boxes are wrapped correctly" do
data/test/test_helper.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'timecop'
2
+ require 'ruby-debug'
3
+
1
4
  # Configure Rails Environment
2
5
  ENV["RAILS_ENV"] = "test"
3
6
 
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.1.3
4
+ version: 0.2.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: 2012-02-03 00:00:00.000000000 Z
12
+ date: 2012-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70341671302580 !ruby/object:Gem::Requirement
16
+ requirement: &70169508560280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70341671302580
24
+ version_requirements: *70169508560280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70341671302160 !ruby/object:Gem::Requirement
27
+ requirement: &70169508559820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,9 +32,31 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70341671302160
36
- description: Rails 3 form builder that makes it easy to style forms with Twitter Bootstrap
37
- 2.0
35
+ version_requirements: *70169508559820
36
+ - !ruby/object:Gem::Dependency
37
+ name: timecop
38
+ requirement: &70169508559240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.3.5
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70169508559240
47
+ - !ruby/object:Gem::Dependency
48
+ name: ruby-debug19
49
+ requirement: &70169508558780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70169508558780
58
+ description: bootstrap_form is a rails form builder that makes it super easy to create
59
+ beautiful-looking forms using Twitter Bootstrap 2.0
38
60
  email:
39
61
  - potenza@gmail.com
40
62
  executables: []
@@ -112,7 +134,7 @@ rubyforge_project:
112
134
  rubygems_version: 1.8.11
113
135
  signing_key:
114
136
  specification_version: 3
115
- summary: Rails 3 form builder that makes it easy to style forms with Twitter Bootstrap
137
+ summary: Rails form builder that makes it easy to style forms using Twitter Bootstrap
116
138
  2.0
117
139
  test_files:
118
140
  - test/bootstrap_form_test.rb