informant 0.7.1 → 0.7.2
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.
- data/CHANGELOG.rdoc +5 -0
- data/Rakefile +4 -36
- data/VERSION +1 -1
- data/lib/informant.rb +71 -62
- data/test/test_helper.rb +2 -1
- metadata +15 -23
- data/informant.gemspec +0 -52
data/CHANGELOG.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,21 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "informant"
|
8
|
-
gem.summary = %Q{A full-featured form builder for Rails.}
|
9
|
-
gem.description = %Q{Informant is a full-featured form builder for Ruby on Rails which promotes a simple syntax that keeps your views clean. Everything about a field (label, description, error display, etc) is encapsulated in a single method call.}
|
10
|
-
gem.email = "alex@alexreisner.com"
|
11
|
-
gem.homepage = "http://github.com/alexreisner/informant"
|
12
|
-
gem.authors = ["Alex Reisner"]
|
13
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
-
end
|
15
|
-
Jeweler::GemcutterTasks.new
|
16
|
-
rescue LoadError
|
17
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
-
end
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
19
3
|
|
20
4
|
require 'rake/testtask'
|
21
5
|
Rake::TestTask.new(:test) do |test|
|
@@ -24,21 +8,6 @@ Rake::TestTask.new(:test) do |test|
|
|
24
8
|
test.verbose = true
|
25
9
|
end
|
26
10
|
|
27
|
-
begin
|
28
|
-
require 'rcov/rcovtask'
|
29
|
-
Rcov::RcovTask.new do |test|
|
30
|
-
test.libs << 'test'
|
31
|
-
test.pattern = 'test/**/*_test.rb'
|
32
|
-
test.verbose = true
|
33
|
-
end
|
34
|
-
rescue LoadError
|
35
|
-
task :rcov do
|
36
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
task :test => :check_dependencies
|
41
|
-
|
42
11
|
task :default => :test
|
43
12
|
|
44
13
|
require 'rake/rdoctask'
|
@@ -50,8 +19,7 @@ Rake::RDocTask.new do |rdoc|
|
|
50
19
|
end
|
51
20
|
|
52
21
|
rdoc.rdoc_dir = 'rdoc'
|
53
|
-
rdoc.title = "
|
54
|
-
rdoc.rdoc_files.include('
|
22
|
+
rdoc.title = "informant #{version}"
|
23
|
+
rdoc.rdoc_files.include('*.rdoc')
|
55
24
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
25
|
end
|
57
|
-
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.2
|
data/lib/informant.rb
CHANGED
@@ -40,11 +40,11 @@ module Informant
|
|
40
40
|
# Displays fields in a <div>, label on one line, field below it.
|
41
41
|
#
|
42
42
|
class Standard < ActionView::Helpers::FormBuilder
|
43
|
-
|
43
|
+
|
44
44
|
# Declare some options as custom (don't pass to built-in form helpers).
|
45
45
|
@@custom_field_options = [:label, :required, :description, :decoration]
|
46
46
|
@@custom_label_options = [:required, :colon, :label_for]
|
47
|
-
|
47
|
+
|
48
48
|
@@custom_options = @@custom_field_options + @@custom_label_options
|
49
49
|
|
50
50
|
# Run already-defined helpers through our "shell".
|
@@ -54,20 +54,20 @@ module Informant
|
|
54
54
|
helpers.each do |h|
|
55
55
|
define_method h do |field, *args|
|
56
56
|
options = args.detect { |a| a.is_a?(Hash) } || {}
|
57
|
-
case h
|
58
|
-
when 'check_box'
|
57
|
+
case h
|
58
|
+
when 'check_box'
|
59
59
|
template = "check_box_field"
|
60
60
|
options[:colon] = false
|
61
|
-
when 'radio_button'
|
61
|
+
when 'radio_button'
|
62
62
|
template = "radio_button_choice"
|
63
63
|
options[:colon] = false
|
64
64
|
else
|
65
65
|
template = "default_field"
|
66
66
|
end
|
67
|
-
build_shell(field, options, template) { super }
|
67
|
+
build_shell(field, options, template) { super(field, *args) }
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
##
|
72
72
|
# Render a set of radio buttons. Takes a method name, an array of
|
73
73
|
# choices (just like a +select+ field), and an Informant options hash.
|
@@ -79,7 +79,7 @@ module Informant
|
|
79
79
|
:label_for => [object_name, method, c[1].to_s.downcase].join('_') }
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
##
|
84
84
|
# Render a set of check boxes for selecting HABTM-associated objects.
|
85
85
|
# Takes a method name (eg, category_ids), an array of
|
@@ -87,17 +87,17 @@ module Informant
|
|
87
87
|
# In the default template the check boxes are enclosed in a <div> with
|
88
88
|
# CSS class <tt>habtm_check_boxes</tt> which can be styled thusly to
|
89
89
|
# achieve a scrolling list:
|
90
|
-
#
|
90
|
+
#
|
91
91
|
# .habtm_check_boxes {
|
92
92
|
# overflow: auto;
|
93
93
|
# height: 150px;
|
94
94
|
# }
|
95
|
-
#
|
95
|
+
#
|
96
96
|
# A hidden field is included which eliminates the need to handle the
|
97
97
|
# no-boxes-checked case in the controller, for example:
|
98
|
-
#
|
98
|
+
#
|
99
99
|
# <input type="hidden" name="article[categories][]" value="" />
|
100
|
-
#
|
100
|
+
#
|
101
101
|
# This ensures that un-checking all boxes will work as expected.
|
102
102
|
# Unfortunately the check_box template is not applied to each check box
|
103
103
|
# (because the standard method of querying the @object for the field's
|
@@ -113,17 +113,17 @@ module Informant
|
|
113
113
|
build_shell(method, options, "habtm_check_boxes_field") do
|
114
114
|
choices.map do |c|
|
115
115
|
field_id = "#{base_id}_#{c[1].to_s.downcase}"
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
habtm_single_check_box_template(
|
117
|
+
:name => "#{base_name}[]",
|
118
|
+
:id => field_id,
|
119
|
+
:value => c[1],
|
120
|
+
:checked => @object.send(method).include?(c[1]),
|
121
|
+
:label => @template.label_tag(field_id, c[0])
|
122
|
+
)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
##
|
128
128
|
# Standard Rails date selector.
|
129
129
|
#
|
@@ -132,9 +132,9 @@ module Informant
|
|
132
132
|
options[:start_year] ||= 1801
|
133
133
|
options[:end_year] ||= Time.now.year
|
134
134
|
options[:label_for] = "#{object_name}_#{method}_1i"
|
135
|
-
|
135
|
+
build_shell(method, options) { super }
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
##
|
139
139
|
# This differs from the Rails-default date_select in that it
|
140
140
|
# submits three distinct fields for storage in three separate attributes.
|
@@ -148,16 +148,16 @@ module Informant
|
|
148
148
|
options[:end_year] ||= Time.now.year
|
149
149
|
options[:prefix] = object_name # for date helpers
|
150
150
|
options[:label_for] = "#{object_name}_#{method}_y"
|
151
|
-
|
151
|
+
build_shell(method, options) do
|
152
152
|
[['y', 'year'], ['m', 'month'], ['d', 'day']].map{ |p|
|
153
153
|
i,j = p
|
154
154
|
value = @object.send(method.to_s + '_' + i)
|
155
155
|
options[:field_name] = method.to_s + '_' + i
|
156
156
|
eval("@template.select_#{j}(#{value.inspect}, options)")
|
157
157
|
}.join(' ')
|
158
|
-
|
158
|
+
end
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
##
|
162
162
|
# Year select field. Takes options <tt>:start_year</tt> and
|
163
163
|
# <tt>:end_year</tt>, and <tt>:step</tt>.
|
@@ -167,7 +167,7 @@ module Informant
|
|
167
167
|
options[:last] = options[:end_year] || Date.today.year
|
168
168
|
integer_select(method, options)
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
##
|
172
172
|
# Integer select field.
|
173
173
|
# Takes options <tt>:first</tt>, <tt>:last</tt>, and <tt>:step</tt>.
|
@@ -179,9 +179,9 @@ module Informant
|
|
179
179
|
choices << n if i % options[:step] == 0
|
180
180
|
i += 1
|
181
181
|
end
|
182
|
-
|
182
|
+
select method, choices, options
|
183
183
|
end
|
184
|
-
|
184
|
+
|
185
185
|
##
|
186
186
|
# Submit button with smart default text (if +value+ is nil uses "Create"
|
187
187
|
# for new record or "Update" for old record).
|
@@ -203,13 +203,13 @@ module Informant
|
|
203
203
|
options.delete :colon
|
204
204
|
options.delete :label_for
|
205
205
|
options.delete :required
|
206
|
-
|
206
|
+
|
207
207
|
text = @template.send(:h, text.blank?? method.to_s.humanize : text.to_s)
|
208
208
|
text << ':'.html_safe if colon
|
209
209
|
text << @template.content_tag(:span, "*", :class => "required") if required
|
210
210
|
super
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
##
|
214
214
|
# Render a field set (HTML <fieldset>). Takes the legend (optional), an
|
215
215
|
# options hash, and a block in which fields are rendered.
|
@@ -220,8 +220,8 @@ module Informant
|
|
220
220
|
@template.capture(&block)
|
221
221
|
end
|
222
222
|
end
|
223
|
-
|
224
|
-
|
223
|
+
|
224
|
+
|
225
225
|
private # ---------------------------------------------------------------
|
226
226
|
|
227
227
|
##
|
@@ -231,14 +231,14 @@ module Informant
|
|
231
231
|
|
232
232
|
# Build new options hash for custom label options.
|
233
233
|
label_options = options.reject{ |i,j| !@@custom_label_options.include? i }
|
234
|
-
|
234
|
+
|
235
235
|
# Build new options hash for custom field options.
|
236
236
|
field_options = options.reject{ |i,j| !@@custom_field_options.include? i }
|
237
237
|
|
238
238
|
# Remove custom options from options hash so things like
|
239
239
|
# <tt>include_blank</tt> aren't added as HTML attributes.
|
240
240
|
options.reject!{ |i,j| @@custom_options.include? i }
|
241
|
-
|
241
|
+
|
242
242
|
locals = {
|
243
243
|
:element => yield,
|
244
244
|
:label => label(method, field_options[:label], label_options),
|
@@ -249,30 +249,30 @@ module Informant
|
|
249
249
|
}
|
250
250
|
send("#{template}_template", locals).html_safe
|
251
251
|
end
|
252
|
-
|
252
|
+
|
253
253
|
##
|
254
254
|
# Render default field template.
|
255
255
|
#
|
256
256
|
def default_field_template(l = {})
|
257
257
|
<<-END
|
258
258
|
<div id="#{l[:div_id]}" class="field">
|
259
|
-
|
259
|
+
#{l[:label]}<br />
|
260
260
|
#{l[:element]}#{l[:decoration]}
|
261
261
|
#{"<p class=\"field_description\">#{l[:description]}</p>" unless l[:description].blank?}
|
262
|
-
|
263
|
-
|
262
|
+
</div>
|
263
|
+
END
|
264
264
|
end
|
265
|
-
|
265
|
+
|
266
266
|
##
|
267
267
|
# Render check box field template.
|
268
268
|
#
|
269
269
|
def check_box_field_template(l = {})
|
270
270
|
<<-END
|
271
271
|
<div id="#{l[:div_id]}" class="field">
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
272
|
+
#{l[:element]} #{l[:label]} #{l[:decoration]}<br />
|
273
|
+
#{"<p class=\"field_description\">#{l[:description]}</p>" unless l[:description].blank?}
|
274
|
+
</div>
|
275
|
+
END
|
276
276
|
end
|
277
277
|
|
278
278
|
##
|
@@ -283,7 +283,7 @@ module Informant
|
|
283
283
|
def radio_button_choice_template(l = {})
|
284
284
|
<<-END
|
285
285
|
#{l[:element]} #{l[:label]}
|
286
|
-
|
286
|
+
END
|
287
287
|
end
|
288
288
|
|
289
289
|
##
|
@@ -299,11 +299,20 @@ module Informant
|
|
299
299
|
def habtm_check_boxes_field_template(l = {})
|
300
300
|
<<-END
|
301
301
|
<div id="#{l[:div_id]}" class="field">
|
302
|
-
|
303
|
-
<div class="habtm_check_boxes">#{l[:element]}</div>#{l[:decoration]}
|
302
|
+
#{l[:label]}<br />
|
303
|
+
<div class="habtm_check_boxes">#{l[:element].join}</div>#{l[:decoration]}
|
304
304
|
#{"<p class=\"field_description\">#{l[:description]}</p>" unless l[:description].blank?}
|
305
|
-
|
306
|
-
|
305
|
+
</div>
|
306
|
+
END
|
307
|
+
end
|
308
|
+
|
309
|
+
##
|
310
|
+
# Render a single check box in a HABTM set.
|
311
|
+
#
|
312
|
+
def habtm_single_check_box_template(l = {})
|
313
|
+
<<-END
|
314
|
+
<div class="habtm_single_check_box"><input type="checkbox" name="#{l[:name]}" id="#{l[:id]}" value="#{l[:value]}" #{'checked="checked"' if l[:checked]}} /> #{l[:label]}</div>
|
315
|
+
END
|
307
316
|
end
|
308
317
|
|
309
318
|
##
|
@@ -312,16 +321,16 @@ module Informant
|
|
312
321
|
def submit_button_template(l = {})
|
313
322
|
<<-END
|
314
323
|
<div class="button">#{l[:element]}</div>
|
315
|
-
|
324
|
+
END
|
316
325
|
end
|
317
326
|
end
|
318
327
|
|
319
|
-
|
328
|
+
|
320
329
|
##
|
321
330
|
# Displays fields with no surrounding HTML containers.
|
322
331
|
#
|
323
332
|
class Simple < Standard
|
324
|
-
|
333
|
+
|
325
334
|
private # ---------------------------------------------------------------
|
326
335
|
|
327
336
|
##
|
@@ -330,7 +339,7 @@ module Informant
|
|
330
339
|
def default_field_template(l = {})
|
331
340
|
"#{l[:element]}#{l[:decoration]}"
|
332
341
|
end
|
333
|
-
|
342
|
+
|
334
343
|
##
|
335
344
|
# Render check box field template.
|
336
345
|
#
|
@@ -345,14 +354,14 @@ module Informant
|
|
345
354
|
l[:element]
|
346
355
|
end
|
347
356
|
end
|
348
|
-
|
349
|
-
|
357
|
+
|
358
|
+
|
350
359
|
##
|
351
360
|
# Displays fields in table rows: label in first column, field (with
|
352
361
|
# description and decoration) in second.
|
353
362
|
#
|
354
363
|
class Table < Standard
|
355
|
-
|
364
|
+
|
356
365
|
private # ---------------------------------------------------------------
|
357
366
|
|
358
367
|
##
|
@@ -361,13 +370,13 @@ module Informant
|
|
361
370
|
def default_field_template(l = {})
|
362
371
|
<<-END
|
363
372
|
<tr id="#{l[:div_id]}" class="field">
|
364
|
-
|
373
|
+
<td>#{l[:label]}</td>
|
365
374
|
<td>#{l[:element]}#{l[:decoration]}
|
366
375
|
#{"<p class=\"field_description\">#{l[:description]}</p>" unless l[:description].blank?}</td>
|
367
|
-
|
368
|
-
|
376
|
+
</tr>
|
377
|
+
END
|
369
378
|
end
|
370
|
-
|
379
|
+
|
371
380
|
##
|
372
381
|
# Render check box field template.
|
373
382
|
#
|
@@ -381,10 +390,10 @@ module Informant
|
|
381
390
|
def submit_button_template(l = {})
|
382
391
|
<<-END
|
383
392
|
<tr id="#{l[:div_id]}" class="field">
|
384
|
-
|
393
|
+
<td></td>
|
385
394
|
<td class="button">#{l[:element]}</td>
|
386
|
-
|
387
|
-
|
395
|
+
</tr>
|
396
|
+
END
|
388
397
|
end
|
389
398
|
end
|
390
399
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'test/unit'
|
2
3
|
#require 'active_support'
|
3
4
|
#require 'active_support/test_case'
|
4
5
|
require 'action_controller'
|
5
6
|
#require 'action_view'
|
6
7
|
#require 'action_view/test_case'
|
7
|
-
require 'test_help'
|
8
|
+
#require 'test_help'
|
8
9
|
require 'informant'
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: informant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 7
|
8
|
-
- 1
|
9
|
-
version: 0.7.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.7.2
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Alex Reisner
|
@@ -14,19 +10,19 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-04-11 00:00:00 -04:00
|
18
14
|
default_executable:
|
19
15
|
dependencies: []
|
20
16
|
|
21
17
|
description: Informant is a full-featured form builder for Ruby on Rails which promotes a simple syntax that keeps your views clean. Everything about a field (label, description, error display, etc) is encapsulated in a single method call.
|
22
|
-
email:
|
18
|
+
email:
|
19
|
+
- alex@alexreisner.com
|
23
20
|
executables: []
|
24
21
|
|
25
22
|
extensions: []
|
26
23
|
|
27
|
-
extra_rdoc_files:
|
28
|
-
|
29
|
-
- README.rdoc
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
30
26
|
files:
|
31
27
|
- .document
|
32
28
|
- .gitignore
|
@@ -35,7 +31,6 @@ files:
|
|
35
31
|
- README.rdoc
|
36
32
|
- Rakefile
|
37
33
|
- VERSION
|
38
|
-
- informant.gemspec
|
39
34
|
- lib/informant.rb
|
40
35
|
- test/informant_test.rb
|
41
36
|
- test/test_helper.rb
|
@@ -44,31 +39,28 @@ homepage: http://github.com/alexreisner/informant
|
|
44
39
|
licenses: []
|
45
40
|
|
46
41
|
post_install_message:
|
47
|
-
rdoc_options:
|
48
|
-
|
42
|
+
rdoc_options: []
|
43
|
+
|
49
44
|
require_paths:
|
50
45
|
- lib
|
51
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
52
48
|
requirements:
|
53
49
|
- - ">="
|
54
50
|
- !ruby/object:Gem::Version
|
55
|
-
segments:
|
56
|
-
- 0
|
57
51
|
version: "0"
|
58
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
59
54
|
requirements:
|
60
55
|
- - ">="
|
61
56
|
- !ruby/object:Gem::Version
|
62
|
-
segments:
|
63
|
-
- 0
|
64
57
|
version: "0"
|
65
58
|
requirements: []
|
66
59
|
|
67
60
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.
|
61
|
+
rubygems_version: 1.6.2
|
69
62
|
signing_key:
|
70
63
|
specification_version: 3
|
71
|
-
summary:
|
72
|
-
test_files:
|
73
|
-
|
74
|
-
- test/informant_test.rb
|
64
|
+
summary: Form-building library for Rails.
|
65
|
+
test_files: []
|
66
|
+
|
data/informant.gemspec
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{informant}
|
8
|
-
s.version = "0.7.1"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Alex Reisner"]
|
12
|
-
s.date = %q{2010-06-01}
|
13
|
-
s.description = %q{Informant is a full-featured form builder for Ruby on Rails which promotes a simple syntax that keeps your views clean. Everything about a field (label, description, error display, etc) is encapsulated in a single method call.}
|
14
|
-
s.email = %q{alex@alexreisner.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"CHANGELOG.rdoc",
|
23
|
-
"LICENSE",
|
24
|
-
"README.rdoc",
|
25
|
-
"Rakefile",
|
26
|
-
"VERSION",
|
27
|
-
"informant.gemspec",
|
28
|
-
"lib/informant.rb",
|
29
|
-
"test/informant_test.rb",
|
30
|
-
"test/test_helper.rb"
|
31
|
-
]
|
32
|
-
s.homepage = %q{http://github.com/alexreisner/informant}
|
33
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
-
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.6}
|
36
|
-
s.summary = %q{A full-featured form builder for Rails.}
|
37
|
-
s.test_files = [
|
38
|
-
"test/test_helper.rb",
|
39
|
-
"test/informant_test.rb"
|
40
|
-
]
|
41
|
-
|
42
|
-
if s.respond_to? :specification_version then
|
43
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
-
s.specification_version = 3
|
45
|
-
|
46
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
-
else
|
48
|
-
end
|
49
|
-
else
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|