formatted_form 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +121 -29
- data/Rakefile +29 -10
- data/VERSION +1 -1
- data/app/assets/javascripts/formatted_form.js +12 -0
- data/app/assets/stylesheets/formatted_form.css +0 -0
- data/app/views/formatted_form/_check_box.html.erb +1 -0
- data/app/views/formatted_form/_date_select.html.erb +1 -0
- data/app/views/formatted_form/_datetime_select.html.erb +1 -0
- data/app/views/formatted_form/_element.html.erb +1 -0
- data/app/views/formatted_form/_email_field.html.erb +1 -0
- data/app/views/formatted_form/_file_field.html.erb +1 -0
- data/app/views/formatted_form/_number_field.html.erb +1 -0
- data/app/views/formatted_form/_password_field.html.erb +1 -0
- data/app/views/formatted_form/_phone_field.html.erb +1 -0
- data/app/views/formatted_form/_radio_button.html.erb +1 -0
- data/app/views/formatted_form/_range_field.html.erb +1 -0
- data/app/views/formatted_form/_search_field.html.erb +1 -0
- data/app/views/formatted_form/_select.html.erb +1 -0
- data/app/views/formatted_form/_submit.html.erb +1 -0
- data/app/views/formatted_form/_telephone_field.html.erb +1 -0
- data/app/views/formatted_form/_text_area.html.erb +1 -0
- data/app/views/formatted_form/_text_field.html.erb +1 -0
- data/app/views/formatted_form/_time_select.html.erb +1 -0
- data/app/views/formatted_form/_time_zone_select.html.erb +1 -0
- data/app/views/formatted_form/templates/_choices.html.erb +35 -0
- data/app/views/formatted_form/templates/_field.html.erb +34 -0
- data/formatted_form.gemspec +76 -26
- data/lib/formatted_form/engine.rb +6 -11
- data/lib/formatted_form/form_builder.rb +125 -0
- data/lib/formatted_form/view_helper.rb +49 -0
- data/lib/formatted_form.rb +3 -20
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +65 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +31 -0
- data/test/dummy/config/environments/production.rb +64 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/form_builder_test.rb +391 -0
- data/test/test_helper.rb +47 -0
- metadata +105 -25
- data/app/views/formatted_form/_check_box.html.haml +0 -14
- data/app/views/formatted_form/_default_field.html.haml +0 -17
- data/app/views/formatted_form/_radio_button.html.haml +0 -17
- data/app/views/formatted_form/_submit.html.haml +0 -3
- data/app/views/twitter_bootstrap/_check_box.html.haml +0 -18
- data/app/views/twitter_bootstrap/_default_field.html.haml +0 -10
- data/app/views/twitter_bootstrap/_radio_button.html.haml +0 -24
- data/app/views/twitter_bootstrap/_submit.html.haml +0 -3
- data/lib/formatted_form/builder.rb +0 -178
- data/lib/formatted_form/configuration.rb +0 -16
- data/lib/formatted_form/helper.rb +0 -10
- data/lib/generators/formatted_form/javascripts/javascripts_generator.rb +0 -11
- data/lib/generators/formatted_form/stylesheets/stylesheets_generator.rb +0 -11
- data/templates/javascripts/formatted_form.js +0 -17
- data/templates/stylesheets/formatted_form.sass +0 -121
@@ -0,0 +1,391 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# `raise output_buffer.inspect` if you want to peek inside generated html
|
4
|
+
class FormBuilderTest < ActionView::TestCase
|
5
|
+
|
6
|
+
# -- Form -----------------------------------------------------------------
|
7
|
+
def test_form
|
8
|
+
with_formatted_form_for(@user, :url => ''){|f|}
|
9
|
+
assert_select "form[class='formatted']"
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_form_with_type_inline
|
13
|
+
with_formatted_form_for(@user, :url => '', :type => :inline){|f|}
|
14
|
+
assert_select "form[class='formatted form-inline']"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_form_with_type_horizontal
|
18
|
+
with_formatted_form_for(@user, :url => '', :type => :horizontal){|f|}
|
19
|
+
assert_select "form[class='formatted form-horizontal']"
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_form_with_type_search
|
23
|
+
with_formatted_form_for(@user, :url => '', :type => :search){|f|}
|
24
|
+
assert_select "form[class='formatted form-search']"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_form_overriding_existing_class
|
28
|
+
with_formatted_form_for(@user, :url => '', :type => :inline, :html => {:class => 'custom'}){|f|}
|
29
|
+
assert_select "form[class='custom form-inline']"
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_form_with_type_derived_from_class
|
33
|
+
with_formatted_form_for(@user, :url => '', :type => :inline, :html => {:class => 'form-horizontal'}){|f|}
|
34
|
+
assert_select "form[class='form-horizontal']"
|
35
|
+
end
|
36
|
+
|
37
|
+
# -- Text Field -----------------------------------------------------------
|
38
|
+
def test_text_field
|
39
|
+
with_text_field :name
|
40
|
+
assert_select "div[class='control-group cg-name']" do
|
41
|
+
assert_select "label[for='user_name']", 'Name'
|
42
|
+
assert_select "div[class='controls']" do
|
43
|
+
assert_select "input[type='text'][id='user_name'][name='user[name]']"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_text_field_prepend_append
|
49
|
+
with_text_field :twitter, :prepend => '@', :append => '!'
|
50
|
+
assert_select "div[class='control-group cg-twitter']" do
|
51
|
+
assert_select "label[for='user_twitter']", 'Twitter'
|
52
|
+
assert_select "div[class='controls']" do
|
53
|
+
assert_select "div[class='input-prepend input-append']" do
|
54
|
+
assert_select "span[class='add-on']", '@'
|
55
|
+
assert_select "input[type='text'][id='user_twitter'][name='user[twitter]']"
|
56
|
+
assert_select "span[class='add-on']", '!'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_text_field_prepend_append_html
|
63
|
+
with_text_field :twitter, :prepend_html => '<b>b</b>', :append_html => '<i>i</i>'
|
64
|
+
assert_select "div[class='control-group cg-twitter']" do
|
65
|
+
assert_select "label[for='user_twitter']", 'Twitter'
|
66
|
+
assert_select "div[class='controls']" do
|
67
|
+
assert_select "div[class='input-prepend input-append']" do
|
68
|
+
assert_select "i", 'i'
|
69
|
+
assert_select "input[type='text'][id='user_twitter'][name='user[twitter]']"
|
70
|
+
assert_select "b", 'b'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_text_field_with_help_block
|
77
|
+
with_text_field :name, :help_block => 'Help'
|
78
|
+
assert_select "div[class='control-group cg-name']" do
|
79
|
+
assert_select "div[class='controls']" do
|
80
|
+
assert_select "input[type='text'][id='user_name'][name='user[name]']"
|
81
|
+
assert_select "span[class='help-block']", 'Help'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_text_field_with_errors
|
87
|
+
assert @user.invalid?
|
88
|
+
with_text_field :name
|
89
|
+
assert_select "div[class='control-group cg-name error']" do
|
90
|
+
assert_select "div[class='controls']" do
|
91
|
+
assert_select "input[type='text'][id='user_name'][name='user[name]']"
|
92
|
+
assert_select "span[class='help-inline']", "can't be blank"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_text_field_with_blank_label
|
98
|
+
with_text_field :name, :label => ''
|
99
|
+
assert_select "label[for='user_name']", 0
|
100
|
+
|
101
|
+
with_text_field :name, :label => false
|
102
|
+
assert_select "label[for='user_name']", 0
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_text_field_for_inline_form
|
106
|
+
with_formatted_form_for(@user, :url => '', :type => :inline){|f| f.text_field :name }
|
107
|
+
assert_select "div[class='control-group cg-name']", 0
|
108
|
+
assert_select "input[type='text'][id='user_name'][name='user[name]']"
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_text_field_with_no_builder
|
112
|
+
with_text_field :name, :builder => false
|
113
|
+
assert_select "div[class='control-group cg-name']", 0
|
114
|
+
assert_select "label[for='user_name']", 0
|
115
|
+
end
|
116
|
+
|
117
|
+
# -- Radio Button ---------------------------------------------------------
|
118
|
+
def test_radio_button
|
119
|
+
with_radio_button :role, 'admin'
|
120
|
+
assert_select "div[class='control-group cg-role']" do
|
121
|
+
assert_select "div[class='control-label']" do
|
122
|
+
assert_select "label[for='user_role']", 'Role'
|
123
|
+
end
|
124
|
+
assert_select "div[class='controls']" do
|
125
|
+
assert_select "input[type='radio'][id='user_role_admin'][name='user[role]'][value='admin']"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_radio_button_with_custom_label
|
131
|
+
with_radio_button :role, 'admin', :label => 'Access'
|
132
|
+
assert_select "div[class='control-label']" do
|
133
|
+
assert_select "label[for='user_role']", 'Access'
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_radio_button_with_choices_array
|
138
|
+
with_radio_button :role, ['admin', 'regular']
|
139
|
+
assert_select "div[class='controls']" do
|
140
|
+
assert_select "label[class='radio']", 'admin' do
|
141
|
+
assert_select "input[type='radio'][id='user_role_admin'][name='user[role]'][value='admin']"
|
142
|
+
end
|
143
|
+
assert_select "label[class='radio']", 'regular' do
|
144
|
+
assert_select "input[type='radio'][id='user_role_regular'][name='user[role]'][value='regular']"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_radio_button_with_choices_tuples
|
150
|
+
with_radio_button :role, [['Admin', 1], ['Regular', 2]]
|
151
|
+
assert_select "label[class='radio']", 'Admin' do
|
152
|
+
assert_select "input[type='radio'][id='user_role_1'][name='user[role]'][value='1']"
|
153
|
+
end
|
154
|
+
assert_select "label[class='radio']", 'Regular' do
|
155
|
+
assert_select "input[type='radio'][id='user_role_2'][name='user[role]'][value='2']"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_radio_button_inline
|
160
|
+
with_radio_button :role, ['admin', 'regular'], :class => 'inline'
|
161
|
+
assert_select "label[class='radio inline']", 'admin' do
|
162
|
+
assert_select "input[type='radio'][id='user_role_admin'][name='user[role]'][value='admin']"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
# -- Check Boxes ----------------------------------------------------------
|
167
|
+
def test_check_box
|
168
|
+
with_check_box :colors, {}, 'yes', 'no'
|
169
|
+
assert_select "div[class='control-group cg-colors']" do
|
170
|
+
assert_select "div[class='control-label']" do
|
171
|
+
assert_select "label[for='user_colors']", 'Colors'
|
172
|
+
end
|
173
|
+
assert_select "div[class='controls']" do
|
174
|
+
assert_select "input[type='hidden'][name='user[colors]'][value='no']"
|
175
|
+
assert_select "input[type='checkbox'][id='user_colors'][name='user[colors]'][value='yes']"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_check_box_custom_label
|
181
|
+
with_check_box :colors, :label => 'Kolors'
|
182
|
+
assert_select "div[class='control-label']" do
|
183
|
+
assert_select "label[for='user_colors']", 'Kolors'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_check_box_with_choices_array
|
188
|
+
with_check_box :colors, {}, ['red', 'green']
|
189
|
+
assert_select "div[class='controls']" do
|
190
|
+
assert_select "label[class='checkbox']", 'red' do
|
191
|
+
assert_select "input[type='checkbox'][id='user_colors_red'][name='user[colors][]'][value='red']"
|
192
|
+
end
|
193
|
+
assert_select "label[class='checkbox']", 'green' do
|
194
|
+
assert_select "input[type='checkbox'][id='user_colors_green'][name='user[colors][]'][value='green']"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_check_box_with_choices_and_labels
|
200
|
+
with_check_box :colors, {}, [['Red', 'r'], ['Green', 'g']]
|
201
|
+
assert_select "div[class='controls']" do
|
202
|
+
assert_select "label[class='checkbox']", 'Red' do
|
203
|
+
assert_select "input[type='checkbox'][id='user_colors_r'][name='user[colors][]'][value='r']"
|
204
|
+
end
|
205
|
+
assert_select "label[class='checkbox']", 'Green' do
|
206
|
+
assert_select "input[type='checkbox'][id='user_colors_g'][name='user[colors][]'][value='g']"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_check_box_inline
|
212
|
+
with_check_box :colors, {:class => 'inline'}, ['red', 'green']
|
213
|
+
assert_select "label[class='checkbox inline']" do
|
214
|
+
assert_select "input[type='checkbox'][id='user_colors_red'][name='user[colors][]']"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# -- Element --------------------------------------------------------------
|
219
|
+
def test_element
|
220
|
+
with_element 'Label', 'Content'
|
221
|
+
assert_select "div[class='control-group']" do
|
222
|
+
assert_select "label[class='control-label']", 'Label'
|
223
|
+
assert_select "div[class='controls']", 'Content'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_element_with_block
|
228
|
+
with_element 'Label' do
|
229
|
+
'Content'
|
230
|
+
end
|
231
|
+
assert_select "div[class='control-group']" do
|
232
|
+
assert_select "label[class='control-label']", 'Label'
|
233
|
+
assert_select "div[class='controls']", 'Content'
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_element_with_no_label
|
238
|
+
with_element do
|
239
|
+
'Content'
|
240
|
+
end
|
241
|
+
assert_select "label[class='control-label']", 0
|
242
|
+
assert_select "div[class='controls']", 'Content'
|
243
|
+
end
|
244
|
+
|
245
|
+
# -- Submit ---------------------------------------------------------------
|
246
|
+
def test_submit
|
247
|
+
with_submit
|
248
|
+
assert_select "input[name=commit][value='Create User'][class='btn btn-primary']"
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_submit_with_label
|
252
|
+
with_submit 'Create'
|
253
|
+
assert_select "input[name='commit'][value='Create']"
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_submit_with_css_class
|
257
|
+
with_submit :class => 'btn-danger'
|
258
|
+
assert_select "input[name=commit][class='btn-danger btn']"
|
259
|
+
end
|
260
|
+
|
261
|
+
# -- Others ---------------------------------------------------------------
|
262
|
+
def test_select_field
|
263
|
+
with_select :name, ['Bob']
|
264
|
+
assert_select "div[class='controls']" do
|
265
|
+
assert_select "select[id='user_name'][name='user[name]']" do
|
266
|
+
assert_select "option[value='Bob']", 'Bob'
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_password_field
|
272
|
+
with_password_field :name
|
273
|
+
assert_select "div[class='controls']" do
|
274
|
+
assert_select "input[type='password'][id='user_name'][name='user[name]']"
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
def test_email_field
|
279
|
+
with_email_field :name
|
280
|
+
assert_select "div[class='controls']" do
|
281
|
+
assert_select "input[type='email'][id='user_name'][name='user[name]']"
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def test_telephone_field
|
286
|
+
with_telephone_field :name
|
287
|
+
assert_select "div[class='controls']" do
|
288
|
+
assert_select "input[type='tel'][id='user_name'][name='user[name]']"
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_number_field
|
293
|
+
with_number_field :name
|
294
|
+
assert_select "div[class='controls']" do
|
295
|
+
assert_select "input[type='number'][id='user_name'][name='user[name]']"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def test_text_area
|
300
|
+
with_text_area :name
|
301
|
+
assert_select "div[class='controls']" do
|
302
|
+
assert_select "textarea[id='user_name'][name='user[name]']"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def test_file_field
|
307
|
+
with_file_field :name
|
308
|
+
assert_select "div[class='controls']" do
|
309
|
+
assert_select "input[type='file'][id='user_name'][name='user[name]']"
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_range_field
|
314
|
+
with_range_field :name
|
315
|
+
assert_select "div[class='controls']" do
|
316
|
+
assert_select "input[type='range'][id='user_name'][name='user[name]']"
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_search_field
|
321
|
+
with_search_field :name
|
322
|
+
assert_select "div[class='controls']" do
|
323
|
+
assert_select "input[type='search'][id='user_name'][name='user[name]']"
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_datetime_select
|
328
|
+
with_datetime_select :timestamp
|
329
|
+
assert_select "div[class='controls']" do
|
330
|
+
assert_select "select[id='user_timestamp_1i'][name='user[timestamp(1i)]']"
|
331
|
+
assert_select "select[id='user_timestamp_2i'][name='user[timestamp(2i)]']"
|
332
|
+
assert_select "select[id='user_timestamp_3i'][name='user[timestamp(3i)]']"
|
333
|
+
assert_select "select[id='user_timestamp_4i'][name='user[timestamp(4i)]']"
|
334
|
+
assert_select "select[id='user_timestamp_5i'][name='user[timestamp(5i)]']"
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_date_select
|
339
|
+
with_date_select :timestamp
|
340
|
+
assert_select "div[class='controls']" do
|
341
|
+
assert_select "select[id='user_timestamp_1i'][name='user[timestamp(1i)]']"
|
342
|
+
assert_select "select[id='user_timestamp_2i'][name='user[timestamp(2i)]']"
|
343
|
+
assert_select "select[id='user_timestamp_3i'][name='user[timestamp(3i)]']"
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
def test_time_select
|
348
|
+
with_time_select :timestamp
|
349
|
+
assert_select "div[class='controls']" do
|
350
|
+
assert_select "input[type='hidden'][id='user_timestamp_1i'][name='user[timestamp(1i)]']"
|
351
|
+
assert_select "input[type='hidden'][id='user_timestamp_2i'][name='user[timestamp(2i)]']"
|
352
|
+
assert_select "input[type='hidden'][id='user_timestamp_3i'][name='user[timestamp(3i)]']"
|
353
|
+
assert_select "select[id='user_timestamp_4i'][name='user[timestamp(4i)]']"
|
354
|
+
assert_select "select[id='user_timestamp_5i'][name='user[timestamp(5i)]']"
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_time_zone_select
|
359
|
+
with_time_zone_select :timestamp
|
360
|
+
assert_select "div[class='controls']" do
|
361
|
+
assert_select "select[id='user_timestamp'][name='user[timestamp]']"
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
# -- Conditional content tag ----------------------------------------------
|
366
|
+
def test_content_tag_if_true
|
367
|
+
concat content_tag_if(true, :div, 'test', :class => 'test')
|
368
|
+
assert_equal "<div class=\"test\">test</div>", output_buffer
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_content_tag_if_false
|
372
|
+
concat content_tag_if(false, :div, 'test', :class => 'test')
|
373
|
+
assert_equal 'test', output_buffer
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_content_tag_if_with_block_if_true
|
377
|
+
concat(content_tag_if(true, :div, :class => 'test'){ 'test' })
|
378
|
+
assert_equal "<div class=\"test\">test</div>", output_buffer
|
379
|
+
end
|
380
|
+
|
381
|
+
def test_content_tag_if_with_block_if_false
|
382
|
+
concat(content_tag_if(false, :div, :class => 'test'){ 'test' })
|
383
|
+
assert_equal 'test', output_buffer
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_content_tag_unless
|
387
|
+
concat content_tag_unless(false, :div, 'test', :class => 'test')
|
388
|
+
assert_equal "<div class=\"test\">test</div>", output_buffer
|
389
|
+
end
|
390
|
+
|
391
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
# Load support files
|
10
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
11
|
+
|
12
|
+
class User
|
13
|
+
extend ActiveModel::Naming
|
14
|
+
include ActiveModel::Validations
|
15
|
+
include ActiveModel::Conversion
|
16
|
+
|
17
|
+
attr_accessor :id, :name, :twitter, :role, :colors, :timestamp
|
18
|
+
|
19
|
+
validates :name, :presence => true
|
20
|
+
|
21
|
+
def persisted?
|
22
|
+
false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ActionView::TestCase
|
27
|
+
include FormattedForm::ViewHelper
|
28
|
+
|
29
|
+
setup :load_user
|
30
|
+
|
31
|
+
def load_user
|
32
|
+
@user = User.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def with_formatted_form_for(*args, &block)
|
36
|
+
concat formatted_form_for(*args, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Helper method to handle things like `with_text_field`, `with_submit`, etc
|
40
|
+
def method_missing(method_name, *args, &block)
|
41
|
+
if method_name =~ /^with_(\w+)/
|
42
|
+
with_formatted_form_for(@user, :url => ''){ |f| f.send($1, *args, &block) }
|
43
|
+
else
|
44
|
+
super(method_name, *args, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,48 +1,124 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formatted_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jack Neto
|
9
|
+
- Oleg Khabarov
|
10
|
+
- The Working Group Inc.
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
|
14
|
-
|
14
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rails
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.1.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 3.1.0
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: jeweler
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
15
48
|
description: ''
|
16
|
-
email: jack@
|
49
|
+
email: jack@twg.ca
|
17
50
|
executables: []
|
18
51
|
extensions: []
|
19
52
|
extra_rdoc_files:
|
20
|
-
- LICENSE
|
53
|
+
- LICENSE
|
21
54
|
- README.md
|
22
55
|
files:
|
23
|
-
-
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE
|
24
58
|
- README.md
|
25
59
|
- Rakefile
|
26
60
|
- VERSION
|
27
|
-
- app/
|
28
|
-
- app/
|
29
|
-
- app/views/formatted_form/
|
30
|
-
- app/views/formatted_form/
|
31
|
-
- app/views/
|
32
|
-
- app/views/
|
33
|
-
- app/views/
|
34
|
-
- app/views/
|
61
|
+
- app/assets/javascripts/formatted_form.js
|
62
|
+
- app/assets/stylesheets/formatted_form.css
|
63
|
+
- app/views/formatted_form/_check_box.html.erb
|
64
|
+
- app/views/formatted_form/_date_select.html.erb
|
65
|
+
- app/views/formatted_form/_datetime_select.html.erb
|
66
|
+
- app/views/formatted_form/_element.html.erb
|
67
|
+
- app/views/formatted_form/_email_field.html.erb
|
68
|
+
- app/views/formatted_form/_file_field.html.erb
|
69
|
+
- app/views/formatted_form/_number_field.html.erb
|
70
|
+
- app/views/formatted_form/_password_field.html.erb
|
71
|
+
- app/views/formatted_form/_phone_field.html.erb
|
72
|
+
- app/views/formatted_form/_radio_button.html.erb
|
73
|
+
- app/views/formatted_form/_range_field.html.erb
|
74
|
+
- app/views/formatted_form/_search_field.html.erb
|
75
|
+
- app/views/formatted_form/_select.html.erb
|
76
|
+
- app/views/formatted_form/_submit.html.erb
|
77
|
+
- app/views/formatted_form/_telephone_field.html.erb
|
78
|
+
- app/views/formatted_form/_text_area.html.erb
|
79
|
+
- app/views/formatted_form/_text_field.html.erb
|
80
|
+
- app/views/formatted_form/_time_select.html.erb
|
81
|
+
- app/views/formatted_form/_time_zone_select.html.erb
|
82
|
+
- app/views/formatted_form/templates/_choices.html.erb
|
83
|
+
- app/views/formatted_form/templates/_field.html.erb
|
35
84
|
- formatted_form.gemspec
|
36
85
|
- lib/formatted_form.rb
|
37
|
-
- lib/formatted_form/builder.rb
|
38
|
-
- lib/formatted_form/configuration.rb
|
39
86
|
- lib/formatted_form/engine.rb
|
40
|
-
- lib/formatted_form/
|
41
|
-
- lib/
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
45
|
-
|
87
|
+
- lib/formatted_form/form_builder.rb
|
88
|
+
- lib/formatted_form/view_helper.rb
|
89
|
+
- test/dummy/README.rdoc
|
90
|
+
- test/dummy/Rakefile
|
91
|
+
- test/dummy/app/assets/javascripts/application.js
|
92
|
+
- test/dummy/app/assets/stylesheets/application.css
|
93
|
+
- test/dummy/app/controllers/application_controller.rb
|
94
|
+
- test/dummy/app/helpers/application_helper.rb
|
95
|
+
- test/dummy/app/mailers/.gitkeep
|
96
|
+
- test/dummy/app/models/.gitkeep
|
97
|
+
- test/dummy/app/views/layouts/application.html.erb
|
98
|
+
- test/dummy/config.ru
|
99
|
+
- test/dummy/config/application.rb
|
100
|
+
- test/dummy/config/boot.rb
|
101
|
+
- test/dummy/config/environment.rb
|
102
|
+
- test/dummy/config/environments/development.rb
|
103
|
+
- test/dummy/config/environments/production.rb
|
104
|
+
- test/dummy/config/environments/test.rb
|
105
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
106
|
+
- test/dummy/config/initializers/inflections.rb
|
107
|
+
- test/dummy/config/initializers/mime_types.rb
|
108
|
+
- test/dummy/config/initializers/secret_token.rb
|
109
|
+
- test/dummy/config/initializers/session_store.rb
|
110
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
111
|
+
- test/dummy/config/locales/en.yml
|
112
|
+
- test/dummy/config/routes.rb
|
113
|
+
- test/dummy/lib/assets/.gitkeep
|
114
|
+
- test/dummy/log/.gitkeep
|
115
|
+
- test/dummy/public/404.html
|
116
|
+
- test/dummy/public/422.html
|
117
|
+
- test/dummy/public/500.html
|
118
|
+
- test/dummy/public/favicon.ico
|
119
|
+
- test/dummy/script/rails
|
120
|
+
- test/form_builder_test.rb
|
121
|
+
- test/test_helper.rb
|
46
122
|
homepage: http://github.com/twg/formatted_form
|
47
123
|
licenses:
|
48
124
|
- MIT
|
@@ -56,6 +132,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
132
|
- - ! '>='
|
57
133
|
- !ruby/object:Gem::Version
|
58
134
|
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -4409253828031207642
|
59
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
139
|
none: false
|
61
140
|
requirements:
|
@@ -64,8 +143,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
143
|
version: '0'
|
65
144
|
requirements: []
|
66
145
|
rubyforge_project:
|
67
|
-
rubygems_version: 1.
|
146
|
+
rubygems_version: 1.8.23
|
68
147
|
signing_key:
|
69
148
|
specification_version: 3
|
70
|
-
summary: A Rails form builder
|
149
|
+
summary: A Rails form builder that generates Twitter Bootstrap markup and helps keep
|
150
|
+
your code clean
|
71
151
|
test_files: []
|
@@ -1,14 +0,0 @@
|
|
1
|
-
.form_element{:class => "#{field_name}"}
|
2
|
-
|
3
|
-
.value
|
4
|
-
= field
|
5
|
-
= builder.label(method, label_text)
|
6
|
-
|
7
|
-
- if required
|
8
|
-
%span.required *
|
9
|
-
|
10
|
-
- if error_messages.present?
|
11
|
-
.errors= error_messages
|
12
|
-
|
13
|
-
- if description.present?
|
14
|
-
.description= description
|
@@ -1,17 +0,0 @@
|
|
1
|
-
.form_element{:class => "#{field_name}"}
|
2
|
-
.label
|
3
|
-
= builder.label(method, label_text)
|
4
|
-
- if required
|
5
|
-
%span.required *
|
6
|
-
|
7
|
-
.value
|
8
|
-
= before_text
|
9
|
-
= field
|
10
|
-
= after_text
|
11
|
-
|
12
|
-
- if description.present?
|
13
|
-
.description= description
|
14
|
-
|
15
|
-
- if error_messages.present?
|
16
|
-
.errors= error_messages
|
17
|
-
|
@@ -1,17 +0,0 @@
|
|
1
|
-
.form_element{:class => "#{field_name}"}
|
2
|
-
.label
|
3
|
-
= label_text
|
4
|
-
- if required
|
5
|
-
%span.required *
|
6
|
-
|
7
|
-
.value
|
8
|
-
- choices.each do |choice|
|
9
|
-
.option
|
10
|
-
= choice[:field]
|
11
|
-
%label{:for => choice[:label_for]}= choice[:label]
|
12
|
-
|
13
|
-
- if error_messages.present?
|
14
|
-
.errors= error_messages
|
15
|
-
|
16
|
-
- if description.present?
|
17
|
-
.description= description
|
@@ -1,18 +0,0 @@
|
|
1
|
-
.clearfix{:class => ('error' if error_messages.present?)}
|
2
|
-
|
3
|
-
.input
|
4
|
-
%ul.inputs-list
|
5
|
-
%li
|
6
|
-
%label
|
7
|
-
= field
|
8
|
-
%span
|
9
|
-
= label_text
|
10
|
-
- if required
|
11
|
-
%span.required *
|
12
|
-
|
13
|
-
- if error_messages.present?
|
14
|
-
%span.help-inline= error_messages
|
15
|
-
- if description.present?
|
16
|
-
%span.help-block= description
|
17
|
-
|
18
|
-
|