formula 0.0.8 → 0.0.9

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 (2) hide show
  1. data/lib/formula.rb +45 -39
  2. metadata +2 -2
data/lib/formula.rb CHANGED
@@ -1,12 +1,18 @@
1
1
  module Formula
2
2
 
3
+
3
4
  require 'formula/railtie' if defined?(Rails)
4
5
 
6
+
7
+ # Default class assigned to block (<div class="block">...</div>).
8
+ mattr_accessor :block_class
9
+ @@block_class = 'block'
10
+
5
11
  # Default class assigned to input (<div class="input">...</div>).
6
12
  mattr_accessor :input_class
7
13
  @@input_class = 'input'
8
14
 
9
- # Default class assigned to input (<div class="association">...</div>).
15
+ # Default class assigned to association (<div class="association">...</div>).
10
16
  mattr_accessor :association_class
11
17
  @@association_class = 'association'
12
18
 
@@ -18,11 +24,15 @@ module Formula
18
24
  mattr_accessor :hint_class
19
25
  @@hint_class = 'hint'
20
26
 
27
+ # Default tag assigned to block (<div class="input">...</div>).
28
+ mattr_accessor :block_tag
29
+ @@block_tag = :div
30
+
21
31
  # Default tag assigned to input (<div class="input">...</div>).
22
32
  mattr_accessor :input_tag
23
33
  @@input_tag = :div
24
34
 
25
- # Default tag assigned to input (<div class="association">...</div>).
35
+ # Default tag assigned to association (<div class="association">...</div>).
26
36
  mattr_accessor :association_tag
27
37
  @@association_tag = :div
28
38
 
@@ -34,17 +44,6 @@ module Formula
34
44
  mattr_accessor :hint_tag
35
45
  @@hint_tag = :div
36
46
 
37
- # Default size used on inputs (<input ... size="50" />).
38
- mattr_accessor :default_input_size
39
- @@default_input_size = 50
40
-
41
- # Default cols used on textarea (<textarea ... cols="50" />).
42
- mattr_accessor :default_textarea_cols
43
- @@default_textarea_cols = 50
44
-
45
- # Default cols used on textarea (<textarea ... rows="5" />).
46
- mattr_accessor :default_textarea_rows
47
- @@default_textarea_rows = 5
48
47
 
49
48
  class FormulaFormBuilder < ActionView::Helpers::FormBuilder
50
49
 
@@ -79,12 +78,12 @@ module Formula
79
78
 
80
79
  components << self.label(method, options[:label])
81
80
 
82
- components << @template.content_tag(::Formula.input_tag, @template.capture(&block), :class => ::Formula.input_class)
81
+ components << @template.capture(&block)
83
82
 
84
83
  components << @template.content_tag(::Formula.hint_tag, options[:hint], :class => ::Formula.hint_class) if options[:hint]
85
84
  components << @template.content_tag(::Formula.error_tag, options[:error], :class => ::Formula.error_class) if options[:error]
86
85
 
87
- @template.content_tag(:div, options[:container]) do
86
+ @template.content_tag(::Formula.block_tag, options[:container]) do
88
87
  components.join
89
88
  end
90
89
  end
@@ -109,26 +108,23 @@ module Formula
109
108
  #
110
109
  # Equivalent:
111
110
  #
112
- # <div>
113
- # <div class="input">
114
- # <%= f.label(:name)
115
- # <%= f.text_field(:name)
116
- # </div>
111
+ # <div class="block">
112
+ # <%= f.label(:name)
113
+ # <div class="input string"><%= f.text_field(:name)</div>
117
114
  # </div>
118
- # <div>
119
- # <div class="input">
120
- # <%= f.label(:email)
121
- # <%= f.email_field(:email)
115
+ # <div class="block">
116
+ # <%= f.label(:email)
117
+ # <div class="input string"><%= f.email_field(:email)</div>
122
118
  # </div>
123
119
  # </div>
124
- # <div class="half">
120
+ # <div class="block half">
125
121
  # <div class="input">
126
122
  # <%= f.label(:password_a, "Password")
127
123
  # <%= f.password_field(:password_a)
128
124
  # <div class="hint">It's a secret!</div>
129
125
  # </div>
130
126
  # </div>
131
- # <div class="half">
127
+ # <div class="block half">
132
128
  # <div class="input">
133
129
  # <%= f.label(:password_b, "Password")
134
130
  # <%= f.password_field(:password_b)
@@ -138,22 +134,25 @@ module Formula
138
134
 
139
135
  def input(method, options = {})
140
136
  options[:as] ||= as(method)
137
+ options[:input] ||= {}
141
138
 
142
139
  self.block(method, options) do
143
- case options[:as]
144
- when :text then text_area(method, options[:input] || {})
140
+ @template.content_tag(::Formula.input_tag, :class => [::Formula.input_class, options[:as]]) do
141
+ case options[:as]
142
+ when :text then text_area(method, options[:input])
145
143
 
146
- when :string then text_field(method, options[:input] || {})
147
- when :password then password_field(method, options[:input] || {})
144
+ when :string then text_field(method, options[:input])
145
+ when :password then password_field(method, options[:input])
148
146
 
149
- when :url then url_field(method, options[:input] || {})
150
- when :email then email_field(method, options[:input] || {})
151
- when :phone then phone_field(method, options[:input] || {})
152
- when :number then number_field(method, options[:input] || {})
147
+ when :url then url_field(method, options[:input])
148
+ when :email then email_field(method, options[:input])
149
+ when :phone then phone_field(method, options[:input])
150
+ when :number then number_field(method, options[:input])
153
151
 
154
- when :date then date_select(method, options[:input] || {})
155
- when :time then time_select(method, options[:input] || {})
156
- when :datetime then datetime_select(method, options[:input] || {})
152
+ when :date then date_select(method, options[:input])
153
+ when :time then time_select(method, options[:input])
154
+ when :datetime then datetime_select(method, options[:input])
155
+ end
157
156
  end
158
157
  end
159
158
  end
@@ -177,14 +176,21 @@ module Formula
177
176
  # <div>
178
177
  # <div class="association">
179
178
  # <%= f.label(:category_id)
180
- # <%= f.collection_select(:category_id, Category.all, :id, :name)
179
+ # <div class="association"><%= f.collection_select(:category_id, Category.all, :id, :name) %></div>
181
180
  # <div class="hint">What do you do?</div>
182
181
  # </div>
183
182
  # </div>
184
183
 
185
184
  def association(method, collection, value, text, options = {})
185
+ options[:as] ||= :select
186
+ options[:association] ||= {}
187
+
186
188
  self.block(method, options) do
187
- collection_select(method, collection, value, text)
189
+ @template.content_tag(::Formula.association_tag, :class => [::Formula.association_class, options[:as]]) do
190
+ case options[:as]
191
+ when :select then collection_select(method, collection, value, text, options[:association])
192
+ end
193
+ end
188
194
  end
189
195
  end
190
196
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kevin Sylvestre