formula 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/README.rdoc +11 -0
  2. data/lib/formula.rb +53 -1
  3. metadata +3 -3
data/README.rdoc CHANGED
@@ -11,6 +11,17 @@ Formula is a Rails form generator that generates simple clean markup. The projec
11
11
  <%= f.input :email %>
12
12
  <%= f.input :password %>
13
13
 
14
+ <%= f.input :email, :label => "Email:", :hint => "We promise never to bother you." %>
15
+ <%= f.input :password, :label => "Password:", :hint => "Must be at least six characters." %>
16
+
17
+ <%= f.input :url, :class => 'grid-04' %>
18
+ <%= f.input :phone, :class => 'grid-04' %>
19
+ <%= f.input :email, :class => 'grid-04' %>
20
+
21
+ <%= f.input :credit_card_number, :label => 'Number:', :class => 'grid-08' %>
22
+ <%= f.input :credit_card_verification, :label => 'CVV:', :class => 'grid-02' %>
23
+ <%= f.input :credit_card_expiration, :label => 'Expiration:', :class => 'grid-02' %>
24
+
14
25
  == Copyright
15
26
 
16
27
  Copyright (c) 2010 Kevin Sylvestre. See LICENSE for details.
data/lib/formula.rb CHANGED
@@ -2,9 +2,59 @@ module Formula
2
2
 
3
3
  require 'formula/railtie' if defined?(Rails)
4
4
 
5
+ mattr_accessor :container_tag
6
+ @@container_tag = :div
7
+
8
+ mattr_accessor :hints_tag
9
+ @@hints_tag = :div
10
+
11
+ mattr_accessor :errors_tag
12
+ @@errors_tag = :div
13
+
14
+ mattr_accessor :default_input_size
15
+ @@default_input_size = 50
16
+
17
+ mattr_accessor :default_textarea_cols
18
+ @@default_textarea_cols = 50
19
+
20
+ mattr_accessor :default_textarea_rows
21
+ @@default_textarea_rows = 3
22
+
5
23
  class FormulaFormBuilder < ActionView::Helpers::FormBuilder
24
+
25
+ def as(method, options = {})
26
+ type = @object.column_for_attribute(method)
27
+
28
+ case type
29
+ when :string then
30
+ return :url if method.to_s =~ /url/
31
+ return :email if method.to_s =~ /email/
32
+ return :phone if method.to_s =~ /phone/
33
+ return :password if method.to_s =~ /password/
34
+ when :integer then
35
+ return :number
36
+ when :float then
37
+ return :number
38
+ when :decimal then
39
+ return :number
40
+ end
41
+
42
+ return :text
43
+ end
6
44
 
7
45
  def input(method, options = {}, &block)
46
+ options[:as] ||= as(method, options)
47
+ options[:errors] ||= @object.errors[method]
48
+
49
+ components = []
50
+
51
+ components << label(:method, options[:label])
52
+ components << @template.content_tag(::Formula.hints_tag, options[:hint], :class => 'hints') if options[:hints]
53
+ components << @template.content_tag(::Formula.errors_tag, options[:errors], :class => 'errors') if options[:errors]
54
+
55
+ @template.content_tag(::Formula.container_tag, :class => options[:class]) do
56
+ components.join
57
+ end
8
58
  end
9
59
 
10
60
  def association(method, options = {}, &block)
@@ -32,7 +82,9 @@ module Formula
32
82
  options[:builder] ||= @@builder
33
83
  fields_for(record_or_name_or_array, *(args << options), &block)
34
84
  end
35
-
85
+
86
+ alias :formula_for :formula_form_for
87
+ alias :fieldula_for :formula_fields_for
36
88
  end
37
89
 
38
90
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kevin Sylvestre
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-08 00:00:00 -05:00
17
+ date: 2010-11-09 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies: []
20
20