bootstrap_forms 2.0.8 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +0 -1
- data/.ruby-version +1 -0
- data/.travis.yml +4 -1
- data/README.markdown +34 -3
- data/bootstrap_forms.gemspec +2 -1
- data/lib/bootstrap_forms/form_builder.rb +33 -18
- data/lib/bootstrap_forms/helpers/wrappers.rb +42 -6
- data/spec/dummy/app/helpers/my_custom_form_builder.rb +3 -3
- data/spec/dummy/app/models/project.rb +6 -0
- data/spec/lib/bootstrap_forms/bootstrap_form_for_spec.rb +26 -26
- data/spec/lib/bootstrap_forms/form_builder_spec.rb +27 -0
- data/spec/support/shared_context.rb +31 -5
- metadata +22 -5
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p385
|
data/.travis.yml
CHANGED
data/README.markdown
CHANGED
@@ -64,6 +64,12 @@ Just when you thought you were done... Bootstrap Forms includes additional form
|
|
64
64
|
= f.collection_check_boxes :category_ids, Category.all, :id, :name
|
65
65
|
```
|
66
66
|
|
67
|
+
You can set the `inline` option to build inline checkboxes:
|
68
|
+
|
69
|
+
```haml
|
70
|
+
= f.collection_check_boxes :category_ids, Category.all, :id, :name, :inline => true
|
71
|
+
```
|
72
|
+
|
67
73
|
### collection_radio_buttons
|
68
74
|
See description above...
|
69
75
|
|
@@ -71,12 +77,32 @@ See description above...
|
|
71
77
|
= f.collection_radio_buttons :primary_category_id, Category.all, :id, :name
|
72
78
|
```
|
73
79
|
|
80
|
+
You can set the `inline` option to build inline radios:
|
81
|
+
|
82
|
+
```haml
|
83
|
+
= f.collection_radio_buttons :primary_category_id, Category.all, :id, :name, :inline => true
|
84
|
+
```
|
85
|
+
|
86
|
+
### check_box
|
87
|
+
|
88
|
+
Also supports `inline` option:
|
89
|
+
|
90
|
+
```haml
|
91
|
+
= f.check_box :enabled, :inline => true
|
92
|
+
```
|
93
|
+
|
74
94
|
### radio_buttons
|
75
95
|
|
76
96
|
```haml
|
77
97
|
= f.radio_buttons :published, { "Published" => true, "Unpublished" => false }
|
78
98
|
```
|
79
99
|
|
100
|
+
You can set the `:inline` option to build inline radios.
|
101
|
+
|
102
|
+
```haml
|
103
|
+
= f.radio_buttons :published, { "Published" => true, "Unpublished" => false }, { :inline => true }
|
104
|
+
```
|
105
|
+
|
80
106
|
Ruby 1.8 doesn't guarantee hashes are ordered. If you care, pass in nested arrays or `ActiveSupport::OrderedHash`.
|
81
107
|
|
82
108
|
Uneditable Input
|
@@ -100,10 +126,10 @@ yields:
|
|
100
126
|
|
101
127
|
Submit Tag
|
102
128
|
----------
|
103
|
-
Bootstrap Forms also adds a default actions panel when you call `f.
|
129
|
+
Bootstrap Forms also adds a default actions panel when you call `f.actions`:
|
104
130
|
|
105
131
|
```haml
|
106
|
-
= f.
|
132
|
+
= f.actions
|
107
133
|
```
|
108
134
|
|
109
135
|
generates:
|
@@ -185,9 +211,14 @@ You can add as many options to any form helper tag. If they are interpreted by B
|
|
185
211
|
</tr>
|
186
212
|
<tr>
|
187
213
|
<th>control_group</th>
|
188
|
-
<td>Pass false to remove the control group and controls HTML, leaving only the label and input
|
214
|
+
<td>Pass false to remove the control group and controls HTML, leaving only the label and input.</td>
|
189
215
|
<td><tt>= f.text_field :name, :control_group => false</tt></td>
|
190
216
|
</tr>
|
217
|
+
<tr>
|
218
|
+
<th>:required => false</th>
|
219
|
+
<td>Pass false to ignore presence validation checks that add a required attribute on the generated element.</td>
|
220
|
+
<td><tt>= f.text_field :name, :required => false</tt></td>
|
221
|
+
</tr>
|
191
222
|
</table>
|
192
223
|
|
193
224
|
Internationalization/Custom Errors
|
data/bootstrap_forms.gemspec
CHANGED
@@ -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.
|
6
|
+
s.version = '2.1.1'
|
7
7
|
s.author = 'Seth Vargo'
|
8
8
|
s.email = 'sethvargo@gmail.com'
|
9
9
|
s.homepage = 'https://github.com/sethvargo/bootstrap_forms'
|
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency 'rails', '~> 3.2.0'
|
22
22
|
s.add_development_dependency 'guard-rspec'
|
23
23
|
s.add_development_dependency 'sqlite3'
|
24
|
+
s.add_development_dependency 'fuubar'
|
24
25
|
end
|
@@ -21,19 +21,24 @@ module BootstrapForms
|
|
21
21
|
|
22
22
|
%w(collection_select select country_select time_zone_select email_field file_field number_field password_field phone_field range_field search_field telephone_field text_area text_field url_field datetime_select date_select time_select).each do |method_name|
|
23
23
|
define_method(method_name) do |name, *args|
|
24
|
+
# Workaround for ree and 1.8.7 since they don't allow block arguments with default values
|
25
|
+
args = args.extract_options!
|
26
|
+
|
24
27
|
@name = name
|
25
28
|
@field_options = field_options(args)
|
26
29
|
@args = args
|
27
30
|
|
28
31
|
control_group_div do
|
29
32
|
label_field + input_div do
|
30
|
-
|
33
|
+
merged_args = @args.merge(@field_options.merge(required_attribute))
|
34
|
+
input_append = (merged_args[:append] || merged_args[:prepend] || merged_args[:append_button]) ? true : nil
|
35
|
+
extras(input_append) { super(name, merged_args) }
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
|
-
def check_box(name,
|
41
|
+
def check_box(name, args = {})
|
37
42
|
@name = name
|
38
43
|
@field_options = field_options(args)
|
39
44
|
@args = args
|
@@ -42,10 +47,13 @@ module BootstrapForms
|
|
42
47
|
input_div do
|
43
48
|
@field_options.merge!(required_attribute)
|
44
49
|
if @field_options[:label] == false || @field_options[:label] == ''
|
45
|
-
extras { super(name,
|
50
|
+
extras { super(name, @args.merge(@field_options)) }
|
46
51
|
else
|
47
|
-
|
48
|
-
|
52
|
+
klasses = 'checkbox'
|
53
|
+
klasses << ' inline' if @field_options.delete(:inline) == true
|
54
|
+
@args.delete :inline
|
55
|
+
label(@name, :class => klasses) do
|
56
|
+
extras { super(name, @args.merge(@field_options)) + (@field_options[:label].blank? ? human_attribute_name : @field_options[:label])}
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end
|
@@ -57,8 +65,10 @@ module BootstrapForms
|
|
57
65
|
@field_options = @options.slice(:namespace, :index).merge(opts.merge(required_attribute))
|
58
66
|
control_group_div do
|
59
67
|
label_field + input_div do
|
68
|
+
klasses = 'radio'
|
69
|
+
klasses << ' inline' if @field_options.delete(:inline) == true
|
60
70
|
values.map do |text, value|
|
61
|
-
label("#{@name}_#{value}", :class =>
|
71
|
+
label("#{@name}_#{value}", :class => klasses) do
|
62
72
|
extras { radio_button(name, value, @field_options) + text }
|
63
73
|
end
|
64
74
|
end.join.html_safe
|
@@ -66,7 +76,7 @@ module BootstrapForms
|
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
def collection_check_boxes(attribute, records, record_id, record_name,
|
79
|
+
def collection_check_boxes(attribute, records, record_id, record_name, args = {})
|
70
80
|
@name = attribute
|
71
81
|
@field_options = field_options(args)
|
72
82
|
@args = args
|
@@ -88,7 +98,7 @@ module BootstrapForms
|
|
88
98
|
end
|
89
99
|
end
|
90
100
|
|
91
|
-
def collection_radio_buttons(attribute, records, record_id, record_name,
|
101
|
+
def collection_radio_buttons(attribute, records, record_id, record_name, args = {})
|
92
102
|
@name = attribute
|
93
103
|
@field_options = field_options(args)
|
94
104
|
@args = args
|
@@ -110,7 +120,7 @@ module BootstrapForms
|
|
110
120
|
end
|
111
121
|
end
|
112
122
|
|
113
|
-
def uneditable_input(name,
|
123
|
+
def uneditable_input(name, args = {})
|
114
124
|
@name = name
|
115
125
|
@field_options = field_options(args)
|
116
126
|
@args = args
|
@@ -129,28 +139,33 @@ module BootstrapForms
|
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
132
|
-
def button(name = nil,
|
142
|
+
def button(name = nil, args = {})
|
143
|
+
name, args = nil, name if name.is_a?(Hash)
|
133
144
|
@name = name
|
134
145
|
@field_options = field_options(args)
|
135
146
|
@args = args
|
136
147
|
|
137
|
-
@field_options[:class] ||= 'btn
|
138
|
-
super(name,
|
148
|
+
@field_options[:class] ||= 'btn'
|
149
|
+
super(name, args.merge(@field_options))
|
139
150
|
end
|
140
151
|
|
141
|
-
def submit(name = nil,
|
152
|
+
def submit(name = nil, args = {})
|
153
|
+
name, args = nil, name if name.is_a?(Hash)
|
142
154
|
@name = name
|
143
155
|
@field_options = field_options(args)
|
144
156
|
@args = args
|
145
157
|
|
146
158
|
@field_options[:class] ||= 'btn btn-primary'
|
147
|
-
super(name,
|
159
|
+
super(name, args.merge(@field_options))
|
148
160
|
end
|
149
161
|
|
150
|
-
def cancel(
|
162
|
+
def cancel(name = nil, args = {})
|
163
|
+
name, args = nil, name if name.is_a?(Hash)
|
164
|
+
name ||= I18n.t('bootstrap_forms.buttons.cancel')
|
151
165
|
@field_options = field_options(args)
|
152
166
|
@field_options[:class] ||= 'btn cancel'
|
153
|
-
|
167
|
+
@field_options[:back] ||= :back
|
168
|
+
link_to(name, @field_options[:back], :class => @field_options[:class])
|
154
169
|
end
|
155
170
|
|
156
171
|
def actions(&block)
|
@@ -166,9 +181,9 @@ module BootstrapForms
|
|
166
181
|
private
|
167
182
|
def field_options(args)
|
168
183
|
if @options
|
169
|
-
@options.slice(:namespace, :index).merge(args
|
184
|
+
@options.slice(:namespace, :index).merge(args)
|
170
185
|
else
|
171
|
-
args
|
186
|
+
args
|
172
187
|
end
|
173
188
|
end
|
174
189
|
end
|
@@ -19,7 +19,11 @@ module BootstrapForms
|
|
19
19
|
control_group_options = {}
|
20
20
|
control_group_options[:class] = klasses if !klasses.empty?
|
21
21
|
|
22
|
-
|
22
|
+
if @field_options[:control_group] == false
|
23
|
+
yield
|
24
|
+
else
|
25
|
+
content_tag(:div, control_group_options, &block)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
def error_string
|
@@ -55,7 +59,9 @@ module BootstrapForms
|
|
55
59
|
klass = []
|
56
60
|
klass << 'input-prepend' if @field_options[:prepend]
|
57
61
|
klass << 'input-append' if @field_options[:append] || @field_options[:append_button]
|
58
|
-
content_tag(:div, :class => klass, &block)
|
62
|
+
html = content_tag(:div, :class => klass, &block)
|
63
|
+
html << extras(false, &block) if @field_options[:help_inline] || @field_options[:help_block] || @field_options[:error] || @field_options[:success] || @field_options[:warning]
|
64
|
+
html
|
59
65
|
else
|
60
66
|
yield if block_given?
|
61
67
|
end
|
@@ -76,12 +82,35 @@ module BootstrapForms
|
|
76
82
|
end
|
77
83
|
|
78
84
|
def required_attribute
|
85
|
+
return {} if @field_options.present? && @field_options.has_key?(:required) && !@field_options[:required]
|
86
|
+
|
79
87
|
if respond_to?(:object) and object.respond_to?(:errors) and object.class.respond_to?('validators_on')
|
80
|
-
return { :required => true } if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
|
88
|
+
return { :required => true } if object.class.validators_on(@name).any? { |v| v.kind_of?( ActiveModel::Validations::PresenceValidator ) && valid_validator?( v ) }
|
81
89
|
end
|
82
90
|
{}
|
83
91
|
end
|
84
92
|
|
93
|
+
def valid_validator?(validator)
|
94
|
+
!conditional_validators?(validator) && action_validator_match?(validator)
|
95
|
+
end
|
96
|
+
|
97
|
+
def conditional_validators?(validator)
|
98
|
+
validator.options.include?(:if) || validator.options.include?(:unless)
|
99
|
+
end
|
100
|
+
|
101
|
+
def action_validator_match?(validator)
|
102
|
+
return true if !validator.options.include?(:on)
|
103
|
+
case validator.options[:on]
|
104
|
+
when :save
|
105
|
+
true
|
106
|
+
when :create
|
107
|
+
!object.persisted?
|
108
|
+
when :update
|
109
|
+
object.persisted?
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
85
114
|
%w(help_inline error success warning help_block append append_button prepend).each do |method_name|
|
86
115
|
define_method(method_name) do |*args|
|
87
116
|
return '' unless value = @field_options[method_name.to_sym]
|
@@ -90,7 +119,7 @@ module BootstrapForms
|
|
90
119
|
tag_options = {}
|
91
120
|
case method_name
|
92
121
|
when 'help_block'
|
93
|
-
element = :
|
122
|
+
element = :span
|
94
123
|
tag_options[:class] = 'help-block'
|
95
124
|
when 'append', 'prepend'
|
96
125
|
element = :span
|
@@ -119,8 +148,15 @@ module BootstrapForms
|
|
119
148
|
end
|
120
149
|
end
|
121
150
|
|
122
|
-
def extras(&block)
|
123
|
-
|
151
|
+
def extras(input_append = nil, &block)
|
152
|
+
case input_append
|
153
|
+
when nil
|
154
|
+
[prepend, (yield if block_given?), append, append_button, help_inline, error, success, warning, help_block].join('').html_safe
|
155
|
+
when true
|
156
|
+
[prepend, (yield if block_given?), append, append_button].join('').html_safe
|
157
|
+
when false
|
158
|
+
[help_inline, error, success, warning, help_block].join('').html_safe
|
159
|
+
end
|
124
160
|
end
|
125
161
|
|
126
162
|
def objectify_options(options)
|
@@ -2,4 +2,10 @@ class Project < ActiveRecord::Base
|
|
2
2
|
has_many :tasks
|
3
3
|
accepts_nested_attributes_for :tasks
|
4
4
|
validates :owner, :presence => true
|
5
|
+
validates :if_presence, :presence => true, :if => lambda { true}
|
6
|
+
validates :unless_presence, :presence => true, :unless => lambda { true}
|
7
|
+
validates :create_presence, :presence => true, :on => :create
|
8
|
+
validates :update_presence, :presence => true, :on => :update
|
9
|
+
attr_accessor :if_presence, :unless_presence, :create_presence, :update_presence
|
10
|
+
|
5
11
|
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'bootstrap_form_for' do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
describe 'default_form_builder' do
|
5
|
+
it 'should be accessible' do
|
6
|
+
BootstrapForms.should respond_to(:default_form_builder)
|
7
|
+
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
it 'should be the BootstrapForms form_builder by default' do
|
10
|
+
BootstrapForms.default_form_builder.should == BootstrapForms::FormBuilder
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
context 'when set to something else' do
|
14
|
+
before do
|
15
|
+
BootstrapForms.default_form_builder = MyCustomFormBuilder
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
it 'should be that other thing' do
|
19
|
+
BootstrapForms.default_form_builder.should == MyCustomFormBuilder
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
describe 'projects/new.html.erb', :type => :view do
|
23
|
+
before do
|
24
|
+
assign :project, Project.new
|
25
|
+
render :file => 'projects/new', :layout => 'layouts/application', :handlers => [:erb]
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
it 'should render with the other form builder' do
|
29
|
+
# in other words, it shouldn't be wrapped with the bootstrap stuff
|
30
|
+
rendered.should_not match /<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\">.*<\/div><\/div>/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
35
|
end
|
@@ -95,6 +95,33 @@ describe 'BootstrapForms::FormBuilder' do
|
|
95
95
|
it 'adds the required attribute' do
|
96
96
|
@builder.text_field('owner').should match /<input .*required="required"/
|
97
97
|
end
|
98
|
+
|
99
|
+
it "does not add the required attribute if required: false" do
|
100
|
+
@builder.text_field('owner', :required => false).should_not match /<input .*required="required"/
|
101
|
+
end
|
102
|
+
|
103
|
+
it "not require if or unless validators" do
|
104
|
+
@builder.text_field('if_presence').should_not match /<input .*required="required"/
|
105
|
+
@builder.text_field('unless_presence').should_not match /<input .*required="required"/
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should not be required if presence is on update and model is created" do
|
109
|
+
@builder.text_field('update_presence').should_not match /<input .*required="required"/
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should be required if on create and model is new" do
|
113
|
+
@builder.text_field('create_presence').should match /<input .*required="required"/
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be required if presence is on update and model is not new" do
|
117
|
+
@project.stub!(:persisted?).and_return(true)
|
118
|
+
@builder.text_field('update_presence').should match /<input .*required="required"/
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should not be required if on create and model is not new" do
|
122
|
+
@project.stub!(:persisted?).and_return(true)
|
123
|
+
@builder.text_field('create_presence').should_not match /<input .*required="required"/
|
124
|
+
end
|
98
125
|
end
|
99
126
|
|
100
127
|
context 'submit' do
|
@@ -41,6 +41,10 @@ shared_examples 'a bootstrap form' do
|
|
41
41
|
it 'allows no label with :label => '' ' do
|
42
42
|
@builder.check_box('name', :label => '').should_not match /<\/label>/
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'adds inline class' do
|
46
|
+
@builder.check_box('name', :inline => true).should == "<div class=\"control-group\"><div class=\"controls\"><label class=\"checkbox inline\" 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>"
|
47
|
+
end
|
44
48
|
end
|
45
49
|
|
46
50
|
describe 'radio_buttons' do
|
@@ -75,6 +79,10 @@ shared_examples 'a bootstrap form' do
|
|
75
79
|
it 'allows no label' do
|
76
80
|
@builder.radio_buttons(:name, @options, {:label => false}).should == "<div class=\"control-group\"><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>"
|
77
81
|
end
|
82
|
+
|
83
|
+
it 'adds inline class' do
|
84
|
+
@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>"
|
85
|
+
end
|
78
86
|
end
|
79
87
|
|
80
88
|
(%w{email file number password range search text url }.map{|field| ["#{field}_field",field]} + [['telephone_field', 'tel'], ['phone_field', 'tel']]).each do |field, type|
|
@@ -116,13 +124,17 @@ shared_examples 'a bootstrap form' do
|
|
116
124
|
end
|
117
125
|
|
118
126
|
it 'adds help block' do
|
119
|
-
@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\" /><
|
127
|
+
@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\" /><span class=\"help-block\">help me!</span></div></div>"
|
120
128
|
end
|
121
129
|
|
122
130
|
it 'adds error message and class' do
|
123
131
|
@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>"
|
124
132
|
end
|
125
133
|
|
134
|
+
it 'adds error message, class and appended text' do
|
135
|
+
@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>"
|
136
|
+
end
|
137
|
+
|
126
138
|
it 'adds success message and class' do
|
127
139
|
@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>"
|
128
140
|
end
|
@@ -143,6 +155,14 @@ shared_examples 'a bootstrap form' do
|
|
143
155
|
@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
156
|
end
|
145
157
|
|
158
|
+
it 'prepends, appends and adds inline help' do
|
159
|
+
@builder.text_field(:name, :append => '@', :prepend => '#', :help_inline => 'some help').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><span class=\"help-inline\">some help</span></div></div>"
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'prepends, appends and adds block help' do
|
163
|
+
@builder.text_field(:name, :append => '@', :prepend => '#', :help_block => 'some help').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><span class=\"help-block\">some help</span></div></div>"
|
164
|
+
end
|
165
|
+
|
146
166
|
it 'appends button with default values' do
|
147
167
|
@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
168
|
end
|
@@ -160,10 +180,10 @@ shared_examples 'a bootstrap form' do
|
|
160
180
|
end
|
161
181
|
|
162
182
|
it "does not add control group" do
|
163
|
-
@builder.text_field(:name, :control_group => false).should == "<
|
183
|
+
@builder.text_field(:name, :control_group => false).should == "<label for=\"item_name\">Name</label><input id=\"item_name\" name=\"item[name]\" size=\"30\" type=\"text\" />"
|
164
184
|
end
|
165
185
|
|
166
|
-
it "
|
186
|
+
it "adds control group attribute to html if :control_group is true" do
|
167
187
|
@builder.text_field(:name, :control_group => true).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\" /></div></div>"
|
168
188
|
end
|
169
189
|
end
|
@@ -202,8 +222,8 @@ shared_examples 'a bootstrap form' do
|
|
202
222
|
end
|
203
223
|
|
204
224
|
context 'button' do
|
205
|
-
it 'adds btn
|
206
|
-
@builder.button.should match /class=\"btn
|
225
|
+
it 'adds btn class if no class is defined' do
|
226
|
+
@builder.button.should match /class=\"btn\"/
|
207
227
|
end
|
208
228
|
|
209
229
|
it 'allows for custom classes' do
|
@@ -221,6 +241,12 @@ shared_examples 'a bootstrap form' do
|
|
221
241
|
@builder.should_receive(:link_to).with(I18n.t('bootstrap_forms.buttons.cancel'), :back, :class => 'btn btn-large my-cancel').and_return("")
|
222
242
|
@builder.cancel(:class => 'btn btn-large my-cancel')
|
223
243
|
end
|
244
|
+
|
245
|
+
it 'creates a link with a custom name when defined' do
|
246
|
+
name = 'Back'
|
247
|
+
@builder.should_receive(:link_to).with(name, :back, :class => 'btn cancel').and_return("")
|
248
|
+
@builder.cancel(name)
|
249
|
+
end
|
224
250
|
end
|
225
251
|
end # actions
|
226
252
|
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.
|
4
|
+
version: 2.1.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:
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|
@@ -107,6 +107,22 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fuubar
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
110
126
|
description: Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating
|
111
127
|
helpful form builders that minimize markup in your views.
|
112
128
|
email: sethvargo@gmail.com
|
@@ -116,6 +132,7 @@ extra_rdoc_files: []
|
|
116
132
|
files:
|
117
133
|
- .gitignore
|
118
134
|
- .rspec
|
135
|
+
- .ruby-version
|
119
136
|
- .travis.yml
|
120
137
|
- Gemfile
|
121
138
|
- Guardfile
|
@@ -196,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
213
|
version: '0'
|
197
214
|
segments:
|
198
215
|
- 0
|
199
|
-
hash: -
|
216
|
+
hash: -1030141123140574531
|
200
217
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
218
|
none: false
|
202
219
|
requirements:
|
@@ -205,10 +222,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
222
|
version: '0'
|
206
223
|
segments:
|
207
224
|
- 0
|
208
|
-
hash: -
|
225
|
+
hash: -1030141123140574531
|
209
226
|
requirements: []
|
210
227
|
rubyforge_project:
|
211
|
-
rubygems_version: 1.8.
|
228
|
+
rubygems_version: 1.8.23
|
212
229
|
signing_key:
|
213
230
|
specification_version: 3
|
214
231
|
summary: Bootstrap Forms makes Twitter's Bootstrap on Rails easy!
|