bootstrap_forms 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,5 +1,7 @@
1
1
  Bootstrap Forms
2
2
  ===============
3
+ [![Build Status](https://secure.travis-ci.org/sethvargo/bootstrap_forms.png?branch=master)](http://travis-ci.org/sethvargo/bootstrap_forms)
4
+
3
5
  Bootstrap Forms is a nice Rails generator that makes working with [Bootstrap (by Twitter)](http://twitter.github.com/bootstrap) even easier on Rails.
4
6
 
5
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,7 +10,7 @@ Bootstrap 2.0 Compliant!
8
10
  ------------------------
9
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.
10
12
 
11
- To get these new features, ensure you are using `bootstrap_forms ~> 1.0.0`.
13
+ To get these new features, ensure you are using `bootstrap_forms ~> 2.0.0`.
12
14
 
13
15
  Note/Caution/Warning
14
16
  --------------------
@@ -186,8 +188,9 @@ Contributing
186
188
  ------------
187
189
  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:
188
190
 
189
- - Squash into a single commit (unless it makes sense to have multiple commits)
190
- - Document your changes
191
+ - **Squash** into a single commit (unless it makes sense to have multiple commits)
192
+ - **Test/Spec** the changes
193
+ - **Document** your changes
191
194
 
192
195
  License
193
196
  -------
@@ -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.0"
6
+ s.version = "2.0.1"
7
7
  s.author = "Seth Vargo"
8
8
  s.email = "sethvargo@gmail.com"
9
9
  s.homepage = "https://github.com/sethvargo/bootstrap_forms"
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
16
  s.require_paths = ["lib"]
17
-
17
+
18
18
  s.add_development_dependency "rspec-rails", "~> 2.9.0"
19
19
  s.add_development_dependency "capybara", "~> 1.1.0"
20
20
  s.add_development_dependency "rake"
@@ -0,0 +1,6 @@
1
+ it:
2
+ bootstrap_forms:
3
+ errors:
4
+ header: "Alcuni errori hanno impedito il salvataggio di %{model}:"
5
+ buttons:
6
+ cancel: 'Cancella'
@@ -1,7 +1,7 @@
1
1
  module BootstrapForms
2
2
  class FormBuilder < ::ActionView::Helpers::FormBuilder
3
3
  include BootstrapForms::Helpers::Wrappers
4
-
4
+
5
5
  delegate :content_tag, :hidden_field_tag, :check_box_tag, :radio_button_tag, :button_tag, :link_to, :to => :@template
6
6
 
7
7
  def error_messages
@@ -40,8 +40,12 @@ module BootstrapForms
40
40
 
41
41
  control_group_div do
42
42
  input_div do
43
- label(@name, :class => [ 'checkbox', required_class ].compact.join(' ')) do
44
- extras { super(name, *(@args << @field_options)) + (@field_options[:label].blank? ? human_attribute_name : @field_options[:label])}
43
+ if @field_options[:label] == false || @field_options[:label] == ''
44
+ extras { super(name, *(@args << @field_options)) }
45
+ else
46
+ label(@name, :class => [ 'checkbox', required_class ].compact.join(' ')) do
47
+ extras { super(name, *(@args << @field_options)) + (@field_options[:label].blank? ? human_attribute_name : @field_options[:label])}
48
+ end
45
49
  end
46
50
  end
47
51
  end
@@ -54,8 +58,12 @@ module BootstrapForms
54
58
  control_group_div do
55
59
  label_field + input_div do
56
60
  values.map do |text, value|
57
- label("#{@name}_#{value}", :class => [ 'radio', required_class ].compact.join(' ')) do
61
+ if @field_options[:label] == '' || @field_options[:label] == false
58
62
  extras { radio_button(name, value, @options) + text }
63
+ else
64
+ label("#{@name}_#{value}", :class => [ 'radio', required_class ].compact.join(' ')) do
65
+ extras { radio_button(name, value, @options) + text }
66
+ end
59
67
  end
60
68
  end.join.html_safe
61
69
  end
@@ -4,7 +4,7 @@ module BootstrapForms
4
4
  private
5
5
  def control_group_div(&block)
6
6
  field_errors = error_string
7
- if @field_options[:error]
7
+ if @field_options[:error]
8
8
  (@field_options[:error] << ", " << field_errors) if field_errors
9
9
  else
10
10
  @field_options[:error] = field_errors
@@ -37,8 +37,9 @@ module BootstrapForms
37
37
  def input_div(&block)
38
38
  content_tag(:div, :class => 'controls') do
39
39
  if @field_options[:append] || @field_options[:prepend]
40
- klass = 'input-prepend' if @field_options[:prepend]
41
- klass = 'input-append' if @field_options[:append]
40
+ klass = []
41
+ klass << 'input-prepend' if @field_options[:prepend]
42
+ klass << 'input-append' if @field_options[:append]
42
43
  content_tag(:div, :class => klass, &block)
43
44
  else
44
45
  yield if block_given?
@@ -47,10 +48,14 @@ module BootstrapForms
47
48
  end
48
49
 
49
50
  def label_field(&block)
50
- if respond_to?(:object)
51
- label(@name, block_given? ? block : @field_options[:label], :class => ['control-label', required_class].compact.join(' '))
51
+ if @field_options[:label] == '' || @field_options[:label] == false
52
+ return ''.html_safe
52
53
  else
53
- label_tag(@name, block_given? ? block : @field_options[:label], :class => ['control-label', required_class].compact.join(' '))
54
+ if respond_to?(:object)
55
+ label(@name, block_given? ? block : @field_options[:label], :class => ['control-label', required_class].compact.join(' '))
56
+ else
57
+ label_tag(@name, block_given? ? block : @field_options[:label], :class => ['control-label', required_class].compact.join(' '))
58
+ end
54
59
  end
55
60
  end
56
61
 
@@ -89,4 +94,4 @@ module BootstrapForms
89
94
  end
90
95
  end
91
96
  end
92
- end
97
+ end
@@ -8,51 +8,51 @@ describe "BootstrapForms::FormBuilder" do
8
8
  @template.output_buffer = ""
9
9
  @builder = BootstrapForms::FormBuilder.new(:item, @project, @template, {}, proc {})
10
10
  end
11
-
11
+
12
12
  describe "with no options" do
13
13
  describe "error_messages" do
14
14
  it "returns empty string without errors" do
15
15
  @builder.error_messages.should == ""
16
16
  end
17
-
17
+
18
18
  context "with errors" do
19
19
  before(:each) do
20
20
  @project.errors.add("name")
21
21
  @result = @builder.error_messages
22
22
  end
23
-
23
+
24
24
  it "is wrapped in error div" do
25
25
  @result.should match /^<div class="alert alert-block alert-error validation-errors">.*<\/div>$/
26
26
  end
27
-
27
+
28
28
  it "has a list with errors" do
29
29
  @result.should match /<ul><li>Name is invalid<\/li><\/ul>/
30
30
  end
31
-
31
+
32
32
  it "has error title" do
33
- @result.should match /<h4 class="alert-heading">#{I18n.t('bootstrap_forms.errors.header', :model => Project.model_name.human)}<\/h4>/
33
+ @result.should match /<h4 class="alert-heading">#{I18n.t('bootstrap_forms.errors.header', :model => Project.model_name.human)}<\/h4>/
34
34
  end
35
-
35
+
36
36
  it "has error message on field" do
37
37
  @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>"
38
38
  end
39
-
39
+
40
40
  it "joins passed error message and validation errors with ', '" do
41
41
  @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>"
42
42
  end
43
43
  end
44
44
  end
45
-
45
+
46
46
  describe "text_area" do
47
47
  before(:each) do
48
48
  @result = @builder.text_area "name"
49
49
  end
50
-
50
+
51
51
  it "has textarea input" do
52
52
  @result.should match /textarea/
53
- end
53
+ end
54
54
  end
55
-
55
+
56
56
  describe "check_box" do
57
57
  it "generates wrapped input" do
58
58
  @builder.check_box("name").should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox\" for=\"item_name\"><input name=\"item[name]\" type=\"hidden\" value=\"0\" /><input id=\"item_name\" name=\"item[name]\" type=\"checkbox\" value=\"1\" />Name</label></div></div>"
@@ -61,8 +61,15 @@ describe "BootstrapForms::FormBuilder" do
61
61
  it "allows custom label" do
62
62
  @builder.check_box("name", :label => "custom label").should match /custom label<\/label>/
63
63
  end
64
+
65
+ it "allows no label with :label => false " do
66
+ @builder.check_box("name", :label => false).should_not match /<\/label>/
67
+ end
68
+ it "allows no label with :label => '' " do
69
+ @builder.check_box("name", :label => '').should_not match /<\/label>/
70
+ end
64
71
  end
65
-
72
+
66
73
  describe "radio_buttons" do
67
74
  it "doesn't use field_options from previously generated field" do
68
75
  @builder.text_field :name, :label => 'Heading', :help_inline => 'Inline help', :help_block => 'Block help'
@@ -77,7 +84,7 @@ describe "BootstrapForms::FormBuilder" do
77
84
  it "generates wrapped input" do
78
85
  @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"}).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></div></div>"
79
86
  end
80
-
87
+
81
88
  it "allows custom label" do
82
89
  @builder.radio_buttons(:name, {"One" => "1", "Two" => "2"}, {:label => "custom label"}).should match /custom label<\/label>/
83
90
  end
@@ -89,16 +96,16 @@ describe "BootstrapForms::FormBuilder" do
89
96
  before(:each) do
90
97
  @result = @builder.send(field, "name")
91
98
  end
92
-
99
+
93
100
  it "is wrapped" do
94
101
  @result.should match /^<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\">.*<\/div><\/div>$/
95
102
  end
96
-
103
+
97
104
  it "has an input of type: #{type}" do
98
105
  @result.should match /<input.*type=["#{type}"]/
99
106
  end
100
107
  end # result
101
-
108
+
102
109
  context "call expectations" do
103
110
  %w(control_group_div label_field input_div extras).map(&:to_sym).each do |method|
104
111
  it "calls #{method}" do
@@ -110,40 +117,56 @@ describe "BootstrapForms::FormBuilder" do
110
117
  @builder.send(field, "name")
111
118
  end
112
119
  end # call expectations
113
-
120
+
114
121
  end # field
115
122
  end # fields
116
123
  end # no options
117
-
124
+
118
125
  describe "extras" do
119
126
  context "text_field" do
120
127
  it "adds span for inline help" do
121
128
  @builder.text_field(:name, :help_inline => 'help me!').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\" /><span class=\"help-inline\">help me!</span></div></div>"
122
129
  end
123
-
130
+
124
131
  it "adds help block" do
125
132
  @builder.text_field(:name, :help_block => 'help me!').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\" /><p class=\"help-block\">help me!</p></div></div>"
126
133
  end
127
-
134
+
128
135
  it "adds error message and class" do
129
136
  @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>"
130
137
  end
131
-
138
+
132
139
  it "adds success message and class" do
133
140
  @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>"
134
141
  end
135
-
142
+
136
143
  it "adds warning message and class" do
137
144
  @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>"
138
145
  end
139
-
146
+
140
147
  it "prepends passed text" do
141
148
  @builder.text_field(:name, :prepend => '@').should == "<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name</label><div class=\"controls\"><div class=\"input-prepend\"><span class=\"add-on\">@</span><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" /></div></div></div>"
142
149
  end
143
-
150
+
144
151
  it "appends passed text" do
145
152
  @builder.text_field(:name, :append => '@').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\" /><span class=\"add-on\">@</span></div></div></div>"
146
153
  end
154
+
155
+ it "prepends and appends passed text" do
156
+ @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>"
157
+ end
158
+ end
159
+ context "label option" do
160
+ %w(select email_field file_field number_field password_field search_field text_area text_field url_field).each do |method_name|
161
+
162
+ it "should not add a label when ''" do
163
+ @builder.send(method_name.to_sym, 'name', :label => '').should_not match /<\/label>/
164
+ end
165
+
166
+ it "should not add a label when false" do
167
+ @builder.send(method_name.to_sym, 'name', :label => false).should_not match /<\/label>/
168
+ end
169
+ end
147
170
  end
148
171
  end # extras
149
172
 
@@ -155,19 +178,19 @@ describe "BootstrapForms::FormBuilder" do
155
178
  end.should == "<div class=\"form-actions\"><input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Create Project\" /></div>"
156
179
  end
157
180
  end
158
-
181
+
159
182
  context "submit" do
160
183
  it "adds btn primary class" do
161
184
  @builder.submit.should == "<input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Create Project\" />"
162
185
  end
163
186
  end
164
-
187
+
165
188
  context "button" do
166
189
  it "adds btn primary class" do
167
190
  @builder.submit.should == "<input class=\"btn btn-primary\" name=\"commit\" type=\"submit\" value=\"Create Project\" />"
168
191
  end
169
192
  end
170
-
193
+
171
194
  context "cancel" do
172
195
  it "creates link with correct class" do
173
196
  @builder.should_receive(:link_to).with(I18n.t('bootstrap_forms.buttons.cancel'), :back, :class => 'btn cancel').and_return("")
@@ -176,5 +199,5 @@ describe "BootstrapForms::FormBuilder" do
176
199
  end
177
200
  end # actions
178
201
  end # setup builder
179
-
202
+
180
203
  end
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.0
4
+ version: 2.0.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: 2012-04-09 00:00:00.000000000 Z
12
+ date: 2012-05-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
@@ -124,6 +124,7 @@ files:
124
124
  - Rakefile
125
125
  - bootstrap_forms.gemspec
126
126
  - config/locales/en.yml
127
+ - config/locales/it.yml
127
128
  - config/locales/sv.yml
128
129
  - lib/bootstrap_forms.rb
129
130
  - lib/bootstrap_forms/engine.rb
@@ -189,15 +190,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
190
  - - ! '>='
190
191
  - !ruby/object:Gem::Version
191
192
  version: '0'
193
+ segments:
194
+ - 0
195
+ hash: 3425154550503238939
192
196
  required_rubygems_version: !ruby/object:Gem::Requirement
193
197
  none: false
194
198
  requirements:
195
199
  - - ! '>='
196
200
  - !ruby/object:Gem::Version
197
201
  version: '0'
202
+ segments:
203
+ - 0
204
+ hash: 3425154550503238939
198
205
  requirements: []
199
206
  rubyforge_project:
200
- rubygems_version: 1.8.21
207
+ rubygems_version: 1.8.23
201
208
  signing_key:
202
209
  specification_version: 3
203
210
  summary: Bootstrap Forms makes Twitter's Bootstrap on Rails easy!