formula 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/formula.rb +30 -10
- data/lib/formula/version.rb +1 -1
- metadata +2 -2
data/lib/formula.rb
CHANGED
@@ -44,6 +44,14 @@ module Formula
|
|
44
44
|
mattr_accessor :hint_tag
|
45
45
|
@@hint_tag = :div
|
46
46
|
|
47
|
+
# Method for file.
|
48
|
+
mattr_accessor :file
|
49
|
+
@@file = [:file?]
|
50
|
+
|
51
|
+
# Default as.
|
52
|
+
mattr_accessor :default_as
|
53
|
+
@@default_as = :string
|
54
|
+
|
47
55
|
|
48
56
|
class FormulaFormBuilder < ActionView::Helpers::FormBuilder
|
49
57
|
|
@@ -274,6 +282,18 @@ module Formula
|
|
274
282
|
end
|
275
283
|
|
276
284
|
|
285
|
+
# Introspection on an association to determine if a method is a file. This
|
286
|
+
# is determined by the methods ability to respond to file methods.
|
287
|
+
|
288
|
+
def file?(method)
|
289
|
+
@files ||= {}
|
290
|
+
@files[method] ||= begin
|
291
|
+
file = @object.send(method) if @object && @object.respond_to?(method)
|
292
|
+
file && ::Formula.file.any? { |method| file.respond_to?(method) }
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
|
277
297
|
# Introspection on the field and method to determine how to render a method. The method is
|
278
298
|
# used to generate form element types.
|
279
299
|
#
|
@@ -291,18 +311,15 @@ module Formula
|
|
291
311
|
# * :string - for all other cases
|
292
312
|
|
293
313
|
def as(method)
|
294
|
-
type = type(method)
|
295
314
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
when /password/ then return :password
|
302
|
-
end
|
315
|
+
case method
|
316
|
+
when /url/ then return :url
|
317
|
+
when /email/ then return :email
|
318
|
+
when /phone/ then return :phone
|
319
|
+
when /password/ then return :password
|
303
320
|
end
|
304
321
|
|
305
|
-
case type
|
322
|
+
case type(method)
|
306
323
|
when :string then return :string
|
307
324
|
when :integer then return :number
|
308
325
|
when :float then return :number
|
@@ -314,7 +331,10 @@ module Formula
|
|
314
331
|
when :text then return :text
|
315
332
|
end
|
316
333
|
|
317
|
-
return :
|
334
|
+
return :file if file?(method)
|
335
|
+
|
336
|
+
return ::Formula.default_as
|
337
|
+
|
318
338
|
end
|
319
339
|
|
320
340
|
|
data/lib/formula/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: formula
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Sylvestre
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-21 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|