bootstrap_forms 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
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.0.
|
6
|
+
s.version = "2.0.4"
|
7
7
|
s.author = "Seth Vargo"
|
8
8
|
s.email = "sethvargo@gmail.com"
|
9
9
|
s.homepage = "https://github.com/sethvargo/bootstrap_forms"
|
@@ -22,7 +22,7 @@ module BootstrapForms
|
|
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
24
|
@name = name
|
25
|
-
@field_options = args
|
25
|
+
@field_options = field_options(args)
|
26
26
|
@args = args
|
27
27
|
|
28
28
|
control_group_div do
|
@@ -35,7 +35,7 @@ module BootstrapForms
|
|
35
35
|
|
36
36
|
def check_box(name, *args)
|
37
37
|
@name = name
|
38
|
-
@field_options = args
|
38
|
+
@field_options = field_options(args)
|
39
39
|
@args = args
|
40
40
|
|
41
41
|
control_group_div do
|
@@ -54,10 +54,10 @@ module BootstrapForms
|
|
54
54
|
|
55
55
|
def radio_buttons(name, values = {}, opts = {})
|
56
56
|
@name = name
|
57
|
-
@field_options = opts.merge(required_attribute)
|
57
|
+
@field_options = @options.slice(:namespace, :index).merge(opts.merge(required_attribute))
|
58
58
|
control_group_div do
|
59
59
|
label_field + input_div do
|
60
|
-
values.map do |text, value|
|
60
|
+
values.map do |text, value|
|
61
61
|
if @field_options[:label] == '' || @field_options[:label] == false
|
62
62
|
extras { radio_button(name, value, @field_options) + text }
|
63
63
|
else
|
@@ -72,7 +72,7 @@ module BootstrapForms
|
|
72
72
|
|
73
73
|
def collection_check_boxes(attribute, records, record_id, record_name, *args)
|
74
74
|
@name = attribute
|
75
|
-
@field_options = args
|
75
|
+
@field_options = field_options(args)
|
76
76
|
@args = args
|
77
77
|
|
78
78
|
control_group_div do
|
@@ -94,7 +94,7 @@ module BootstrapForms
|
|
94
94
|
|
95
95
|
def collection_radio_buttons(attribute, records, record_id, record_name, *args)
|
96
96
|
@name = attribute
|
97
|
-
@field_options = args
|
97
|
+
@field_options = field_options(args)
|
98
98
|
@args = args
|
99
99
|
|
100
100
|
control_group_div do
|
@@ -116,7 +116,7 @@ module BootstrapForms
|
|
116
116
|
|
117
117
|
def uneditable_input(name, *args)
|
118
118
|
@name = name
|
119
|
-
@field_options = args
|
119
|
+
@field_options = field_options(args)
|
120
120
|
@args = args
|
121
121
|
|
122
122
|
control_group_div do
|
@@ -125,7 +125,7 @@ module BootstrapForms
|
|
125
125
|
value = @field_options.delete(:value)
|
126
126
|
@field_options[:class] = [@field_options[:class], 'uneditable-input'].compact
|
127
127
|
|
128
|
-
content_tag(:span, @field_options) do
|
128
|
+
content_tag(:span, @field_options) do
|
129
129
|
value || object.send(@name.to_sym) rescue nil
|
130
130
|
end
|
131
131
|
end
|
@@ -135,7 +135,7 @@ module BootstrapForms
|
|
135
135
|
|
136
136
|
def button(name = nil, *args)
|
137
137
|
@name = name
|
138
|
-
@field_options = args
|
138
|
+
@field_options = field_options(args)
|
139
139
|
@args = args
|
140
140
|
|
141
141
|
@field_options[:class] ||= 'btn btn-primary'
|
@@ -144,7 +144,7 @@ module BootstrapForms
|
|
144
144
|
|
145
145
|
def submit(name = nil, *args)
|
146
146
|
@name = name
|
147
|
-
@field_options = args
|
147
|
+
@field_options = field_options(args)
|
148
148
|
@args = args
|
149
149
|
|
150
150
|
@field_options[:class] ||= 'btn btn-primary'
|
@@ -152,7 +152,7 @@ module BootstrapForms
|
|
152
152
|
end
|
153
153
|
|
154
154
|
def cancel(*args)
|
155
|
-
@field_options = args
|
155
|
+
@field_options = field_options(args)
|
156
156
|
@field_options[:class] ||= 'btn cancel'
|
157
157
|
link_to(I18n.t('bootstrap_forms.buttons.cancel'), (@field_options[:back] || :back), :class => @field_options[:class])
|
158
158
|
end
|
@@ -166,5 +166,14 @@ module BootstrapForms
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
169
|
+
|
170
|
+
private
|
171
|
+
def field_options(args)
|
172
|
+
if @options
|
173
|
+
@options.slice(:namespace, :index).merge(args.extract_options!)
|
174
|
+
else
|
175
|
+
args.extract_options!
|
176
|
+
end
|
177
|
+
end
|
169
178
|
end
|
170
179
|
end
|
@@ -2,7 +2,8 @@ module BootstrapForms
|
|
2
2
|
module Helpers
|
3
3
|
module FormHelper
|
4
4
|
def bootstrap_form_for(record, options = {}, &block)
|
5
|
-
options[:builder]
|
5
|
+
options[:builder] ||= BootstrapForms.default_form_builder
|
6
|
+
|
6
7
|
form_for(record, options) do |f|
|
7
8
|
if f.object.respond_to?(:errors)
|
8
9
|
f.error_messages.html_safe + capture(f, &block).html_safe
|
@@ -13,7 +14,8 @@ module BootstrapForms
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def bootstrap_fields_for(record, options = {}, &block)
|
16
|
-
options[:builder]
|
17
|
+
options[:builder] ||= BootstrapForms.default_form_builder
|
18
|
+
|
17
19
|
fields_for(record, nil, options, &block)
|
18
20
|
end
|
19
21
|
end
|
@@ -2,16 +2,16 @@ module BootstrapForms
|
|
2
2
|
module Helpers
|
3
3
|
module FormTagHelper
|
4
4
|
include BootstrapForms::Helpers::Wrappers
|
5
|
-
|
5
|
+
|
6
6
|
def bootstrap_form_tag(url_for_options = {}, options = {}, &block)
|
7
7
|
form_tag(url_for_options, options, &block)
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
%w(check_box_tag email_field_tag file_field_tag image_submit_tag number_field_tag password_field_tag phone_field_tag radio_button_tag range_field_tag search_field_tag select_tag telephone_field_tag text_area_tag text_field_tag url_field_tag).each do |method_name|
|
11
11
|
# prefix each method with bootstrap_*
|
12
12
|
define_method("bootstrap_#{method_name}") do |name, *args|
|
13
13
|
@name = name
|
14
|
-
@field_options = args
|
14
|
+
@field_options = field_options(args)
|
15
15
|
@args = args
|
16
16
|
|
17
17
|
control_group_div do
|
@@ -21,17 +21,17 @@ module BootstrapForms
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def uneditable_input_tag(name, *args)
|
26
26
|
@name = name
|
27
|
-
@field_options = args
|
27
|
+
@field_options = field_options(args)
|
28
28
|
@args = args
|
29
29
|
|
30
30
|
control_group_div do
|
31
31
|
label_field + input_div do
|
32
32
|
extras do
|
33
33
|
content_tag(:span, :class => 'uneditable-input') do
|
34
|
-
@field_options[:value]
|
34
|
+
@field_options[:value]
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -40,7 +40,7 @@ module BootstrapForms
|
|
40
40
|
|
41
41
|
def bootstrap_button_tag(name = nil, *args)
|
42
42
|
@name = name
|
43
|
-
@field_options = args
|
43
|
+
@field_options = field_options(args)
|
44
44
|
@args = args
|
45
45
|
|
46
46
|
@field_options[:class] = 'btn btn-primary'
|
@@ -49,7 +49,7 @@ module BootstrapForms
|
|
49
49
|
|
50
50
|
def bootstrap_submit_tag(name = nil, *args)
|
51
51
|
@name = name
|
52
|
-
@field_options = args
|
52
|
+
@field_options = field_options(args)
|
53
53
|
@args = args
|
54
54
|
|
55
55
|
@field_options[:class] = 'btn btn-primary'
|
@@ -57,7 +57,7 @@ module BootstrapForms
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def bootstrap_cancel_tag(*args)
|
60
|
-
@field_options = args
|
60
|
+
@field_options = field_options(args)
|
61
61
|
link_to(I18n.t('bootstrap_forms.buttons.cancel'), (@field_options[:back] || :back), :class => 'btn cancel')
|
62
62
|
end
|
63
63
|
|
@@ -66,10 +66,19 @@ module BootstrapForms
|
|
66
66
|
if block_given?
|
67
67
|
yield
|
68
68
|
else
|
69
|
-
[bootstrap_submit_tag, bootstrap_cancel_tag].join(' ').html_safe
|
69
|
+
[ bootstrap_submit_tag, bootstrap_cancel_tag ].join(' ').html_safe
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
def field_options(args)
|
76
|
+
if @options
|
77
|
+
@options.slice(:namespace, :index).merge(args.extract_options!)
|
78
|
+
else
|
79
|
+
args.extract_options!
|
80
|
+
end
|
81
|
+
end
|
73
82
|
end
|
74
83
|
end
|
75
84
|
end
|
@@ -1,81 +1,99 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
context
|
3
|
+
describe 'BootstrapForms::FormBuilder' do
|
4
|
+
context 'given a setup builder' do
|
5
5
|
before(:each) do
|
6
6
|
@project = Project.new
|
7
7
|
@template = ActionView::Base.new
|
8
|
-
@template.output_buffer =
|
8
|
+
@template.output_buffer =''
|
9
9
|
@builder = BootstrapForms::FormBuilder.new(:item, @project, @template, {}, proc {})
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
context 'with no options' do
|
13
|
+
it_behaves_like 'a bootstrap form'
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
16
|
+
context 'with the :namespace option' do
|
17
|
+
before(:each) do
|
18
|
+
@builder.options[:namespace] = 'foo'
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
21
|
+
it 'prefixs HTML ids correctly' do
|
22
|
+
@builder.text_field('name').should match /<(input) .*id="foo_item_name"/
|
23
|
+
end
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
context 'with the :index option' do
|
27
|
+
before(:each) do
|
28
|
+
@builder.options[:index] = 69
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
it 'uses the correct :index' do
|
32
|
+
@builder.text_field('name').should match /<input .*id="item_69_name"/
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
it 'does not add extraneous input data' do
|
36
|
+
@builder.text_field('name').should_not match /<input .*index/
|
37
|
+
end
|
38
|
+
end
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
context 'with the :namespace and :index options' do
|
41
|
+
before(:each) do
|
42
|
+
@builder.options[:namespace] = 'foo'
|
43
|
+
@builder.options[:index] = 69
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
+
it 'uses the correct :index' do
|
47
|
+
@builder.text_field('name').should match /<input .*id="foo_item_69_name"/
|
46
48
|
end
|
47
49
|
end
|
48
50
|
|
49
|
-
context
|
51
|
+
context 'with :html options' do
|
50
52
|
before(:each) do
|
51
|
-
@
|
53
|
+
@builder.options[:html] = { :class => 'foo' }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'does not add the class to the elements' do
|
57
|
+
@builder.text_field('name').should_not match /<input .*class="foo"/
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'without errors' do
|
62
|
+
it 'returns empty string' do
|
63
|
+
@builder.error_messages.should be_empty
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'errors' do
|
68
|
+
before(:each) do
|
69
|
+
@project.errors.add('name')
|
52
70
|
@result = @builder.error_messages
|
53
71
|
end
|
54
72
|
|
55
|
-
it
|
73
|
+
it 'are wrapped in error div' do
|
56
74
|
@result.should match /^<div class="alert alert-block alert-error validation-errors">.*<\/div>$/
|
57
75
|
end
|
58
76
|
|
59
|
-
it
|
77
|
+
it 'have a list with errors' do
|
60
78
|
@result.should match /<ul><li>Name is invalid<\/li><\/ul>/
|
61
79
|
end
|
62
80
|
|
63
|
-
it
|
81
|
+
it 'have error title' do
|
64
82
|
@result.should match /<h4 class="alert-heading">#{I18n.t('bootstrap_forms.errors.header', :model => Project.model_name.human)}<\/h4>/
|
65
83
|
end
|
66
84
|
|
67
|
-
it
|
68
|
-
@builder.text_field(
|
85
|
+
it 'have error message on field' do
|
86
|
+
@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>"
|
69
87
|
end
|
70
88
|
|
71
89
|
it "joins passed error message and validation errors with ', '" do
|
72
|
-
@builder.text_field(
|
90
|
+
@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>"
|
73
91
|
end
|
74
92
|
end
|
75
93
|
|
76
|
-
context
|
77
|
-
it
|
78
|
-
@builder.text_field(
|
94
|
+
context 'an attribute with a PresenceValidator' do
|
95
|
+
it 'adds the required attribute' do
|
96
|
+
@builder.text_field('owner').should match /<input .*required="required"/
|
79
97
|
end
|
80
98
|
end
|
81
99
|
|
@@ -92,10 +110,10 @@ describe "BootstrapForms::FormBuilder" do
|
|
92
110
|
end
|
93
111
|
end
|
94
112
|
|
95
|
-
context
|
113
|
+
context 'setup builder with a symbol' do
|
96
114
|
before(:each) do
|
97
115
|
@template = ActionView::Base.new
|
98
|
-
@template.output_buffer =
|
116
|
+
@template.output_buffer = ''
|
99
117
|
@builder = BootstrapForms::FormBuilder.new(:item, nil, @template, {}, proc {})
|
100
118
|
end
|
101
119
|
|
@@ -112,6 +130,7 @@ describe 'BootstrapForms::Helpers::FormTagHelper' do
|
|
112
130
|
@template.output_buffer = ""
|
113
131
|
@builder = BootstrapForms::FormBuilder.new(:item, @non_active_record_object, @template, {}, proc {})
|
114
132
|
end
|
133
|
+
|
115
134
|
it 'returns an empty string with no errors' do
|
116
135
|
@template.bootstrap_text_field_tag(@builder.object[:name]).should match /<div class="control-group">.*/
|
117
136
|
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.
|
4
|
+
version: 2.0.4
|
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-
|
12
|
+
date: 2012-11-07 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: -
|
198
|
+
hash: -722096709655512624
|
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: -
|
207
|
+
hash: -722096709655512624
|
208
208
|
requirements: []
|
209
209
|
rubyforge_project:
|
210
210
|
rubygems_version: 1.8.24
|