dao 5.3.0 → 5.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +26 -40
  3. data/a.rb +8 -0
  4. data/dao.gemspec +6 -23
  5. data/lib/dao.rb +5 -1
  6. data/lib/dao/form.rb +331 -293
  7. data/test/form_test.rb +30 -0
  8. metadata +7 -145
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGViMmUzODVjMzE1ZTRhMjM4MjAyZjYxZTZhOGFkY2U1ODdmYjQ3Ng==
4
+ MjczMDcyNTc1MjA4NTgwN2E5NmEwNjNhNTI3MDI5M2QxMTA1YWM4ZA==
5
5
  data.tar.gz: !binary |-
6
- ZmFhNzhhNDJmYjFkNWEzOTNlZmNhNDg5ZTQ1MmE5YTYzMzNlMjcyZg==
6
+ OWJkNzIzYWY0Nzg4ZjYwZWM1YjdhZGFhYTRhZDYyOThlYzg4ZTQ2NQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjQ1NmU2NTYzZTFjMDgzZDFkMjE5NGZjMDZjODBjOGNkNDU4Y2NlZTJmMDY0
10
- MWE0MDcxYjE5ZWJhYzE4ZDAxNjY3Nzc0Mjc5OWUzMjgzMWZlNTQzZWJkNTQ4
11
- NTJiMWMwMzdiZjNmNjliZjNhMjI1NjdkZjdmMDRiMTFmZDUwYzc=
9
+ YzkxNjcyYTBjMjA0MGI0MjcwMjYwMzAzZWY2YWQ3YzFmN2NjN2ZlZTBiOTI4
10
+ YmRlNDE1OTFmMjBjYzljOGIwNDg1OGJlMTk2ODEzZTRkYjY0ZjU5ODg5NjBl
11
+ Y2IwZWEyMzFmODk3YTZiNGI2MzdkYTk0NWVjY2Y0MDI2MTA1OGU=
12
12
  data.tar.gz: !binary |-
13
- NGUyYmFjNTk5ZDU2YTUxMjE0OGI3YWUxNzlkZDJkYzQyODVlMjNiMTU1OWUx
14
- MTJhN2ZjNTI5ZTk0MTM1NWUzMzAxM2RhMWQxYzJhYzU2ZTQ3MDY0MDU5MzNm
15
- ZWE3ODg2ZWFlMjRjMTA3ZWM0OGVhNDg0MmQ2MTQ4ZTViYjg2MGY=
13
+ OTRjN2I1MGZlYzdlNzMxNWIxZjI3NGFlOWIwZDgxY2E0MzkxYTVmYmRhODI2
14
+ NzY2ZWNjZDE1M2Y5NTk5OTA5ZmQ2NzBhZTQ3MDYzNDc3MGNlNjEyZDFmYzhl
15
+ YjM0MDU5MzEwMmQxNTdmMGJmNmYxYzMxYjJjYzAxZDhhY2RmMjI=
data/Rakefile CHANGED
@@ -3,6 +3,9 @@ This.author = "Ara T. Howard"
3
3
  This.email = "ara.t.howard@gmail.com"
4
4
  This.homepage = "https://github.com/ahoward/#{ This.lib }"
5
5
 
6
+ task :license do
7
+ open('LICENSE', 'w'){|fd| fd.puts "same as ruby's"}
8
+ end
6
9
 
7
10
  task :default do
8
11
  puts((Rake::Task.tasks.map{|task| task.name.gsub(/::/,':')} - ['default']).sort)
@@ -29,7 +32,7 @@ def run_tests!(which = nil)
29
32
 
30
33
  test_rbs.each_with_index do |test_rb, index|
31
34
  testno = index + 1
32
- command = "#{ File.basename(This.ruby) } -I ./lib -I ./test/lib #{ test_rb }"
35
+ command = "#{ This.ruby } -w -I ./lib -I ./test/lib #{ test_rb }"
33
36
 
34
37
  puts
35
38
  say(div, :color => :cyan, :bold => true)
@@ -59,8 +62,8 @@ end
59
62
 
60
63
  task :gemspec do
61
64
  ignore_extensions = ['git', 'svn', 'tmp', /sw./, 'bak', 'gem']
62
- ignore_directories = ['pkg', 'db']
63
- ignore_files = ['test/log', 'test/db.yml', 'a.rb', 'b.rb'] + Dir['db/*'] + %w'db'
65
+ ignore_directories = ['pkg']
66
+ ignore_files = ['test/log']
64
67
 
65
68
  shiteless =
66
69
  lambda do |list|
@@ -87,9 +90,10 @@ task :gemspec do
87
90
  files = shiteless[Dir::glob("**/**")]
88
91
  executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
89
92
  #has_rdoc = true #File.exist?('doc')
90
- test_files = test(?e, "test/#{ lib }.rb") ? "test/#{ lib }.rb" : nil
93
+ test_files = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
91
94
  summary = object.respond_to?(:summary) ? object.summary : "summary: #{ lib } kicks the ass"
92
95
  description = object.respond_to?(:description) ? object.description : "description: #{ lib } kicks the ass"
96
+ license = object.respond_to?(:license) ? object.license : "same as ruby's"
93
97
 
94
98
  if This.extensions.nil?
95
99
  This.extensions = []
@@ -100,51 +104,39 @@ task :gemspec do
100
104
  end
101
105
  extensions = [extensions].flatten.compact
102
106
 
103
- # TODO
104
- if This.dependencies.nil?
105
- dependencies = []
106
- else
107
- case This.dependencies
108
- when Hash
109
- dependencies = This.dependencies.values
110
- when Array
111
- dependencies = This.dependencies
112
- end
113
- end
114
-
115
107
  template =
116
108
  if test(?e, 'gemspec.erb')
117
109
  Template{ IO.read('gemspec.erb') }
118
110
  else
119
111
  Template {
120
112
  <<-__
121
- ## <%= lib %>.gemspec
113
+ ## #{ lib }.gemspec
122
114
  #
123
115
 
124
116
  Gem::Specification::new do |spec|
125
- spec.name = <%= lib.inspect %>
126
- spec.version = <%= version.inspect %>
117
+ spec.name = #{ lib.inspect }
118
+ spec.version = #{ version.inspect }
127
119
  spec.platform = Gem::Platform::RUBY
128
- spec.summary = <%= lib.inspect %>
129
- spec.description = <%= description.inspect %>
120
+ spec.summary = #{ lib.inspect }
121
+ spec.description = #{ description.inspect }
122
+ spec.license = #{ license.inspect }
130
123
 
131
- spec.files =\n<%= files.sort.pretty_inspect %>
132
- spec.executables = <%= executables.inspect %>
124
+ spec.files =\n#{ files.sort.pretty_inspect }
125
+ spec.executables = #{ executables.inspect }
133
126
 
134
127
  spec.require_path = "lib"
135
128
 
136
- spec.test_files = <%= test_files.inspect %>
129
+ spec.test_files = #{ test_files.inspect }
137
130
 
138
- <% dependencies.each do |lib_version| %>
139
- spec.add_dependency(*<%= Array(lib_version).flatten.inspect %>)
140
- <% end %>
131
+ ### spec.add_dependency 'lib', '>= version'
132
+ #### spec.add_dependency 'map'
141
133
 
142
- spec.extensions.push(*<%= extensions.inspect %>)
134
+ spec.extensions.push(*#{ extensions.inspect })
143
135
 
144
- spec.rubyforge_project = <%= This.rubyforge_project.inspect %>
145
- spec.author = <%= This.author.inspect %>
146
- spec.email = <%= This.email.inspect %>
147
- spec.homepage = <%= This.homepage.inspect %>
136
+ spec.rubyforge_project = #{ This.rubyforge_project.inspect }
137
+ spec.author = #{ This.author.inspect }
138
+ spec.email = #{ This.email.inspect }
139
+ spec.homepage = #{ This.homepage.inspect }
148
140
  end
149
141
  __
150
142
  }
@@ -188,8 +180,8 @@ task :readme do
188
180
  end
189
181
 
190
182
  template =
191
- if test(?e, 'readme.erb')
192
- Template{ IO.read('readme.erb') }
183
+ if test(?e, 'README.erb')
184
+ Template{ IO.read('README.erb') }
193
185
  else
194
186
  Template {
195
187
  <<-__
@@ -280,12 +272,6 @@ BEGIN {
280
272
  end
281
273
  This.version = version
282
274
 
283
- # see if dependencies are export by the module
284
- #
285
- if This.object.respond_to?(:dependencies)
286
- This.dependencies = This.object.dependencies
287
- end
288
-
289
275
  # we need to know the name of the lib an it's version
290
276
  #
291
277
  abort('no lib') unless This.lib
data/a.rb ADDED
@@ -0,0 +1,8 @@
1
+
2
+ f = Dao::Form.new
3
+
4
+ f.scope_for(:foo) do
5
+ p f.name_for(:bar)
6
+ p f.key_for(:bar)
7
+ end
8
+
@@ -3,16 +3,18 @@
3
3
 
4
4
  Gem::Specification::new do |spec|
5
5
  spec.name = "dao"
6
- spec.version = "5.3.0"
6
+ spec.version = "5.3.2"
7
7
  spec.platform = Gem::Platform::RUBY
8
8
  spec.summary = "dao"
9
- spec.description = "description: dao kicks the ass"
9
+ spec.description = "presenter, conducer, api, and better form objects for you rails' pleasure"
10
+ spec.license = "same as ruby's"
10
11
 
11
12
  spec.files =
12
13
  ["Gemfile",
13
14
  "Gemfile.lock",
14
15
  "README",
15
16
  "Rakefile",
17
+ "a.rb",
16
18
  "dao.gemspec",
17
19
  "lib",
18
20
  "lib/dao",
@@ -104,27 +106,8 @@ Gem::Specification::new do |spec|
104
106
 
105
107
  spec.test_files = nil
106
108
 
107
-
108
- spec.add_dependency(*["rails", " >= 3.1"])
109
-
110
- spec.add_dependency(*["map", " >= 6.0.0"])
111
-
112
- spec.add_dependency(*["fattr", " >= 2.2"])
113
-
114
- spec.add_dependency(*["coerce", " >= 0.0.3"])
115
-
116
- spec.add_dependency(*["tagz", " >= 9.9.2"])
117
-
118
- spec.add_dependency(*["multi_json", " >= 1.0.3"])
119
-
120
- spec.add_dependency(*["uuidtools", " >= 2.1.2"])
121
-
122
- spec.add_dependency(*["wrap", " >= 1.5.0"])
123
-
124
- spec.add_dependency(*["rails_current", " >= 1.8.0"])
125
-
126
- spec.add_dependency(*["rails_errors2html", " >= 1.3.0"])
127
-
109
+ ### spec.add_dependency 'lib', '>= version'
110
+ #### spec.add_dependency 'map'
128
111
 
129
112
  spec.extensions.push(*[])
130
113
 
data/lib/dao.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  # dao libs
12
12
  #
13
13
  module Dao
14
- Version = '5.3.0' unless defined?(Version)
14
+ Version = '5.3.2' unless defined?(Version)
15
15
 
16
16
  def version
17
17
  Dao::Version
@@ -32,6 +32,10 @@
32
32
  }
33
33
  end
34
34
 
35
+ def description
36
+ "presenter, conducer, api, and better form objects for you rails' pleasure"
37
+ end
38
+
35
39
  def libdir(*args, &block)
36
40
  @libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
37
41
  args.empty? ? @libdir : File.join(@libdir, *args)
@@ -39,9 +39,13 @@ module Dao
39
39
  # instance methods
40
40
  #
41
41
  attr_accessor :object
42
+ attr_accessor :unscoped
43
+ attr_accessor :scope
42
44
 
43
45
  def initialize(*args)
44
46
  @object = args.shift
47
+ @unscoped = Map.new
48
+ @scope = []
45
49
  end
46
50
 
47
51
  fattr(:attributes) do
@@ -63,14 +67,15 @@ module Dao
63
67
  Map.new
64
68
  end
65
69
 
66
- case attributes
67
- when Map
68
- attributes
69
- when Hash
70
- Map.new(attributes)
71
- else
72
- raise(ArgumentError.new("#{ attributes.inspect } (#{ attributes.class })"))
73
- end
70
+ @unscoped[:attributes] =
71
+ case attributes
72
+ when Map
73
+ attributes
74
+ when Hash
75
+ Map.new(attributes)
76
+ else
77
+ raise(ArgumentError.new("#{ attributes.inspect } (#{ attributes.class })"))
78
+ end
74
79
  end
75
80
 
76
81
  fattr(:name) do
@@ -107,12 +112,13 @@ module Dao
107
112
  Errors.new
108
113
  end
109
114
 
110
- case errors
111
- when Errors
112
- errors
113
- else
114
- raise(ArgumentError.new("#{ errors.inspect } (#{ errors.class })"))
115
- end
115
+ @unscoped[:errors] =
116
+ case errors
117
+ when Errors
118
+ errors
119
+ else
120
+ raise(ArgumentError.new("#{ errors.inspect } (#{ errors.class })"))
121
+ end
116
122
  end
117
123
 
118
124
  fattr(:messages) do
@@ -148,351 +154,351 @@ module Dao
148
154
 
149
155
  # html generation methods
150
156
  #
151
- def element(which, *args, &block)
152
- send(which, *args, &block)
153
- end
154
-
155
- def form(*args, &block)
156
- options = args.extract_options!.to_options!
157
- keys = args.flatten
157
+ module Elements
158
+ def element(which, *args, &block)
159
+ send(which, *args, &block)
160
+ end
158
161
 
159
- action = options.delete(:action) || './'
160
- method = options.delete(:method) || 'post'
161
- id = options.delete(:id) || id_for(keys)
162
- klass = class_for(keys, options.delete(:class))
163
- error = error_for(keys, options.delete(:error))
162
+ def form(*args, &block)
163
+ options = args.extract_options!.to_options!
164
+ keys = scope(args)
164
165
 
165
- content =
166
- if block.nil? and !options.has_key?(:content)
167
- ''
168
- else
169
- block ? block.call(form=self) : options.delete(:content)
170
- end
171
-
172
- form_(options_for(options, :action => action, :method => method, :class => klass, :id => id, :data_error => error)){ content }
173
- end
166
+ action = options.delete(:action) || './'
167
+ method = options.delete(:method) || 'post'
168
+ id = options.delete(:id) || id_for(keys)
169
+ klass = class_for(keys, options.delete(:class))
170
+ error = error_for(keys, options.delete(:error))
174
171
 
175
- def label(*args, &block)
176
- options = args.extract_options!.to_options!
177
- keys = args.flatten
172
+ content =
173
+ if block.nil? and !options.has_key?(:content)
174
+ ''
175
+ else
176
+ block ? block.call(form=self) : options.delete(:content)
177
+ end
178
178
 
179
- block ||=
180
- proc do
181
- options.delete(:content) ||
182
- options.delete(:value) ||
183
- keys.map{|key| key.to_s.titleize}.join(' ')
184
- end
179
+ form_(options_for(options, :action => action, :method => method, :class => klass, :id => id, :data_error => error)){ content }
180
+ end
185
181
 
186
- id = options.delete(:id) || id_for(keys + [:label])
187
- klass = class_for(keys, options.delete(:class))
188
- error = error_for(keys, options.delete(:error))
189
- target = options.delete(:for) || id_for(keys)
182
+ def label(*args, &block)
183
+ options = args.extract_options!.to_options!
184
+ keys = scope(args)
190
185
 
191
- label_(options_for(options, :for => target, :class => klass, :id => id, :data_error => error), &block)
192
- end
186
+ block ||=
187
+ proc do
188
+ options.delete(:content) ||
189
+ options.delete(:value) ||
190
+ keys.map{|key| key.to_s.titleize}.join(' ')
191
+ end
193
192
 
194
- def input(*args, &block)
195
- options = args.extract_options!.to_options!
196
- keys = args.flatten
193
+ id = options.delete(:id) || id_for(keys + [:label])
194
+ klass = class_for(keys, options.delete(:class))
195
+ error = error_for(keys, options.delete(:error))
196
+ target = options.delete(:for) || id_for(keys)
197
197
 
198
- type = options.delete(:type) || :text
199
- name = options.delete(:name) || name_for(keys)
200
- id = options.delete(:id) || id_for(keys)
201
- klass = class_for(keys, options.delete(:class))
202
- error = error_for(keys, options.delete(:error))
198
+ label_(options_for(options, :for => target, :class => klass, :id => id, :data_error => error), &block)
199
+ end
203
200
 
204
- value =
205
- if block.nil? and !options.has_key?(:value)
206
- value_for(attributes, keys)
207
- else
208
- block ? block.call(attributes.get(keys)) : options.delete(:value)
209
- end
201
+ def input(*args, &block)
202
+ options = args.extract_options!.to_options!
203
+ keys = scope(args)
210
204
 
211
- value = escape_html(value)
205
+ type = options.delete(:type) || :text
206
+ name = options.delete(:name) || name_for(keys)
207
+ id = options.delete(:id) || id_for(keys)
208
+ klass = class_for(keys, options.delete(:class))
209
+ error = error_for(keys, options.delete(:error))
212
210
 
213
- input_(options_for(options, :type => type, :name => name, :value => value, :class => klass, :id => id, :data_error => error)){}
214
- end
211
+ value =
212
+ if block.nil? and !options.has_key?(:value)
213
+ value_for(attributes, keys)
214
+ else
215
+ block ? block.call(attributes.get(keys)) : options.delete(:value)
216
+ end
215
217
 
216
- def submit(*args, &block)
217
- options = args.extract_options!.to_options!
218
- keys = args.flatten
218
+ input_(options_for(options, :type => type, :name => name, :value => value, :class => klass, :id => id, :data_error => error)){}
219
+ end
219
220
 
220
- keys.push(:submit) if keys.empty?
221
- name = options.delete(:name) || name_for(keys)
221
+ def submit(*args, &block)
222
+ options = args.extract_options!.to_options!
223
+ keys = scope(args)
222
224
 
223
- content = block ? block.call : (args.first || 'Submit')
225
+ keys.push(:submit) if keys.empty?
226
+ name = options.delete(:name) || name_for(keys)
224
227
 
225
- options[:name] ||= name
226
- options[:type] ||= :submit
227
- options[:value] ||= content
228
+ content = block ? block.call : (args.first || 'Submit')
228
229
 
229
- input_(options_for(options)){}
230
- end
230
+ options[:name] ||= name
231
+ options[:type] ||= :submit
232
+ options[:value] ||= content
231
233
 
232
- def button(*args, &block)
233
- options = args.extract_options!.to_options!
234
- keys = args.flatten
234
+ input_(options_for(options)){}
235
+ end
235
236
 
236
- type = options.delete(:type) || :button
237
- name = options.delete(:name) || name_for(keys)
238
- id = options.delete(:id) || id_for(keys)
239
- klass = class_for(keys, options.delete(:class))
240
- error = error_for(keys, options.delete(:error))
237
+ def button(*args, &block)
238
+ options = args.extract_options!.to_options!
239
+ keys = scope(args)
241
240
 
242
- value = options.has_key?(:value) ? options.delete(:value) : value_for(attributes, keys)
241
+ type = options.delete(:type) || :button
242
+ name = options.delete(:name) || name_for(keys)
243
+ id = options.delete(:id) || id_for(keys)
244
+ klass = class_for(keys, options.delete(:class))
245
+ error = error_for(keys, options.delete(:error))
243
246
 
244
- content = (block ? block.call : (options.delete(:content) || 'Submit'))
247
+ value = options.has_key?(:value) ? options.delete(:value) : value_for(attributes, keys)
245
248
 
246
- value = escape_html(value)
247
- content = escape_html(content)
249
+ content = (block ? block.call : (options.delete(:content) || 'Submit'))
248
250
 
249
- button_(options_for(options, :type => type, :name => name, :value => value, :class => klass, :id => id, :data_error => error)){ content }
250
- end
251
+ content = escape_html(content)
251
252
 
252
- def radio_button(*args, &block)
253
- options = args.extract_options!.to_options!
254
- keys = args.flatten
255
-
256
- type = options.delete(:type) || :radio
257
- name = options.delete(:name) || name_for(keys)
258
- id = options.delete(:id) || id_for(keys)
259
- klass = class_for(keys, options.delete(:class))
260
- error = error_for(keys, options.delete(:error))
261
-
262
- unless options.has_key?(:checked)
263
- checked =
264
- if options.has_key?(:value) and attributes.has?(keys)
265
- a = attributes.get(keys)
266
- b = options[:value]
267
- a==b or a.to_s==b.to_s
268
- else
269
- false
270
- end
271
- options[:checked] = checked if checked
253
+ button_(options_for(options, :type => type, :name => name, :value => value, :class => klass, :id => id, :data_error => error)){ content }
272
254
  end
273
255
 
274
- input_(options_for(options, :type => :radio, :name => name, :class => klass, :id => id, :data_error => error)){}
275
- end
256
+ def radio_button(*args, &block)
257
+ options = args.extract_options!.to_options!
258
+ keys = scope(args)
259
+
260
+ type = options.delete(:type) || :radio
261
+ name = options.delete(:name) || name_for(keys)
262
+ id = options.delete(:id) || id_for(keys)
263
+ klass = class_for(keys, options.delete(:class))
264
+ error = error_for(keys, options.delete(:error))
265
+
266
+ unless options.has_key?(:checked)
267
+ checked =
268
+ if options.has_key?(:value) and attributes.has?(keys)
269
+ a = attributes.get(keys)
270
+ b = options[:value]
271
+ a==b or a.to_s==b.to_s
272
+ else
273
+ false
274
+ end
275
+ options[:checked] = checked if checked
276
+ end
276
277
 
277
- def checkbox(*args, &block)
278
- options = args.extract_options!.to_options!
279
- keys = args.flatten
278
+ input_(options_for(options, :type => :radio, :name => name, :class => klass, :id => id, :data_error => error)){}
279
+ end
280
280
 
281
- type = options.delete(:type) || :checkbox
282
- name = options.delete(:name) || name_for(keys)
283
- id = options.delete(:id) || id_for(keys)
284
- klass = class_for(keys, options.delete(:class))
285
- error = error_for(keys, options.delete(:error))
286
- values = options.delete(:values)
281
+ def checkbox(*args, &block)
282
+ options = args.extract_options!.to_options!
283
+ keys = scope(args)
287
284
 
288
- unless options.has_key?(:checked)
289
- checked = Coerce.boolean(attributes.get(keys))
290
- options[:checked] = checked if checked
291
- end
285
+ type = options.delete(:type) || :checkbox
286
+ name = options.delete(:name) || name_for(keys)
287
+ id = options.delete(:id) || id_for(keys)
288
+ klass = class_for(keys, options.delete(:class))
289
+ error = error_for(keys, options.delete(:error))
290
+ values = options.delete(:values)
292
291
 
293
- value_for =
294
- case values
295
- when false, nil
296
- {true => '1', false => '0'}
297
- when Hash
298
- h = {}
299
- values.map{|k, v| h[ k =~ /t|1|on|yes/ ? true : false ] = v}
300
- h
301
- else
302
- t, f, *ignored = Array(values).flatten.compact
303
- {true => t, false => f}
292
+ unless options.has_key?(:checked)
293
+ checked = Coerce.boolean(attributes.get(keys))
294
+ options[:checked] = checked if checked
304
295
  end
305
- value_for[true] ||= '1'
306
- value_for[false] ||= '0'
307
-
308
- hidden_options =
309
- options.dup.tap{|o| o.delete(:checked)}
310
-
311
- tagz{
312
- input_(options_for(hidden_options, :type => :hidden, :name => name, :value => value_for[false])){}
313
-
314
- __
315
-
316
- input_(
317
- options_for(
318
- options,
319
- :type => :checkbox,
320
- :name => name,
321
- :value => value_for[true],
322
- :class => klass,
323
- :id => id,
324
- :data_error => error
325
- )
326
- ){}
327
- }
328
- end
329
296
 
330
- def hidden(*args, &block)
331
- options = args.extract_options!.to_options!
332
- options[:type] = :hidden
333
- args.push(options)
334
- input(*args, &block)
335
- end
297
+ value_for =
298
+ case values
299
+ when false, nil
300
+ {true => '1', false => '0'}
301
+ when Hash
302
+ h = {}
303
+ values.map{|k, v| h[ k =~ /t|1|on|yes/ ? true : false ] = v}
304
+ h
305
+ else
306
+ t, f, *ignored = Array(values).flatten.compact
307
+ {true => t, false => f}
308
+ end
309
+ value_for[true] ||= '1'
310
+ value_for[false] ||= '0'
311
+
312
+ hidden_options =
313
+ options.dup.tap{|o| o.delete(:checked)}
314
+
315
+ tagz{
316
+ input_(options_for(hidden_options, :type => :hidden, :name => name, :value => value_for[false])){}
317
+
318
+ __
319
+
320
+ input_(
321
+ options_for(
322
+ options,
323
+ :type => :checkbox,
324
+ :name => name,
325
+ :value => value_for[true],
326
+ :class => klass,
327
+ :id => id,
328
+ :data_error => error
329
+ )
330
+ ){}
331
+ }
332
+ end
336
333
 
337
- def reset(*args)
338
- options = args.extract_options!.to_options!
339
- options[:type] = :reset
340
- args.push(options)
341
- button(*args)
342
- end
334
+ def hidden(*args, &block)
335
+ options = args.extract_options!.to_options!
336
+ options[:type] = :hidden
337
+ args.push(options)
338
+ input(*args, &block)
339
+ end
343
340
 
344
- def textarea(*args, &block)
345
- options = args.extract_options!.to_options!
346
- keys = args.flatten
341
+ def reset(*args)
342
+ options = args.extract_options!.to_options!
343
+ options[:type] = :reset
344
+ args.push(options)
345
+ button(*args)
346
+ end
347
347
 
348
- name = options.delete(:name) || name_for(keys)
349
- id = options.delete(:id) || id_for(keys)
350
- klass = class_for(keys, options.delete(:class))
351
- error = error_for(keys, options.delete(:error))
348
+ def textarea(*args, &block)
349
+ options = args.extract_options!.to_options!
350
+ keys = scope(args)
352
351
 
353
- value =
354
- if block.nil? and !options.has_key?(:value)
355
- value_for(attributes, keys)
356
- else
357
- block ? block.call(attributes.get(keys)) : options.delete(:value)
358
- end
352
+ name = options.delete(:name) || name_for(keys)
353
+ id = options.delete(:id) || id_for(keys)
354
+ klass = class_for(keys, options.delete(:class))
355
+ error = error_for(keys, options.delete(:error))
359
356
 
360
- value = escape_html(value)
357
+ value =
358
+ if block.nil? and !options.has_key?(:value)
359
+ value_for(attributes, keys)
360
+ else
361
+ block ? block.call(attributes.get(keys)) : options.delete(:value)
362
+ end
361
363
 
362
- textarea_(options_for(options, :name => name, :class => klass, :id => id, :data_error => error)){ value }
363
- end
364
+ value = escape_html(value)
364
365
 
365
- def select(*args, &block)
366
- options = args.extract_options!.to_options!
367
- keys = args.flatten
366
+ textarea_(options_for(options, :name => name, :class => klass, :id => id, :data_error => error)){ value }
367
+ end
368
368
 
369
- name = options.delete(:name) || name_for(keys)
370
- values = options.delete(:values) || options.delete(:options) || options.delete(:from)
369
+ def select(*args, &block)
370
+ options = args.extract_options!.to_options!
371
+ keys = scope(args)
371
372
 
372
- has_blank = options.has_key?(:blank) && options[:blank] != false
373
- blank = options.delete(:blank)
373
+ name = options.delete(:name) || name_for(keys)
374
+ values = options.delete(:values) || options.delete(:options) || options.delete(:from)
374
375
 
375
- id = options.delete(:id) || id_for(keys)
376
- klass = class_for(keys, options.delete(:class))
377
- error = error_for(keys, options.delete(:error))
376
+ has_blank = options.has_key?(:blank) && options[:blank] != false
377
+ blank = options.delete(:blank)
378
378
 
379
- if values.nil?
380
- key = keys.map{|key| "#{ key }"}
381
- key.last << "_options"
382
- values = attributes.get(*key) if attributes.has?(*key)
383
- end
379
+ id = options.delete(:id) || id_for(keys)
380
+ klass = class_for(keys, options.delete(:class))
381
+ error = error_for(keys, options.delete(:error))
384
382
 
385
- if options[:multiple]
386
- name += '[]'
387
- end
383
+ if values.nil?
384
+ key = keys.map{|key| "#{ key }"}
385
+ key.last << "_options"
386
+ values = attributes.get(*key) if attributes.has?(*key)
387
+ end
388
388
 
389
- list = Array(values).map{|value| value.dup rescue value} # ensure list is dup'd
389
+ if options[:multiple]
390
+ name += '[]'
391
+ end
390
392
 
391
- case list.first
392
- when Hash, Array
393
- nil
394
- else
395
- list.flatten!
396
- list.compact!
397
- list.map!{|element| [element, element]}
398
- end
393
+ list = Array(values).map{|value| value.dup rescue value} # ensure list is dup'd
399
394
 
400
- if has_blank
401
- case blank
402
- when false
403
- blank = nil
404
- when nil, true
405
- blank = [nil, nil]
395
+ case list.first
396
+ when Hash, Array
397
+ nil
406
398
  else
407
- blank = [Array(blank).first, '']
399
+ list.flatten!
400
+ list.compact!
401
+ list.map!{|element| [element, element]}
408
402
  end
409
- end
410
403
 
411
- selected_value =
412
- if options.has_key?(:selected)
413
- options.delete(:selected)
414
- else
415
- attributes.get(keys)
404
+ if has_blank
405
+ case blank
406
+ when false
407
+ blank = nil
408
+ when nil, true
409
+ blank = [nil, nil]
410
+ else
411
+ blank = [Array(blank).first, '']
412
+ end
416
413
  end
417
414
 
418
- selected_values = {}
415
+ selected_value =
416
+ if options.has_key?(:selected)
417
+ options.delete(:selected)
418
+ else
419
+ attributes.get(keys)
420
+ end
419
421
 
420
- Array(selected_value).flatten.compact.each do |val|
421
- selected_values[val.to_s] = true
422
- end
422
+ selected_values = {}
423
423
 
424
- select_(options_for(options, :name => name, :class => klass, :id => id, :data_error => error)){
425
- if blank
426
- content = blank.first || ''
427
- value = blank.last
428
- value.nil? ? option_(){ content } : option_(:value => value){ content }
424
+ Array(selected_value).flatten.compact.each do |val|
425
+ selected_values[val.to_s] = true
429
426
  end
430
427
 
431
- unless list.empty?
432
- list.each do |pair|
433
- returned = block ? Dao.call(block, :call, pair.first, pair.last, selected_value) : pair
434
-
435
- opts = Map.new
436
- selected = nil
437
-
438
- case returned
439
- when Array
440
- content, value, selected, *ignored = returned
441
- if value.is_a?(Hash)
442
- map = Map.for(value)
443
- value = map.delete(:value)
444
- selected = map.delete(:selected)
445
- opts.update(map)
446
- end
447
-
448
- when Hash
449
- content = returned[:content]
450
- value = returned[:value]
451
- selected = returned[:selected]
452
-
453
- else
454
- content = returned
455
- value = returned
456
- selected = nil
457
- end
428
+ select_(options_for(options, :name => name, :class => klass, :id => id, :data_error => error)){
429
+ if blank
430
+ content = blank.first || ''
431
+ value = blank.last
432
+ value.nil? ? option_(){ content } : option_(:value => value){ content }
433
+ end
458
434
 
459
- if selected.nil?
460
- selected = selected_values.has_key?(value.to_s)
435
+ unless list.empty?
436
+ list.each do |pair|
437
+ returned = block ? Dao.call(block, :call, pair.first, pair.last, selected_value) : pair
438
+
439
+ opts = Map.new
440
+ selected = nil
441
+
442
+ case returned
443
+ when Array
444
+ content, value, selected, *ignored = returned
445
+ if value.is_a?(Hash)
446
+ map = Map.for(value)
447
+ value = map.delete(:value)
448
+ selected = map.delete(:selected)
449
+ opts.update(map)
450
+ end
451
+
452
+ when Hash
453
+ content = returned[:content]
454
+ value = returned[:value]
455
+ selected = returned[:selected]
456
+
457
+ else
458
+ content = returned
459
+ value = returned
460
+ selected = nil
461
+ end
462
+
463
+ if selected.nil?
464
+ selected = selected_values.has_key?(value.to_s)
465
+ end
466
+
467
+ opts[:value] = (value.nil? ? content : value)
468
+ opts[:selected] = Coerce.boolean(selected) if selected
469
+
470
+ option_(opts){ content }
461
471
  end
462
-
463
- opts[:value] = (value.nil? ? content : value)
464
- opts[:selected] = Coerce.boolean(selected) if selected
465
-
466
- option_(opts){ content }
467
472
  end
468
- end
469
- }
470
- end
473
+ }
474
+ end
471
475
 
472
- def upload(*args, &block)
473
- options = args.extract_options!.to_options!
474
- keys = args.flatten
476
+ def upload(*args, &block)
477
+ options = args.extract_options!.to_options!
478
+ keys = scope(args)
475
479
 
476
- cache_key = keys + [:cache]
477
- file_key = keys + [:file]
480
+ cache_key = keys + [:cache]
481
+ file_key = keys + [:file]
478
482
 
479
- cache_name = options.delete(:cache_name) || name_for(cache_key)
480
- file_name = options.delete(:file_name) || options.delete(:name) || name_for(file_key)
483
+ cache_name = options.delete(:cache_name) || name_for(cache_key)
484
+ file_name = options.delete(:file_name) || options.delete(:name) || name_for(file_key)
481
485
 
482
- id = options.delete(:id) || id_for(keys)
483
- klass = class_for(keys, options.delete(:class))
484
- error = error_for(keys, options.delete(:error))
486
+ id = options.delete(:id) || id_for(keys)
487
+ klass = class_for(keys, options.delete(:class))
488
+ error = error_for(keys, options.delete(:error))
485
489
 
486
- cache_value = attributes.get(cache_key)
490
+ cache_value = attributes.get(cache_key)
487
491
 
488
- tagz{
489
- input_(:name => cache_name, :value => cache_value, :type => :hidden){ }
492
+ tagz{
493
+ input_(:name => cache_name, :value => cache_value, :type => :hidden){ }
490
494
 
491
- __
495
+ __
492
496
 
493
- input_(options_for(options, :name => file_name, :class => klass, :id => id, :data_error => error, :type => :file)){ }
494
- }
497
+ input_(options_for(options, :name => file_name, :class => klass, :id => id, :data_error => error, :type => :file)){ }
498
+ }
499
+ end
495
500
  end
501
+ include Elements
496
502
 
497
503
  # html generation support methods
498
504
  #
@@ -540,7 +546,7 @@ module Dao
540
546
  value
541
547
  end
542
548
 
543
- escape_html(value)
549
+ value.to_s
544
550
  end
545
551
 
546
552
  def escape_html(string)
@@ -576,6 +582,38 @@ module Dao
576
582
  Form.name_for(name, *keys)
577
583
  end
578
584
 
585
+ def scope(*keys, &block)
586
+ if block.nil?
587
+ return [@scope, *keys].flatten.compact
588
+ end
589
+
590
+ #attributes = self.attributes
591
+ #errors = self.errors
592
+
593
+ scope = @scope
594
+ @scope = Coerce.list_of_strings(keys)
595
+
596
+ #@attributes = Map.for(attributes.get(*@scope))
597
+ #@errors = Errors.new.tap{|e| e.update(errors.get(*@scope))}
598
+
599
+ #p '@scope' => @scope
600
+ #p '@errors' => @errors
601
+ #p '@attributes' => @attributes
602
+ #p 'errors' => errors
603
+ #p 'attributes' => attributes
604
+ #puts
605
+ #abort
606
+ begin
607
+ argv = block.arity == 0 ? [@scope] : []
608
+ block.call(*argv)
609
+ ensure
610
+ @scope = scope
611
+ #@attributes = attributes
612
+ #@errors = errors
613
+ end
614
+ end
615
+ alias_method(:scope_for, :scope)
616
+
579
617
  def options_for(*hashes)
580
618
  map = Map.new
581
619
 
@@ -12,6 +12,36 @@ Testing Dao::Form do
12
12
  assert{ new_named_form(:foo).name_for(:a, :b) == 'dao[foo][a.b]' }
13
13
  end
14
14
 
15
+ testing 'scope_for' do
16
+ form = new_form()
17
+
18
+ assert do
19
+ html = form.input(:bar)
20
+ scmp(
21
+ html,
22
+ '<input type="text" name="dao[form][bar]" class="dao" id="form_bar"/>'
23
+ )
24
+ end
25
+
26
+ assert do
27
+ form.scope_for(:foo) do
28
+ html = form.input(:bar)
29
+ scmp(
30
+ html,
31
+ '<input type="text" name="dao[form][foo.bar]" class="dao" id="form_foo-bar"/>'
32
+ )
33
+ end
34
+ end
35
+
36
+ assert do
37
+ html = form.input(:bar)
38
+ scmp(
39
+ html,
40
+ '<input type="text" name="dao[form][bar]" class="dao" id="form_bar"/>'
41
+ )
42
+ end
43
+ end
44
+
15
45
  testing 'Form#select' do
16
46
  #
17
47
  form = new_form()
metadata CHANGED
@@ -1,156 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dao
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 5.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ara T. Howard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-14 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ! '>='
18
- - !ruby/object:Gem::Version
19
- version: '3.1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '3.1'
27
- - !ruby/object:Gem::Dependency
28
- name: map
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: 6.0.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: 6.0.0
41
- - !ruby/object:Gem::Dependency
42
- name: fattr
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '2.2'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '2.2'
55
- - !ruby/object:Gem::Dependency
56
- name: coerce
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: 0.0.3
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: 0.0.3
69
- - !ruby/object:Gem::Dependency
70
- name: tagz
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ! '>='
74
- - !ruby/object:Gem::Version
75
- version: 9.9.2
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ! '>='
81
- - !ruby/object:Gem::Version
82
- version: 9.9.2
83
- - !ruby/object:Gem::Dependency
84
- name: multi_json
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: 1.0.3
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ! '>='
95
- - !ruby/object:Gem::Version
96
- version: 1.0.3
97
- - !ruby/object:Gem::Dependency
98
- name: uuidtools
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ! '>='
102
- - !ruby/object:Gem::Version
103
- version: 2.1.2
104
- type: :runtime
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: 2.1.2
111
- - !ruby/object:Gem::Dependency
112
- name: wrap
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: 1.5.0
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ! '>='
123
- - !ruby/object:Gem::Version
124
- version: 1.5.0
125
- - !ruby/object:Gem::Dependency
126
- name: rails_current
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ! '>='
130
- - !ruby/object:Gem::Version
131
- version: 1.8.0
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ! '>='
137
- - !ruby/object:Gem::Version
138
- version: 1.8.0
139
- - !ruby/object:Gem::Dependency
140
- name: rails_errors2html
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ! '>='
144
- - !ruby/object:Gem::Version
145
- version: 1.3.0
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ! '>='
151
- - !ruby/object:Gem::Version
152
- version: 1.3.0
153
- description: ! 'description: dao kicks the ass'
11
+ date: 2014-02-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: presenter, conducer, api, and better form objects for you rails' pleasure
154
14
  email: ara.t.howard@gmail.com
155
15
  executables: []
156
16
  extensions: []
@@ -160,6 +20,7 @@ files:
160
20
  - Gemfile.lock
161
21
  - README
162
22
  - Rakefile
23
+ - a.rb
163
24
  - dao.gemspec
164
25
  - lib/dao.rb
165
26
  - lib/dao/active_record.rb
@@ -231,7 +92,8 @@ files:
231
92
  - test/testing.rb
232
93
  - test/validations_test.rb
233
94
  homepage: https://github.com/ahoward/dao
234
- licenses: []
95
+ licenses:
96
+ - same as ruby's
235
97
  metadata: {}
236
98
  post_install_message:
237
99
  rdoc_options: []