bootstrap_forms 3.0.0.rc1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/{README.markdown → README.md} +17 -1
- data/bootstrap_forms.gemspec +2 -1
- data/lib/bootstrap_forms/form_builder.rb +38 -33
- data/lib/bootstrap_forms/helpers/form_helper.rb +6 -2
- data/lib/bootstrap_forms/helpers/form_tag_helper.rb +17 -1
- data/spec/dummy/app/views/projects/new_without_summary_errors.html.erb +4 -0
- data/spec/lib/bootstrap_forms/bootstrap_form_for_spec.rb +13 -0
- data/spec/support/shared_context.rb +25 -0
- metadata +25 -10
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.3-
|
1
|
+
1.9.3-p392
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
@@ -149,7 +149,23 @@ Adding More Options
|
|
149
149
|
-------------------
|
150
150
|
You can add as many options to any form helper tag. If they are interpreted by Bootstrap Forms, they are interpreted and rendered in the output. If not, they are passed along as values to the final HTML form object.
|
151
151
|
|
152
|
-
###
|
152
|
+
### Form Options
|
153
|
+
<table>
|
154
|
+
<tr>
|
155
|
+
<th>Name</th>
|
156
|
+
<th>Description</th>
|
157
|
+
<th>Usage</th>
|
158
|
+
<th>Default</th>
|
159
|
+
</tr>
|
160
|
+
<tr>
|
161
|
+
<th>summary_errors</th>
|
162
|
+
<td>Show summary errors at the top</td>
|
163
|
+
<td><tt>= bootstrap_form_for @thing, summary_errors: false</td></td>
|
164
|
+
<td><tt>true</tt></td>
|
165
|
+
</tr>
|
166
|
+
</table>
|
167
|
+
|
168
|
+
### Field Options
|
153
169
|
|
154
170
|
<table>
|
155
171
|
<tr>
|
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 = '3.0.0
|
6
|
+
s.version = '3.0.0'
|
7
7
|
s.author = 'Seth Vargo'
|
8
8
|
s.email = 'sethvargo@gmail.com'
|
9
9
|
s.homepage = 'https://github.com/sethvargo/bootstrap_forms'
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.add_development_dependency 'capybara', '~> 2.0.0'
|
20
20
|
s.add_development_dependency 'rake'
|
21
21
|
s.add_development_dependency 'rails', '~> 3.2.0'
|
22
|
+
s.add_development_dependency 'country_select', '~> 1.1.1'
|
22
23
|
s.add_development_dependency 'guard-rspec'
|
23
24
|
s.add_development_dependency 'sqlite3'
|
24
25
|
s.add_development_dependency 'fuubar'
|
@@ -19,48 +19,53 @@ module BootstrapForms
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
%w(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
%w(
|
23
|
+
select
|
24
|
+
collection_select
|
25
|
+
country_select
|
26
|
+
datetime_select
|
27
|
+
date_select
|
28
|
+
time_select
|
29
|
+
time_zone_select
|
30
|
+
|
31
|
+
email_field
|
32
|
+
file_field
|
33
|
+
number_field
|
34
|
+
password_field
|
35
|
+
phone_field
|
36
|
+
range_field
|
37
|
+
search_field
|
38
|
+
telephone_field
|
39
|
+
text_area
|
40
|
+
text_field
|
41
|
+
url_field
|
42
|
+
).each do |method_name|
|
43
|
+
define_method(method_name) do |name, *raw_args|
|
44
|
+
|
45
|
+
options = {}
|
46
|
+
html_options = {}
|
47
|
+
|
48
|
+
if raw_args.length > 0
|
49
|
+
if raw_args[-1].is_a?(Hash) && raw_args[-2].is_a?(Hash)
|
50
|
+
html_options = raw_args[-1]
|
51
|
+
options = raw_args[-2]
|
52
|
+
elsif raw_args[-1].is_a?(Hash)
|
53
|
+
options = raw_args[-1]
|
36
54
|
end
|
37
55
|
end
|
38
|
-
end
|
39
|
-
end
|
40
56
|
|
41
|
-
|
42
|
-
|
43
|
-
if args[-1].is_a? Hash
|
44
|
-
if args[-2].is_a? Hash
|
45
|
-
html_options = args.pop
|
46
|
-
options = args.pop
|
47
|
-
else
|
48
|
-
html_options = {}
|
49
|
-
options = args.pop
|
50
|
-
end
|
51
|
-
else
|
52
|
-
html_options = {}
|
53
|
-
options = {}
|
54
|
-
end
|
57
|
+
# Add options hash to argument array if its empty
|
58
|
+
raw_args << options if raw_args.length == 0
|
55
59
|
|
56
60
|
@name = name
|
57
61
|
@field_options = field_options(options)
|
58
|
-
@args =
|
62
|
+
@args = options
|
59
63
|
|
60
64
|
control_group_div do
|
61
65
|
label_field + input_div do
|
62
|
-
|
63
|
-
|
66
|
+
options.merge!(@field_options.merge(required_attribute))
|
67
|
+
input_append = (options[:append] || options[:prepend] || options[:append_button]) ? true : nil
|
68
|
+
extras(input_append) { super(name, *raw_args) }
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
@@ -4,8 +4,12 @@ module BootstrapForms
|
|
4
4
|
def bootstrap_form_for(record, options = {}, &block)
|
5
5
|
options[:builder] ||= BootstrapForms.default_form_builder
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
form_options = options.deep_dup
|
8
|
+
options[:summary_errors] = true unless form_options.has_key?(:summary_errors)
|
9
|
+
form_options.delete(:summary_errors)
|
10
|
+
|
11
|
+
form_for(record, form_options) do |f|
|
12
|
+
if f.object.respond_to?(:errors) and options[:summary_errors]
|
9
13
|
f.error_messages.html_safe + capture(f, &block).html_safe
|
10
14
|
else
|
11
15
|
capture(f, &block).html_safe
|
@@ -7,7 +7,23 @@ module BootstrapForms
|
|
7
7
|
form_tag(url_for_options, options, &block)
|
8
8
|
end
|
9
9
|
|
10
|
-
%w(
|
10
|
+
%w(
|
11
|
+
check_box_tag
|
12
|
+
email_field_tag
|
13
|
+
file_field_tag
|
14
|
+
image_submit_tag
|
15
|
+
number_field_tag
|
16
|
+
password_field_tag
|
17
|
+
phone_field_tag
|
18
|
+
radio_button_tag
|
19
|
+
range_field_tag
|
20
|
+
search_field_tag
|
21
|
+
select_tag
|
22
|
+
telephone_field_tag
|
23
|
+
text_area_tag
|
24
|
+
text_field_tag
|
25
|
+
url_field_tag
|
26
|
+
).each do |method_name|
|
11
27
|
# prefix each method with bootstrap_*
|
12
28
|
define_method("bootstrap_#{method_name}") do |name, *args|
|
13
29
|
@name = name
|
@@ -10,6 +10,19 @@ describe 'bootstrap_form_for' do
|
|
10
10
|
BootstrapForms.default_form_builder.should == BootstrapForms::FormBuilder
|
11
11
|
end
|
12
12
|
|
13
|
+
context 'projects/new_without_summary_errors.html.erb', :type => :view do
|
14
|
+
before do
|
15
|
+
project = Project.new
|
16
|
+
project.errors.add('name')
|
17
|
+
assign :project, project
|
18
|
+
render :file => 'projects/new_without_summary_errors', :layout => 'layouts/application', :handlers => [:erb]
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should not render the full error messages div' do
|
22
|
+
rendered.should_not match /There were errors that prevented this Project from being saved/
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
13
26
|
context 'when set to something else' do
|
14
27
|
before do
|
15
28
|
BootstrapForms.default_form_builder = MyCustomFormBuilder
|
@@ -1,3 +1,6 @@
|
|
1
|
+
|
2
|
+
require 'country_select'
|
3
|
+
|
1
4
|
shared_examples 'a bootstrap form' do
|
2
5
|
describe 'with no options' do
|
3
6
|
describe 'error_messages' do
|
@@ -135,6 +138,28 @@ shared_examples 'a bootstrap form' do
|
|
135
138
|
@result.should match /class=".*baz/
|
136
139
|
end
|
137
140
|
end
|
141
|
+
|
142
|
+
|
143
|
+
describe 'country_select' do
|
144
|
+
before(:each) do
|
145
|
+
@result = @builder.country_select(:name,[ "United Kingdom", "France", "Germany" ])
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'is wrapped' do
|
149
|
+
@result.should match /^<div class=\"control-group\"><label class=\"control-label\" for=\"item_name\">Name<\/label><div class=\"controls\"><select id=\"item_name\" name=\"item\[name\]\"><option value=\"United Kingdom\">United Kingdom<\/option>/
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'collection_select with html options' do
|
154
|
+
before(:each) do
|
155
|
+
@result = @builder.country_select(:name, [ "United Kingdom", "France", "Germany" ], {}, :class => "baz")
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'uses html options' do
|
159
|
+
@result.should match /class=".*baz/
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
138
163
|
|
139
164
|
end # no options
|
140
165
|
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Seth Vargo
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec-rails
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 3.2.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: country_select
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.1.1
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.1.1
|
78
94
|
- !ruby/object:Gem::Dependency
|
79
95
|
name: guard-rspec
|
80
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -131,13 +147,12 @@ extensions: []
|
|
131
147
|
extra_rdoc_files: []
|
132
148
|
files:
|
133
149
|
- .gitignore
|
134
|
-
- .rspec
|
135
150
|
- .ruby-version
|
136
151
|
- .travis.yml
|
137
152
|
- Gemfile
|
138
153
|
- Guardfile
|
139
154
|
- LICENSE
|
140
|
-
- README.
|
155
|
+
- README.md
|
141
156
|
- Rakefile
|
142
157
|
- bootstrap_forms.gemspec
|
143
158
|
- config/locales/en.yml
|
@@ -166,6 +181,7 @@ files:
|
|
166
181
|
- spec/dummy/app/models/task.rb
|
167
182
|
- spec/dummy/app/views/layouts/application.html.erb
|
168
183
|
- spec/dummy/app/views/projects/new.html.erb
|
184
|
+
- spec/dummy/app/views/projects/new_without_summary_errors.html.erb
|
169
185
|
- spec/dummy/config.ru
|
170
186
|
- spec/dummy/config/application.rb
|
171
187
|
- spec/dummy/config/boot.rb
|
@@ -211,15 +227,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
211
227
|
- - ! '>='
|
212
228
|
- !ruby/object:Gem::Version
|
213
229
|
version: '0'
|
214
|
-
segments:
|
215
|
-
- 0
|
216
|
-
hash: 594779022012185333
|
217
230
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
231
|
none: false
|
219
232
|
requirements:
|
220
|
-
- - ! '
|
233
|
+
- - ! '>='
|
221
234
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
235
|
+
version: '0'
|
223
236
|
requirements: []
|
224
237
|
rubyforge_project:
|
225
238
|
rubygems_version: 1.8.23
|
@@ -242,6 +255,7 @@ test_files:
|
|
242
255
|
- spec/dummy/app/models/task.rb
|
243
256
|
- spec/dummy/app/views/layouts/application.html.erb
|
244
257
|
- spec/dummy/app/views/projects/new.html.erb
|
258
|
+
- spec/dummy/app/views/projects/new_without_summary_errors.html.erb
|
245
259
|
- spec/dummy/config.ru
|
246
260
|
- spec/dummy/config/application.rb
|
247
261
|
- spec/dummy/config/boot.rb
|
@@ -275,3 +289,4 @@ test_files:
|
|
275
289
|
- spec/lib/bootstrap_forms/form_builder_spec.rb
|
276
290
|
- spec/spec_helper.rb
|
277
291
|
- spec/support/shared_context.rb
|
292
|
+
has_rdoc:
|