merb_helpers 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/lib/merb_helpers/form/builder.rb +160 -151
- data/lib/merb_helpers/form/helpers.rb +80 -79
- data/lib/merb_helpers/form_helpers.rb +13 -3
- metadata +3 -3
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ GEM_EMAIL = "ykatz@engineyard.com"
|
|
18
18
|
|
19
19
|
GEM_NAME = "merb_helpers"
|
20
20
|
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
|
21
|
-
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.
|
21
|
+
GEM_VERSION = (Merb::MORE_VERSION rescue "0.9.7") + PKG_BUILD
|
22
22
|
|
23
23
|
RELEASE_NAME = "REL #{GEM_VERSION}"
|
24
24
|
|
@@ -36,7 +36,7 @@ spec = Gem::Specification.new do |s|
|
|
36
36
|
s.author = GEM_AUTHOR
|
37
37
|
s.email = GEM_EMAIL
|
38
38
|
s.homepage = PROJECT_URL
|
39
|
-
s.add_dependency('merb-core', '>= 0.9.
|
39
|
+
s.add_dependency('merb-core', '>= 0.9.7')
|
40
40
|
s.require_path = 'lib'
|
41
41
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,specs}/**/*")
|
42
42
|
end
|
@@ -14,19 +14,117 @@ module Merb::Helpers::Form::Builder
|
|
14
14
|
@origin.concat(@origin.capture(&blk), blk.binding)
|
15
15
|
end
|
16
16
|
|
17
|
+
def form(attrs = {}, &blk)
|
18
|
+
captured = @origin.capture(&blk)
|
19
|
+
fake_method_tag = process_form_attrs(attrs)
|
20
|
+
tag(:form, fake_method_tag + captured, attrs)
|
21
|
+
end
|
22
|
+
|
17
23
|
def fieldset(attrs, &blk)
|
18
24
|
legend = (l_attr = attrs.delete(:legend)) ? tag(:legend, l_attr) : ""
|
19
25
|
tag(:fieldset, legend + @origin.capture(&blk), attrs)
|
20
26
|
# @origin.concat(contents, blk.binding)
|
21
27
|
end
|
22
28
|
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
%w(text password hidden file).each do |kind|
|
30
|
+
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
31
|
+
def bound_#{kind}_field(method, attrs = {})
|
32
|
+
name = control_name(method)
|
33
|
+
update_bound_controls(method, attrs, "#{kind}")
|
34
|
+
unbound_#{kind}_field({:name => name, :value => @obj.send(method)}.merge(attrs))
|
35
|
+
end
|
26
36
|
|
27
|
-
|
37
|
+
def unbound_#{kind}_field(attrs)
|
38
|
+
update_unbound_controls(attrs, "#{kind}")
|
39
|
+
self_closing_tag(:input, {:type => "#{kind}"}.merge(attrs))
|
40
|
+
end
|
41
|
+
RUBY
|
42
|
+
end
|
43
|
+
|
44
|
+
def bound_check_box(method, attrs = {})
|
45
|
+
name = control_name(method)
|
46
|
+
update_bound_controls(method, attrs, "checkbox")
|
47
|
+
unbound_check_box({:name => name}.merge(attrs))
|
48
|
+
end
|
49
|
+
|
50
|
+
def unbound_check_box(attrs)
|
51
|
+
update_unbound_controls(attrs, "checkbox")
|
52
|
+
if attrs.delete(:boolean)
|
53
|
+
on, off = attrs.delete(:on), attrs.delete(:off)
|
54
|
+
unbound_hidden_field(:name => attrs[:name], :value => off) <<
|
55
|
+
self_closing_tag(:input, {:type => "checkbox", :value => on}.merge(attrs))
|
56
|
+
else
|
57
|
+
self_closing_tag(:input, {:type => "checkbox"}.merge(attrs))
|
58
|
+
end
|
28
59
|
end
|
29
60
|
|
61
|
+
def bound_radio_button(method, attrs = {})
|
62
|
+
name = control_name(method)
|
63
|
+
update_bound_controls(method, attrs, "radio")
|
64
|
+
unbound_radio_button({:name => name, :value => @obj.send(method)}.merge(attrs))
|
65
|
+
end
|
66
|
+
|
67
|
+
def unbound_radio_button(attrs)
|
68
|
+
update_unbound_controls(attrs, "radio")
|
69
|
+
self_closing_tag(:input, {:type => "radio"}.merge(attrs))
|
70
|
+
end
|
71
|
+
|
72
|
+
def bound_radio_group(method, arr)
|
73
|
+
val = @obj.send(method)
|
74
|
+
arr.map do |attrs|
|
75
|
+
attrs = {:value => attrs} unless attrs.is_a?(Hash)
|
76
|
+
attrs[:checked] ||= (val == attrs[:value])
|
77
|
+
radio_group_item(method, attrs)
|
78
|
+
end.join
|
79
|
+
end
|
80
|
+
|
81
|
+
def unbound_radio_group(arr, attrs = {})
|
82
|
+
arr.map do |ind_attrs|
|
83
|
+
ind_attrs = {:value => ind_attrs} unless ind_attrs.is_a?(Hash)
|
84
|
+
joined = attrs.merge(ind_attrs)
|
85
|
+
joined.merge!(:label => joined[:label] || joined[:value])
|
86
|
+
unbound_radio_button(joined)
|
87
|
+
end.join
|
88
|
+
end
|
89
|
+
|
90
|
+
def bound_select(method, attrs = {})
|
91
|
+
name = control_name(method)
|
92
|
+
update_bound_controls(method, attrs, "select")
|
93
|
+
unbound_select({:name => name}.merge(attrs))
|
94
|
+
end
|
95
|
+
|
96
|
+
def unbound_select(attrs = {})
|
97
|
+
update_unbound_controls(attrs, "select")
|
98
|
+
attrs[:name] << "[]" if attrs[:multiple] && !(attrs[:name] =~ /\[\]$/)
|
99
|
+
tag(:select, options_for(attrs), attrs)
|
100
|
+
end
|
101
|
+
|
102
|
+
def bound_text_area(method, attrs = {})
|
103
|
+
name = "#{@name}[#{method}]"
|
104
|
+
update_bound_controls(method, attrs, "text_area")
|
105
|
+
unbound_text_area(@obj.send(method), {:name => name}.merge(attrs))
|
106
|
+
end
|
107
|
+
|
108
|
+
def unbound_text_area(contents, attrs)
|
109
|
+
update_unbound_controls(attrs, "text_area")
|
110
|
+
tag(:textarea, contents, attrs)
|
111
|
+
end
|
112
|
+
|
113
|
+
def button(contents, attrs)
|
114
|
+
update_unbound_controls(attrs, "button")
|
115
|
+
tag(:button, contents, attrs)
|
116
|
+
end
|
117
|
+
|
118
|
+
def submit(value, attrs)
|
119
|
+
attrs[:type] ||= "submit"
|
120
|
+
attrs[:name] ||= "submit"
|
121
|
+
attrs[:value] ||= value
|
122
|
+
update_unbound_controls(attrs, "submit")
|
123
|
+
self_closing_tag(:input, attrs)
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
30
128
|
def process_form_attrs(attrs)
|
31
129
|
method = attrs[:method]
|
32
130
|
|
@@ -46,10 +144,6 @@ module Merb::Helpers::Form::Builder
|
|
46
144
|
self_closing_tag(:input, :type => "hidden", :name => "_method", :value => method)
|
47
145
|
end
|
48
146
|
|
49
|
-
def add_css_class(attrs, new_class)
|
50
|
-
attrs[:class] = attrs[:class] ? "#{attrs[:class]} #{new_class}" : new_class
|
51
|
-
end
|
52
|
-
|
53
147
|
def update_bound_controls(method, attrs, type)
|
54
148
|
case type
|
55
149
|
when "checkbox"
|
@@ -59,12 +153,6 @@ module Merb::Helpers::Form::Builder
|
|
59
153
|
end
|
60
154
|
end
|
61
155
|
|
62
|
-
def update_bound_select(method, attrs)
|
63
|
-
attrs[:value_method] ||= method
|
64
|
-
attrs[:text_method] ||= attrs[:value_method] || :to_s
|
65
|
-
attrs[:selected] ||= @obj.send(attrs[:value_method])
|
66
|
-
end
|
67
|
-
|
68
156
|
def update_bound_check_box(method, attrs)
|
69
157
|
raise ArgumentError, ":value can't be used with a bound_check_box" if attrs.has_key?(:value)
|
70
158
|
|
@@ -74,6 +162,12 @@ module Merb::Helpers::Form::Builder
|
|
74
162
|
attrs[:checked] = attrs.key?(:on) ? val == attrs[:on] : considered_true?(val)
|
75
163
|
end
|
76
164
|
|
165
|
+
def update_bound_select(method, attrs)
|
166
|
+
attrs[:value_method] ||= method
|
167
|
+
attrs[:text_method] ||= attrs[:value_method] || :to_s
|
168
|
+
attrs[:selected] ||= @obj.send(attrs[:value_method])
|
169
|
+
end
|
170
|
+
|
77
171
|
def update_unbound_controls(attrs, type)
|
78
172
|
case type
|
79
173
|
when "checkbox"
|
@@ -104,109 +198,6 @@ module Merb::Helpers::Form::Builder
|
|
104
198
|
attrs[:checked] = "checked" if attrs.delete(:checked)
|
105
199
|
end
|
106
200
|
|
107
|
-
def bound_check_box(method, attrs = {})
|
108
|
-
name = control_name(method)
|
109
|
-
update_bound_controls(method, attrs, "checkbox")
|
110
|
-
unbound_check_box({:name => name}.merge(attrs))
|
111
|
-
end
|
112
|
-
|
113
|
-
def unbound_check_box(attrs)
|
114
|
-
update_unbound_controls(attrs, "checkbox")
|
115
|
-
if attrs.delete(:boolean)
|
116
|
-
on, off = attrs.delete(:on), attrs.delete(:off)
|
117
|
-
unbound_hidden_field(:name => attrs[:name], :value => off) <<
|
118
|
-
self_closing_tag(:input, {:type => "checkbox", :value => on}.merge(attrs))
|
119
|
-
else
|
120
|
-
self_closing_tag(:input, {:type => "checkbox"}.merge(attrs))
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
%w(text password hidden file).each do |kind|
|
125
|
-
self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
126
|
-
def unbound_#{kind}_field(attrs)
|
127
|
-
update_unbound_controls(attrs, "#{kind}")
|
128
|
-
self_closing_tag(:input, {:type => "#{kind}"}.merge(attrs))
|
129
|
-
end
|
130
|
-
|
131
|
-
def bound_#{kind}_field(method, attrs = {})
|
132
|
-
name = control_name(method)
|
133
|
-
update_bound_controls(method, attrs, "#{kind}")
|
134
|
-
unbound_#{kind}_field({:name => name, :value => @obj.send(method)}.merge(attrs))
|
135
|
-
end
|
136
|
-
RUBY
|
137
|
-
end
|
138
|
-
|
139
|
-
def bound_radio_button(method, attrs = {})
|
140
|
-
name = control_name(method)
|
141
|
-
update_bound_controls(method, attrs, "radio")
|
142
|
-
unbound_radio_button({:name => name, :value => @obj.send(method)}.merge(attrs))
|
143
|
-
end
|
144
|
-
|
145
|
-
def unbound_radio_button(attrs)
|
146
|
-
update_unbound_controls(attrs, "radio")
|
147
|
-
self_closing_tag(:input, {:type => "radio"}.merge(attrs))
|
148
|
-
end
|
149
|
-
|
150
|
-
def button(contents, attrs)
|
151
|
-
update_unbound_controls(attrs, "button")
|
152
|
-
tag(:button, contents, attrs)
|
153
|
-
end
|
154
|
-
|
155
|
-
def submit(value, attrs)
|
156
|
-
attrs[:type] ||= "submit"
|
157
|
-
attrs[:name] ||= "submit"
|
158
|
-
attrs[:value] ||= value
|
159
|
-
update_unbound_controls(attrs, "submit")
|
160
|
-
self_closing_tag(:input, attrs)
|
161
|
-
end
|
162
|
-
|
163
|
-
def bound_select(method, attrs = {})
|
164
|
-
name = control_name(method)
|
165
|
-
update_bound_controls(method, attrs, "select")
|
166
|
-
unbound_select({:name => name}.merge(attrs))
|
167
|
-
end
|
168
|
-
|
169
|
-
def unbound_select(attrs = {})
|
170
|
-
update_unbound_controls(attrs, "select")
|
171
|
-
attrs[:name] << "[]" if attrs[:multiple] && !(attrs[:name] =~ /\[\]$/)
|
172
|
-
tag(:select, options_for(attrs), attrs)
|
173
|
-
end
|
174
|
-
|
175
|
-
def bound_radio_group(method, arr)
|
176
|
-
val = @obj.send(method)
|
177
|
-
arr.map do |attrs|
|
178
|
-
attrs = {:value => attrs} unless attrs.is_a?(Hash)
|
179
|
-
attrs[:checked] ||= (val == attrs[:value])
|
180
|
-
radio_group_item(method, attrs)
|
181
|
-
end.join
|
182
|
-
end
|
183
|
-
|
184
|
-
def unbound_radio_group(arr, attrs = {})
|
185
|
-
arr.map do |ind_attrs|
|
186
|
-
ind_attrs = {:value => ind_attrs} unless ind_attrs.is_a?(Hash)
|
187
|
-
joined = attrs.merge(ind_attrs)
|
188
|
-
joined.merge!(:label => joined[:label] || joined[:value])
|
189
|
-
unbound_radio_button(joined)
|
190
|
-
end.join
|
191
|
-
end
|
192
|
-
|
193
|
-
def unbound_text_area(contents, attrs)
|
194
|
-
update_unbound_controls(attrs, "text_area")
|
195
|
-
tag(:textarea, contents, attrs)
|
196
|
-
end
|
197
|
-
|
198
|
-
def bound_text_area(method, attrs = {})
|
199
|
-
name = "#{@name}[#{method}]"
|
200
|
-
update_bound_controls(method, attrs, "text_area")
|
201
|
-
unbound_text_area(@obj.send(method), {:name => name}.merge(attrs))
|
202
|
-
end
|
203
|
-
|
204
|
-
private
|
205
|
-
|
206
|
-
def control_name(method)
|
207
|
-
"#{@name}[#{method}]"
|
208
|
-
end
|
209
|
-
|
210
201
|
# Accepts a collection (hash, array, enumerable, your type) and returns a string of option tags.
|
211
202
|
# Given a collection where the elements respond to first and last (such as a two-element array),
|
212
203
|
# the "lasts" serve as option values and the "firsts" as option text. Hashes are turned into
|
@@ -258,7 +249,11 @@ module Merb::Helpers::Form::Builder
|
|
258
249
|
value = item.is_a?(String) ? item : item.send(value_meth)
|
259
250
|
|
260
251
|
option_attrs = {:value => value}
|
261
|
-
|
252
|
+
if sel.is_a?(Array)
|
253
|
+
option_attrs.merge!(:selected => "selected") if value.in? sel
|
254
|
+
else
|
255
|
+
option_attrs.merge!(:selected => "selected") if value == sel
|
256
|
+
end
|
262
257
|
tag(:option, text, option_attrs)
|
263
258
|
end).join
|
264
259
|
end
|
@@ -271,22 +266,17 @@ module Merb::Helpers::Form::Builder
|
|
271
266
|
def considered_true?(value)
|
272
267
|
value && value != "0" && value != 0
|
273
268
|
end
|
274
|
-
end
|
275
269
|
|
276
|
-
|
277
|
-
|
278
|
-
attrs.merge!(:id => "#{@name}_#{method}") unless attrs[:id]
|
279
|
-
super
|
270
|
+
def control_name(method)
|
271
|
+
"#{@name}[#{method}]"
|
280
272
|
end
|
281
273
|
|
282
|
-
def
|
283
|
-
|
284
|
-
when "text", "radio", "password", "hidden", "checkbox", "file"
|
285
|
-
add_css_class(attrs, type)
|
286
|
-
end
|
287
|
-
super
|
274
|
+
def add_css_class(attrs, new_class)
|
275
|
+
attrs[:class] = attrs[:class] ? "#{attrs[:class]} #{new_class}" : new_class
|
288
276
|
end
|
277
|
+
end
|
289
278
|
|
279
|
+
class Form < Base
|
290
280
|
def label(contents, attrs = {})
|
291
281
|
if contents.is_a?(Hash)
|
292
282
|
attrs = contents
|
@@ -308,11 +298,22 @@ module Merb::Helpers::Form::Builder
|
|
308
298
|
RUBY
|
309
299
|
end
|
310
300
|
|
311
|
-
def
|
312
|
-
label(attrs)
|
301
|
+
def unbound_check_box(attrs = {})
|
302
|
+
label_text = label(attrs)
|
303
|
+
super + label_text
|
313
304
|
end
|
314
305
|
|
315
|
-
def
|
306
|
+
def unbound_hidden_field(attrs = {})
|
307
|
+
attrs.delete(:label)
|
308
|
+
super
|
309
|
+
end
|
310
|
+
|
311
|
+
def unbound_radio_button(attrs = {})
|
312
|
+
label_text = label(attrs)
|
313
|
+
super + label_text
|
314
|
+
end
|
315
|
+
|
316
|
+
def unbound_select(attrs = {})
|
316
317
|
label(attrs) + super
|
317
318
|
end
|
318
319
|
|
@@ -320,18 +321,27 @@ module Merb::Helpers::Form::Builder
|
|
320
321
|
label(attrs) + super
|
321
322
|
end
|
322
323
|
|
323
|
-
def
|
324
|
+
def button(contents, attrs = {})
|
324
325
|
label(attrs) + super
|
325
326
|
end
|
326
327
|
|
327
|
-
def
|
328
|
-
|
329
|
-
super + label_text
|
328
|
+
def submit(value, attrs = {})
|
329
|
+
label(attrs) + super
|
330
330
|
end
|
331
331
|
|
332
|
-
|
333
|
-
|
334
|
-
|
332
|
+
private
|
333
|
+
|
334
|
+
def update_bound_controls(method, attrs, type)
|
335
|
+
attrs.merge!(:id => "#{@name}_#{method}") unless attrs[:id]
|
336
|
+
super
|
337
|
+
end
|
338
|
+
|
339
|
+
def update_unbound_controls(attrs, type)
|
340
|
+
case type
|
341
|
+
when "text", "radio", "password", "hidden", "checkbox", "file"
|
342
|
+
add_css_class(attrs, type)
|
343
|
+
end
|
344
|
+
super
|
335
345
|
end
|
336
346
|
|
337
347
|
def radio_group_item(method, attrs)
|
@@ -342,21 +352,9 @@ module Merb::Helpers::Form::Builder
|
|
342
352
|
attrs.merge!(:label => attrs[:label] || attrs[:value])
|
343
353
|
super
|
344
354
|
end
|
345
|
-
|
346
|
-
def unbound_hidden_field(attrs = {})
|
347
|
-
attrs.delete(:label)
|
348
|
-
super
|
349
|
-
end
|
350
355
|
end
|
351
356
|
|
352
357
|
module Errorifier
|
353
|
-
def update_bound_controls(method, attrs, type)
|
354
|
-
if @obj.errors.on(method.to_sym)
|
355
|
-
add_css_class(attrs, "error")
|
356
|
-
end
|
357
|
-
super
|
358
|
-
end
|
359
|
-
|
360
358
|
def error_messages_for(obj, error_class, build_li, header, before)
|
361
359
|
obj ||= @obj
|
362
360
|
return "" unless obj.respond_to?(:errors)
|
@@ -371,6 +369,15 @@ module Merb::Helpers::Form::Builder
|
|
371
369
|
errors.each {|err| markup << (build_li % (sequel ? err : err.join(" ")))}
|
372
370
|
markup << %Q{</ul></div>}
|
373
371
|
end
|
372
|
+
|
373
|
+
private
|
374
|
+
|
375
|
+
def update_bound_controls(method, attrs, type)
|
376
|
+
if @obj.errors.on(method.to_sym)
|
377
|
+
add_css_class(attrs, "error")
|
378
|
+
end
|
379
|
+
super
|
380
|
+
end
|
374
381
|
end
|
375
382
|
|
376
383
|
class FormWithErrors < Form
|
@@ -378,6 +385,8 @@ module Merb::Helpers::Form::Builder
|
|
378
385
|
end
|
379
386
|
|
380
387
|
module Resourceful
|
388
|
+
private
|
389
|
+
|
381
390
|
def process_form_attrs(attrs)
|
382
391
|
attrs[:action] ||= @origin.url(@name, @obj) if @origin
|
383
392
|
super
|
@@ -3,8 +3,9 @@
|
|
3
3
|
module Merb::Helpers::Form
|
4
4
|
|
5
5
|
def _singleton_form_context
|
6
|
+
self._default_builder = Merb::Helpers::Form::Builder::ResourcefulFormWithErrors unless self._default_builder
|
6
7
|
@_singleton_form_context ||=
|
7
|
-
self.
|
8
|
+
self._default_builder.new(nil, nil, self)
|
8
9
|
end
|
9
10
|
|
10
11
|
def form_contexts
|
@@ -22,7 +23,7 @@ module Merb::Helpers::Form
|
|
22
23
|
ivar, name = name, name.class.to_s.snake_case
|
23
24
|
end
|
24
25
|
builder ||= current_form_context.class if current_form_context
|
25
|
-
(builder || self.
|
26
|
+
(builder || self._default_builder).new(ivar, name, self)
|
26
27
|
end
|
27
28
|
|
28
29
|
def with_form_context(name, builder)
|
@@ -149,22 +150,31 @@ module Merb::Helpers::Form
|
|
149
150
|
end
|
150
151
|
end
|
151
152
|
|
152
|
-
# Provides a generic HTML
|
153
|
+
# Provides a generic HTML checkbox input tag.
|
154
|
+
# There are two ways this tag can be generated, based on the
|
155
|
+
# option :boolean. If not set to true, a "magic" input is generated.
|
156
|
+
# Otherwise, an input is created that can be easily used for passing
|
157
|
+
# an array of values to the application.
|
153
158
|
#
|
154
159
|
# ==== Parameters
|
155
|
-
#
|
160
|
+
# method<Symbol>:: Resource attribute
|
161
|
+
# attrs<Hash>:: HTML attributes and options
|
156
162
|
#
|
157
163
|
# ==== Returns
|
158
164
|
# String:: HTML
|
159
165
|
#
|
160
166
|
# ==== Example
|
161
|
-
# <%=
|
162
|
-
# =>
|
163
|
-
|
164
|
-
|
165
|
-
|
167
|
+
# <%= check_box :name => "is_activated", :value => "1" %>
|
168
|
+
# <%= check_box :name => "choices[]", :boolean => false, :value => "dog" %>
|
169
|
+
# <%= check_box :name => "choices[]", :boolean => false, :value => "cat" %>
|
170
|
+
# <%= check_box :name => "choices[]", :boolean => false, :value => "weasle" %>
|
171
|
+
#
|
172
|
+
# Used with a model:
|
173
|
+
#
|
174
|
+
# <%= check_box :is_activated, :label => "Activated?" %>
|
175
|
+
def check_box; end
|
166
176
|
|
167
|
-
# Provides a HTML
|
177
|
+
# Provides a HTML file input
|
168
178
|
#
|
169
179
|
# ==== Parameters
|
170
180
|
# name<Symbol>:: Model or Resource
|
@@ -174,17 +184,14 @@ module Merb::Helpers::Form
|
|
174
184
|
# String:: HTML
|
175
185
|
#
|
176
186
|
# ==== Example
|
177
|
-
# <%=
|
178
|
-
# # => <label for="fav_color">Your Favorite Color</label><input type="text" id="fav_color" name="fav_color" />
|
187
|
+
# <%= file_field :name => "file", :label => "File" %>
|
179
188
|
#
|
180
189
|
# Used with a model:
|
181
190
|
#
|
182
|
-
# <%=
|
183
|
-
|
184
|
-
# <% end =%>
|
185
|
-
def text_field; end
|
191
|
+
# <%= file_field :file, :label => "Choose a file" %>
|
192
|
+
def file_field; end
|
186
193
|
|
187
|
-
# Provides a HTML
|
194
|
+
# Provides a HTML hidden input field
|
188
195
|
#
|
189
196
|
# ==== Parameters
|
190
197
|
# name<Symbol>:: Model or Resource
|
@@ -194,33 +201,30 @@ module Merb::Helpers::Form
|
|
194
201
|
# String:: HTML
|
195
202
|
#
|
196
203
|
# ==== Example
|
197
|
-
# <%=
|
198
|
-
# # => <label for="password">Password</label><input type="password" id="password" name="password" />
|
204
|
+
# <%= hidden_field :name => "secret", :value => "some secret value" %>
|
199
205
|
#
|
200
206
|
# Used with a model:
|
201
207
|
#
|
202
|
-
# <%=
|
203
|
-
|
208
|
+
# <%= hidden_field :identifier %>
|
209
|
+
# # => <input type="hidden" id="person_identifier" name="person[identifier]" value="#{@person.identifier}" />
|
210
|
+
def hidden_field; end
|
204
211
|
|
205
|
-
# Provides a HTML
|
212
|
+
# Provides a generic HTML label.
|
206
213
|
#
|
207
214
|
# ==== Parameters
|
208
|
-
# name<Symbol>:: Model or Resource
|
209
215
|
# attrs<Hash>:: HTML attributes
|
210
216
|
#
|
211
217
|
# ==== Returns
|
212
218
|
# String:: HTML
|
213
219
|
#
|
214
220
|
# ==== Example
|
215
|
-
# <%=
|
216
|
-
#
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
# # => <input type="hidden" id="person_identifier" name="person[identifier]" value="#{@person.identifier}" />
|
221
|
-
def hidden_field; end
|
221
|
+
# <%= label "Full Name", :for => "name" %>
|
222
|
+
# => <label for="name">Full Name</label>
|
223
|
+
def label(*args)
|
224
|
+
current_form_context.label(*args)
|
225
|
+
end
|
222
226
|
|
223
|
-
# Provides a HTML
|
227
|
+
# Provides a HTML password input.
|
224
228
|
#
|
225
229
|
# ==== Parameters
|
226
230
|
# name<Symbol>:: Model or Resource
|
@@ -230,29 +234,52 @@ module Merb::Helpers::Form
|
|
230
234
|
# String:: HTML
|
231
235
|
#
|
232
236
|
# ==== Example
|
233
|
-
# <%=
|
237
|
+
# <%= password_field :name => :password, :label => "Password" %>
|
238
|
+
# # => <label for="password">Password</label><input type="password" id="password" name="password" />
|
234
239
|
#
|
235
240
|
# Used with a model:
|
236
241
|
#
|
237
|
-
# <%=
|
238
|
-
def
|
242
|
+
# <%= password_field :password, :label => 'New Password' %>
|
243
|
+
def password_field; end
|
239
244
|
|
240
|
-
# Provides a HTML
|
245
|
+
# Provides a HTML radio input tag
|
241
246
|
#
|
242
247
|
# ==== Parameters
|
243
|
-
#
|
244
|
-
# attrs<Hash>:: HTML attributes
|
248
|
+
# method<Symbol>:: Resource attribute
|
249
|
+
# attrs<Hash>:: HTML attributes and options
|
245
250
|
#
|
246
251
|
# ==== Returns
|
247
252
|
# String:: HTML
|
248
253
|
#
|
249
254
|
# ==== Example
|
250
|
-
# <%=
|
255
|
+
# <%= radio_button :name => "radio_options", :value => "1", :label => "One" %>
|
256
|
+
# <%= radio_button :name => "radio_options", :value => "2", :label => "Two" %>
|
257
|
+
# <%= radio_button :name => "radio_options", :value => "3", :label => "Three", :checked => true %>
|
251
258
|
#
|
252
259
|
# Used with a model:
|
253
260
|
#
|
254
|
-
# <%=
|
255
|
-
|
261
|
+
# <%= form_for @person do %>
|
262
|
+
# <%= radio_button :first_name %>
|
263
|
+
# <% end =%>
|
264
|
+
def radio_button; end
|
265
|
+
|
266
|
+
# Provides a radio group based on a resource attribute.
|
267
|
+
# This is generally used within a resource block such as +form_for+.
|
268
|
+
#
|
269
|
+
# ==== Parameters
|
270
|
+
# method<Symbol>:: Resource attribute
|
271
|
+
# arr<Array>:: Choices
|
272
|
+
#
|
273
|
+
# ==== Returns
|
274
|
+
# String:: HTML
|
275
|
+
#
|
276
|
+
# ==== Examples
|
277
|
+
# <%# the labels are the options %>
|
278
|
+
# <%= radio_group :my_choice, [5,6,7] %>
|
279
|
+
#
|
280
|
+
# <%# custom labels %>
|
281
|
+
# <%= radio_group :my_choice, [{:value => 5, :label => "five"}] %>
|
282
|
+
def radio_group; end
|
256
283
|
|
257
284
|
# Provides a HTML select
|
258
285
|
#
|
@@ -275,68 +302,42 @@ module Merb::Helpers::Form
|
|
275
302
|
# <%= select :name, :collection => %w(one two three) %>
|
276
303
|
def select; end
|
277
304
|
|
278
|
-
# Provides a
|
279
|
-
# There are two ways this tag can be generated, based on the
|
280
|
-
# option :boolean. If not set to true, a "magic" input is generated.
|
281
|
-
# Otherwise, an input is created that can be easily used for passing
|
282
|
-
# an array of values to the application.
|
305
|
+
# Provides a HTML textarea tag
|
283
306
|
#
|
284
307
|
# ==== Parameters
|
285
|
-
#
|
286
|
-
# attrs<Hash>:: HTML attributes
|
308
|
+
# contents<String>:: Contents of the text area
|
309
|
+
# attrs<Hash>:: HTML attributes
|
287
310
|
#
|
288
311
|
# ==== Returns
|
289
312
|
# String:: HTML
|
290
313
|
#
|
291
314
|
# ==== Example
|
292
|
-
# <%=
|
293
|
-
# <%= check_box :name => "choices[]", :boolean => false, :value => "dog" %>
|
294
|
-
# <%= check_box :name => "choices[]", :boolean => false, :value => "cat" %>
|
295
|
-
# <%= check_box :name => "choices[]", :boolean => false, :value => "weasle" %>
|
315
|
+
# <%= text_area "my comments", :name => "comments" %>
|
296
316
|
#
|
297
317
|
# Used with a model:
|
298
318
|
#
|
299
|
-
# <%=
|
300
|
-
def
|
319
|
+
# <%= text_area :comments %>
|
320
|
+
def text_area; end
|
301
321
|
|
302
|
-
# Provides a HTML
|
322
|
+
# Provides a HTML text input tag
|
303
323
|
#
|
304
324
|
# ==== Parameters
|
305
|
-
#
|
306
|
-
# attrs<Hash>:: HTML attributes
|
325
|
+
# name<Symbol>:: Model or Resource
|
326
|
+
# attrs<Hash>:: HTML attributes
|
307
327
|
#
|
308
328
|
# ==== Returns
|
309
329
|
# String:: HTML
|
310
330
|
#
|
311
331
|
# ==== Example
|
312
|
-
# <%=
|
313
|
-
#
|
314
|
-
# <%= radio_button :name => "radio_options", :value => "3", :label => "Three", :checked => true %>
|
332
|
+
# <%= text_field :name => :fav_color, :label => "Your Favorite Color" %>
|
333
|
+
# # => <label for="fav_color">Your Favorite Color</label><input type="text" id="fav_color" name="fav_color" />
|
315
334
|
#
|
316
335
|
# Used with a model:
|
317
336
|
#
|
318
337
|
# <%= form_for @person do %>
|
319
|
-
# <%=
|
338
|
+
# <%= text_field :first_name, :label => "First Name" %>
|
320
339
|
# <% end =%>
|
321
|
-
def
|
322
|
-
|
323
|
-
# Provides a radio group based on a resource attribute.
|
324
|
-
# This is generally used within a resource block such as +form_for+.
|
325
|
-
#
|
326
|
-
# ==== Parameters
|
327
|
-
# method<Symbol>:: Resource attribute
|
328
|
-
# arr<Array>:: Choices
|
329
|
-
#
|
330
|
-
# ==== Returns
|
331
|
-
# String:: HTML
|
332
|
-
#
|
333
|
-
# ==== Examples
|
334
|
-
# <%# the labels are the options %>
|
335
|
-
# <%= radio_group :my_choice, [5,6,7] %>
|
336
|
-
#
|
337
|
-
# <%# custom labels %>
|
338
|
-
# <%= radio_group :my_choice, [{:value => 5, :label => "five"}] %>
|
339
|
-
def radio_group; end
|
340
|
+
def text_field; end
|
340
341
|
|
341
342
|
# @todo radio_group helper still needs to be implemented
|
342
343
|
%w(text_field password_field hidden_field file_field
|
@@ -2,13 +2,23 @@ load File.dirname(__FILE__) / "form" / "helpers.rb"
|
|
2
2
|
load File.dirname(__FILE__) / "form" / "builder.rb"
|
3
3
|
|
4
4
|
class Merb::Controller
|
5
|
-
class_inheritable_accessor :
|
5
|
+
class_inheritable_accessor :_default_builder
|
6
|
+
include Merb::Helpers::Form
|
7
|
+
end
|
8
|
+
|
9
|
+
class Merb::PartController
|
10
|
+
class_inheritable_accessor :_default_builder
|
6
11
|
include Merb::Helpers::Form
|
7
12
|
end
|
8
13
|
|
9
14
|
Merb::BootLoader.after_app_loads do
|
10
15
|
class Merb::Controller
|
11
|
-
self.
|
12
|
-
Object.full_const_get(Merb::Plugins.config[:helpers][:
|
16
|
+
self._default_builder =
|
17
|
+
Object.full_const_get(Merb::Plugins.config[:helpers][:default_builder]) rescue Merb::Helpers::Form::Builder::ResourcefulFormWithErrors
|
18
|
+
end
|
19
|
+
|
20
|
+
class Merb::PartController
|
21
|
+
self._default_builder =
|
22
|
+
Object.full_const_get(Merb::Plugins.config[:helpers][:default_builder]) rescue Merb::Helpers::Form::Builder::ResourcefulFormWithErrors
|
13
23
|
end
|
14
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yehuda Katz
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09-
|
12
|
+
date: 2008-09-14 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.7
|
24
24
|
version:
|
25
25
|
description: Helper support for merb (similar to the Rails form helpers)
|
26
26
|
email: ykatz@engineyard.com
|