ccls-common_lib 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +116 -0
- data/lib/ccls-common_lib.rb +1 -0
- data/lib/common_lib.rb +37 -0
- data/lib/common_lib/action_controller_extension.rb +8 -0
- data/lib/common_lib/action_controller_extension/accessible_via_protocol.rb +405 -0
- data/lib/common_lib/action_controller_extension/accessible_via_user.rb +605 -0
- data/lib/common_lib/action_controller_extension/routing.rb +20 -0
- data/lib/common_lib/action_controller_extension/test_case.rb +22 -0
- data/lib/common_lib/action_view_extension.rb +3 -0
- data/lib/common_lib/action_view_extension/base.rb +310 -0
- data/lib/common_lib/action_view_extension/form_builder.rb +197 -0
- data/lib/common_lib/active_model.rb +4 -0
- data/lib/common_lib/active_model/errors.rb +16 -0
- data/lib/common_lib/active_model/validations/absence.rb +78 -0
- data/lib/common_lib/active_model/validations/complete_date.rb +138 -0
- data/lib/common_lib/active_model/validations/past_date.rb +121 -0
- data/lib/common_lib/active_record.rb +1 -0
- data/lib/common_lib/active_record/base.rb +129 -0
- data/lib/common_lib/active_support_extension.rb +12 -0
- data/lib/common_lib/active_support_extension/assertions.rb +108 -0
- data/lib/common_lib/active_support_extension/associations.rb +154 -0
- data/lib/common_lib/active_support_extension/attributes.rb +296 -0
- data/lib/common_lib/active_support_extension/pending.rb +115 -0
- data/lib/common_lib/active_support_extension/test_case.rb +203 -0
- data/lib/common_lib/railtie.rb +48 -0
- data/lib/common_lib/ruby.rb +8 -0
- data/lib/common_lib/ruby/array.rb +128 -0
- data/lib/common_lib/ruby/fixnum.rb +5 -0
- data/lib/common_lib/ruby/hash.rb +51 -0
- data/lib/common_lib/ruby/integer.rb +11 -0
- data/lib/common_lib/ruby/nil_class.rb +13 -0
- data/lib/common_lib/ruby/numeric.rb +0 -0
- data/lib/common_lib/ruby/object.rb +53 -0
- data/lib/common_lib/ruby/string.rb +20 -0
- data/lib/common_lib/translation_table.rb +129 -0
- data/lib/tasks/common_lib.rake +10 -0
- data/lib/tasks/csv.rake +0 -0
- data/lib/tasks/database.rake +229 -0
- data/lib/tasks/rcov.rake +52 -0
- data/vendor/assets/javascripts/common_lib.js +77 -0
- data/vendor/assets/stylesheets/common_lib.css +71 -0
- metadata +84 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
module CommonLib::ActionControllerExtension::Routing
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
def assert_no_route(verb,action,args={})
|
10
|
+
test "#{brand}no route to #{verb} #{action} #{args.inspect}" do
|
11
|
+
assert_raise(ActionController::RoutingError){
|
12
|
+
send(verb,action,args)
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end # module ClassMethods
|
18
|
+
end # module CommonLib::ActionControllerExtension::Routing
|
19
|
+
ActionController::TestCase.send(:include,
|
20
|
+
CommonLib::ActionControllerExtension::Routing)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module CommonLib::ActionControllerExtension::TestCase
|
2
|
+
|
3
|
+
# def turn_https_on
|
4
|
+
# @request.env['HTTPS'] = 'on'
|
5
|
+
## @request.env['HTTP_X_FORWARDED_PROTO'] == 'https'
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# def turn_https_off
|
9
|
+
# @request.env['HTTPS'] = nil
|
10
|
+
# end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Apparently, I don't use this?
|
14
|
+
#
|
15
|
+
# def assert_layout(layout)
|
16
|
+
# layout = "layouts/#{layout}" unless layout.match(/^layouts/)
|
17
|
+
# assert_equal layout, @response.layout
|
18
|
+
# end
|
19
|
+
|
20
|
+
end # module CommonLib::ActionControllerExtension::TestCase
|
21
|
+
ActionController::TestCase.send(:include,
|
22
|
+
CommonLib::ActionControllerExtension::TestCase)
|
@@ -0,0 +1,310 @@
|
|
1
|
+
module CommonLib::ActionViewExtension::Base
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
# This NEEDS to be HERE or gets stuck at method_missing_without_wrapping call????
|
6
|
+
alias_method_chain( :method_missing, :wrapping )
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Just a simple method to wrap the passed text in a span
|
11
|
+
# with class='required'
|
12
|
+
def required(text)
|
13
|
+
"<span class='required'>#{text}</span>".html_safe
|
14
|
+
end
|
15
|
+
alias_method :req, :required
|
16
|
+
|
17
|
+
def nbsp
|
18
|
+
" ".html_safe
|
19
|
+
end
|
20
|
+
|
21
|
+
def mdy(date)
|
22
|
+
( date.blank? or !date.respond_to?(:strftime) ) ? nbsp : date.strftime("%m/%d/%Y")
|
23
|
+
end
|
24
|
+
|
25
|
+
# For use in CSV output as don't want the
|
26
|
+
def mdy_or_nil(date)
|
27
|
+
( date.blank? or !date.respond_to?(:strftime) ) ? nil : date.strftime("%m/%d/%Y")
|
28
|
+
end
|
29
|
+
|
30
|
+
def mdyhm(datetime)
|
31
|
+
( datetime.blank? or !datetime.respond_to?(:strftime) ) ? nbsp :
|
32
|
+
datetime.strftime("%m/%d/%Y %H:%M (%Z)")
|
33
|
+
end
|
34
|
+
|
35
|
+
# For use in CSV output as don't want the
|
36
|
+
def mdyhm_or_nil(datetime)
|
37
|
+
( datetime.blank? or !datetime.respond_to?(:strftime) ) ? nil :
|
38
|
+
datetime.strftime("%m/%d/%Y %H:%M (%Z)")
|
39
|
+
end
|
40
|
+
|
41
|
+
def time_mdy(time)
|
42
|
+
( time.blank? or !time.respond_to?(:strftime) ) ? nbsp :
|
43
|
+
time.strftime("%I:%M %p %m/%d/%Y")
|
44
|
+
end
|
45
|
+
|
46
|
+
def field_wrapper(method,options={},&block)
|
47
|
+
classes = [method,options[:class]].compact.join(' ')
|
48
|
+
s = "<div class='#{classes} field_wrapper'>\n"
|
49
|
+
s << yield
|
50
|
+
s << "\n</div><!-- class='#{classes}' -->"
|
51
|
+
s.html_safe
|
52
|
+
end
|
53
|
+
|
54
|
+
# t is RedCloth.textualize NOT I18n.translate
|
55
|
+
|
56
|
+
# This is NOT a form field
|
57
|
+
def _wrapped_spans(object_name,method,options={})
|
58
|
+
object = instance_variable_get("@#{object_name}")
|
59
|
+
# s = "<span class='label'>#{options[:label_text]||method}</span>\n"
|
60
|
+
|
61
|
+
# could also "object.class.human_attribute_name method" ?
|
62
|
+
|
63
|
+
# s = "<span class='label'>#{options[:label_text]||I18n.translate(
|
64
|
+
# "#{object.class.to_s.underscore}.#{method}",
|
65
|
+
# :scope => "activerecord.attributes",
|
66
|
+
# :default => method.to_s)}</span>\n" # if method is a symbol, tries to translate it too.
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
#
|
72
|
+
# label = if options[:label_text].present?
|
73
|
+
# options[:label_text]
|
74
|
+
# else
|
75
|
+
# l = ( I18n.translate("#{object.class.to_s.underscore}.#{method}",
|
76
|
+
# :scope => "activerecord.attributes", :raise => true ) rescue false ) ||
|
77
|
+
# method.to_s
|
78
|
+
# l.send( :humanize or :titleize or :gsub('_', ' ') or ......
|
79
|
+
# end
|
80
|
+
#
|
81
|
+
# titleize - capitalizes all words
|
82
|
+
# humanize - capitalizes only the first word ( same as other rails helpers, but I don't like )
|
83
|
+
#
|
84
|
+
#
|
85
|
+
|
86
|
+
s = "<span class='label'>#{options[:label_text] ||
|
87
|
+
( I18n.translate("#{object.class.to_s.underscore}.#{method}",
|
88
|
+
:scope => "activerecord.attributes", :raise => true ) rescue false ) ||
|
89
|
+
method.to_s.humanize }</span>\n" # if method is a symbol, tries to translate it too.
|
90
|
+
|
91
|
+
value = if options[:value]
|
92
|
+
options[:value]
|
93
|
+
else
|
94
|
+
# moved to top
|
95
|
+
# object = instance_variable_get("@#{object_name}")
|
96
|
+
value = object.send(method)
|
97
|
+
value = (value.to_s.blank?)?' ':value
|
98
|
+
end
|
99
|
+
s << "<span class='value'>#{value}</span>"
|
100
|
+
s << (( options.has_key?(:post_text) ) ? "<span class='post_text'>#{options[:post_text]}</span>" : "")
|
101
|
+
s.html_safe
|
102
|
+
end
|
103
|
+
|
104
|
+
def _wrapped_date_spans(object_name,method,options={})
|
105
|
+
object = instance_variable_get("@#{object_name}")
|
106
|
+
_wrapped_spans(object_name,method,options.update(
|
107
|
+
:value => mdy(object.send(method)) ) )
|
108
|
+
end
|
109
|
+
|
110
|
+
def _wrapped_datetime_spans(object_name,method,options={})
|
111
|
+
object = instance_variable_get("@#{object_name}")
|
112
|
+
_wrapped_spans(object_name,method,options.update(
|
113
|
+
:value => mdyhm(object.send(method)) ) )
|
114
|
+
end
|
115
|
+
|
116
|
+
# This is NOT a form field
|
117
|
+
def _wrapped_yes_or_no_spans(object_name,method,options={})
|
118
|
+
object = instance_variable_get("@#{object_name}")
|
119
|
+
_wrapped_spans(object_name,method,options.update(
|
120
|
+
:value => (object.send("#{method}?"))?'Yes':'No') )
|
121
|
+
# s = "<span class='label'>#{options[:label_text]||method}</span>\n"
|
122
|
+
# value = (object.send("#{method}?"))?'Yes':'No'
|
123
|
+
# s << "<span class='value'>#{value}</span>"
|
124
|
+
end
|
125
|
+
|
126
|
+
def method_missing_with_wrapping(symb,*args, &block)
|
127
|
+
method_name = symb.to_s
|
128
|
+
if method_name =~ /^wrapped_(.+)$/
|
129
|
+
unwrapped_method_name = $1
|
130
|
+
#
|
131
|
+
# It'd be nice to be able to genericize all of the
|
132
|
+
# wrapped_* methods since they are all basically
|
133
|
+
# the same.
|
134
|
+
# Strip of the "wrapped_"
|
135
|
+
# Label
|
136
|
+
# Call "unwrapped" method
|
137
|
+
#
|
138
|
+
|
139
|
+
object_name = args[0]
|
140
|
+
method = args[1]
|
141
|
+
|
142
|
+
content = field_wrapper(method,:class => unwrapped_method_name) do
|
143
|
+
s = if respond_to?(unwrapped_method_name)
|
144
|
+
options = args.detect{|i| i.is_a?(Hash) }
|
145
|
+
label_text = options.delete(:label_text) unless options.nil?
|
146
|
+
if unwrapped_method_name == 'check_box'
|
147
|
+
send("#{unwrapped_method_name}",*args,&block) <<
|
148
|
+
label( object_name, method, label_text )
|
149
|
+
else
|
150
|
+
label( object_name, method, label_text ) <<
|
151
|
+
send("#{unwrapped_method_name}",*args,&block)
|
152
|
+
end
|
153
|
+
else
|
154
|
+
send("_#{method_name}",*args,&block)
|
155
|
+
end
|
156
|
+
|
157
|
+
s << (( block_given? )? capture(&block) : '')
|
158
|
+
# send("_#{method_name}",*args) <<
|
159
|
+
# (( block_given? )? capture(&block) : '')
|
160
|
+
end
|
161
|
+
# if block_called_from_erb?(block)
|
162
|
+
# concat(content)
|
163
|
+
# else
|
164
|
+
content
|
165
|
+
# end
|
166
|
+
else
|
167
|
+
method_missing_without_wrapping(symb,*args, &block)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def form_link_to( title, url, options={}, &block )
|
172
|
+
extra_tags = extra_tags_for_form(options)
|
173
|
+
s = "\n" <<
|
174
|
+
"<form " <<
|
175
|
+
"class='#{options.delete(:class)||'form_link_to'}' " <<
|
176
|
+
"action='#{url_for(url)}' " <<
|
177
|
+
"method='#{options.delete('method')}'>\n" <<
|
178
|
+
extra_tags << "\n"
|
179
|
+
s << (( block_given? )? capture(&block) : '')
|
180
|
+
s << submit_tag(title, :name => nil ) << "\n" <<
|
181
|
+
"</form>\n"
|
182
|
+
s.html_safe
|
183
|
+
end
|
184
|
+
|
185
|
+
def destroy_link_to( title, url, options={}, &block )
|
186
|
+
s = form_link_to( title, url, options.merge(
|
187
|
+
'method' => 'delete',
|
188
|
+
:class => 'destroy_link_to'
|
189
|
+
),&block )
|
190
|
+
end
|
191
|
+
|
192
|
+
def aws_image_tag(image,options={})
|
193
|
+
# in console @controller is nil
|
194
|
+
protocol = @controller.try(:request).try(:protocol) || 'http://'
|
195
|
+
host = 's3.amazonaws.com/'
|
196
|
+
# bucket = ( defined?(RAILS_APP_NAME) && RAILS_APP_NAME ) || 'ccls'
|
197
|
+
bucket = ( defined?(RAILS_APP_NAME) && RAILS_APP_NAME ) ||
|
198
|
+
Rails.application.class.parent.to_s.downcase || 'ccls'
|
199
|
+
src = "#{protocol}#{host}#{bucket}/images/#{image}"
|
200
|
+
alt = options.delete(:alt) || options.delete('alt') || image
|
201
|
+
tag('img',options.merge({:src => src, :alt => alt}))
|
202
|
+
end
|
203
|
+
|
204
|
+
def flasher
|
205
|
+
s = ''
|
206
|
+
flash.each do |key, msg|
|
207
|
+
s << content_tag( :p, msg, :id => key, :class => "flash #{key}" )
|
208
|
+
s << "\n"
|
209
|
+
end
|
210
|
+
s << "<noscript><p id='noscript' class='flash'>\n"
|
211
|
+
s << "Javascript is required for this site to be fully functional.\n"
|
212
|
+
s << "</p></noscript>\n"
|
213
|
+
s.html_safe
|
214
|
+
end
|
215
|
+
|
216
|
+
# Created to stop multiple entries of same stylesheet
|
217
|
+
def stylesheets(*args)
|
218
|
+
@stylesheets ||= []
|
219
|
+
args.each do |stylesheet|
|
220
|
+
unless @stylesheets.include?(stylesheet.to_s)
|
221
|
+
@stylesheets.push(stylesheet.to_s)
|
222
|
+
content_for(:head,stylesheet_link_tag(stylesheet.to_s))
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def javascripts(*args)
|
228
|
+
@javascripts ||= []
|
229
|
+
args.each do |javascript|
|
230
|
+
unless @javascripts.include?(javascript.to_s)
|
231
|
+
@javascripts.push(javascript.to_s)
|
232
|
+
content_for(:head,javascript_include_tag(javascript).to_s)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def yndk(value=nil)
|
238
|
+
(YNDK[value]||' ').html_safe
|
239
|
+
end
|
240
|
+
|
241
|
+
def ynodk(value=nil)
|
242
|
+
(YNODK[value]||' ').html_safe
|
243
|
+
end
|
244
|
+
|
245
|
+
def ynrdk(value=nil)
|
246
|
+
(YNRDK[value]||' ').html_safe
|
247
|
+
end
|
248
|
+
|
249
|
+
def ynordk(value=nil)
|
250
|
+
(YNORDK[value]||' ').html_safe
|
251
|
+
end
|
252
|
+
|
253
|
+
def padk(value=nil)
|
254
|
+
(PADK[value]||' ').html_safe
|
255
|
+
end
|
256
|
+
|
257
|
+
def adna(value=nil)
|
258
|
+
(ADNA[value]||' ').html_safe
|
259
|
+
end
|
260
|
+
|
261
|
+
def pos_neg(value=nil)
|
262
|
+
(POSNEG[value]||' ').html_safe
|
263
|
+
end
|
264
|
+
alias_method :posneg, :pos_neg
|
265
|
+
|
266
|
+
def _wrapped_yndk_spans(object_name,method,options={})
|
267
|
+
object = instance_variable_get("@#{object_name}")
|
268
|
+
_wrapped_spans(object_name,method,options.update(
|
269
|
+
:value => (YNDK[object.send(method)]||' ') ) )
|
270
|
+
end
|
271
|
+
|
272
|
+
def _wrapped_ynodk_spans(object_name,method,options={})
|
273
|
+
object = instance_variable_get("@#{object_name}")
|
274
|
+
_wrapped_spans(object_name,method,options.update(
|
275
|
+
:value => (YNODK[object.send(method)]||' ') ) )
|
276
|
+
end
|
277
|
+
|
278
|
+
def _wrapped_ynrdk_spans(object_name,method,options={})
|
279
|
+
object = instance_variable_get("@#{object_name}")
|
280
|
+
_wrapped_spans(object_name,method,options.update(
|
281
|
+
:value => (YNRDK[object.send(method)]||' ') ) )
|
282
|
+
end
|
283
|
+
|
284
|
+
def _wrapped_ynordk_spans(object_name,method,options={})
|
285
|
+
object = instance_variable_get("@#{object_name}")
|
286
|
+
_wrapped_spans(object_name,method,options.update(
|
287
|
+
:value => (YNORDK[object.send(method)]||' ') ) )
|
288
|
+
end
|
289
|
+
|
290
|
+
def _wrapped_padk_spans(object_name,method,options={})
|
291
|
+
object = instance_variable_get("@#{object_name}")
|
292
|
+
_wrapped_spans(object_name,method,options.update(
|
293
|
+
:value => (PADK[object.send(method)]||' ') ) )
|
294
|
+
end
|
295
|
+
|
296
|
+
def _wrapped_adna_spans(object_name,method,options={})
|
297
|
+
object = instance_variable_get("@#{object_name}")
|
298
|
+
_wrapped_spans(object_name,method,options.update(
|
299
|
+
:value => (ADNA[object.send(method)]||' ') ) )
|
300
|
+
end
|
301
|
+
|
302
|
+
def _wrapped_pos_neg_spans(object_name,method,options={})
|
303
|
+
object = instance_variable_get("@#{object_name}")
|
304
|
+
_wrapped_spans(object_name,method,options.update(
|
305
|
+
:value => (POSNEG[object.send(method)]||' ') ) )
|
306
|
+
end
|
307
|
+
|
308
|
+
end # module CommonLib::ActionViewExtension::Base
|
309
|
+
ActionView::Base.send(:include,
|
310
|
+
CommonLib::ActionViewExtension::Base )
|
@@ -0,0 +1,197 @@
|
|
1
|
+
module CommonLib::ActionViewExtension::FormBuilder
|
2
|
+
|
3
|
+
def error_messages
|
4
|
+
if self.object.errors.count > 0
|
5
|
+
s = '<div id="errorExplanation" class="errorExplanation">'
|
6
|
+
s << "<h2>#{self.object.errors.count} #{"error".pluralize(self.object.errors.count)} prohibited this #{self.object.class} from being saved:</h2>"
|
7
|
+
s << '<p>There were problems with the following fields:</p>'
|
8
|
+
s << '<ul>'
|
9
|
+
self.object.errors.full_messages.each do |msg|
|
10
|
+
s << "<li>#{msg}</li>"
|
11
|
+
end
|
12
|
+
s << '</ul></div>'
|
13
|
+
s.html_safe
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def hour_select(method,options={},html_options={})
|
18
|
+
@template.select(object_name, method,
|
19
|
+
(1..12),
|
20
|
+
{:include_blank => 'Hour'}.merge(options), html_options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def minute_select(method,options={},html_options={})
|
24
|
+
minutes = (0..59).to_a.collect{|m|[sprintf("%02d",m),m]}
|
25
|
+
@template.select(object_name, method,
|
26
|
+
minutes,
|
27
|
+
{:include_blank => 'Minute'}.merge(options), html_options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def meridiem_select(method,options={},html_options={})
|
31
|
+
@template.select(object_name, method,
|
32
|
+
['AM','PM'],
|
33
|
+
{:include_blank => 'Meridiem'}.merge(options), html_options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def sex_select(method,options={},html_options={})
|
37
|
+
@template.select(object_name, method,
|
38
|
+
[['-select-',''],['male','M'],['female','F'],["don't know",'DK']],
|
39
|
+
options, html_options)
|
40
|
+
end
|
41
|
+
alias_method :gender_select, :sex_select
|
42
|
+
|
43
|
+
def date_text_field(method, options = {})
|
44
|
+
format = options.delete(:format) || '%m/%d/%Y'
|
45
|
+
tmp_value = if options[:value].blank? #and !options[:object].nil?
|
46
|
+
# object = options[:object]
|
47
|
+
tmp = self.object.send("#{method}") ||
|
48
|
+
self.object.send("#{method}_before_type_cast")
|
49
|
+
else
|
50
|
+
options[:value]
|
51
|
+
end
|
52
|
+
begin
|
53
|
+
options[:value] = tmp_value.to_date.try(:strftime,format)
|
54
|
+
rescue NoMethodError, ArgumentError
|
55
|
+
options[:value] = tmp_value
|
56
|
+
end
|
57
|
+
options.update(:class => [options[:class],'datepicker'].compact.join(' '))
|
58
|
+
@template.text_field( object_name, method, options )
|
59
|
+
end
|
60
|
+
|
61
|
+
def datetime_text_field(method, options = {})
|
62
|
+
format = options.delete(:format) || '%m/%d/%Y %H:%M'
|
63
|
+
tmp_value = if options[:value].blank?
|
64
|
+
tmp = self.object.send("#{method}") ||
|
65
|
+
self.object.send("#{method}_before_type_cast")
|
66
|
+
else
|
67
|
+
options[:value]
|
68
|
+
end
|
69
|
+
begin
|
70
|
+
options[:value] = tmp_value.to_datetime.try(:strftime,format)
|
71
|
+
rescue NoMethodError, ArgumentError
|
72
|
+
options[:value] = tmp_value
|
73
|
+
end
|
74
|
+
options.update(:class => [options[:class],'datetimepicker'].compact.join(' '))
|
75
|
+
@template.text_field( object_name, method, options )
|
76
|
+
end
|
77
|
+
|
78
|
+
def yndk_select(method,options={},html_options={})
|
79
|
+
@template.select(object_name, method, YNDK.selector_options,
|
80
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
81
|
+
end
|
82
|
+
|
83
|
+
def ynrdk_select(method,options={},html_options={})
|
84
|
+
@template.select(object_name, method, YNRDK.selector_options,
|
85
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
86
|
+
end
|
87
|
+
|
88
|
+
def ynodk_select(method,options={},html_options={})
|
89
|
+
@template.select(object_name, method, YNODK.selector_options,
|
90
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
91
|
+
end
|
92
|
+
|
93
|
+
def ynordk_select(method,options={},html_options={})
|
94
|
+
@template.select(object_name, method, YNORDK.selector_options,
|
95
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
96
|
+
end
|
97
|
+
|
98
|
+
def padk_select(method,options={},html_options={})
|
99
|
+
@template.select(object_name, method, PADK.selector_options,
|
100
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def adna_select(method,options={},html_options={})
|
104
|
+
@template.select(object_name, method, ADNA.selector_options,
|
105
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
106
|
+
end
|
107
|
+
|
108
|
+
def pos_neg_select(method, options={}, html_options={})
|
109
|
+
@template.select(object_name, method, POSNEG.selector_options,
|
110
|
+
{:include_blank => true}.merge(objectify_options(options)), html_options)
|
111
|
+
end
|
112
|
+
|
113
|
+
def wrapped_check_box(*args,&block)
|
114
|
+
method = args[0]
|
115
|
+
content = @template.field_wrapper(method,:class => 'check_box') do
|
116
|
+
options = args.detect{|i| i.is_a?(Hash) }
|
117
|
+
label_text = options.delete(:label_text) unless options.nil?
|
118
|
+
post_text = options.delete(:post_text) unless options.nil?
|
119
|
+
# INVERTED ORDER SO NOT INCLUDED BELOW
|
120
|
+
s = check_box(*args,&block) <<
|
121
|
+
self.label( method, label_text )
|
122
|
+
s << (( block_given? )? @template.capture(&block) : '')
|
123
|
+
s << (( post_text.blank? ) ? '' : "<span>#{post_text}</span>".html_safe )
|
124
|
+
end
|
125
|
+
content.html_safe
|
126
|
+
end
|
127
|
+
|
128
|
+
# special
|
129
|
+
# def wrapped_check_box(*args,&block)
|
130
|
+
|
131
|
+
#
|
132
|
+
# This isn't pretty, but does appear to work.
|
133
|
+
# Dynamically defined using a class_eval rather than
|
134
|
+
# define_method. And no method_missing.
|
135
|
+
#
|
136
|
+
# Actually, now that we're using ruby 1.9, can't I use
|
137
|
+
# define_method with a block?
|
138
|
+
#
|
139
|
+
# Add "field_error" class if errors.include?(method)
|
140
|
+
#
|
141
|
+
%w( adna_select collection_select country_select
|
142
|
+
datetime_select date_text_field datetime_text_field
|
143
|
+
file_field password_field
|
144
|
+
hour_select minute_select meridiem_select gender_select
|
145
|
+
grouped_collection_select padk_select
|
146
|
+
pos_neg_select select sex_select text_area
|
147
|
+
text_field yndk_select ynodk_select ynrdk_select ynordk_select
|
148
|
+
).each do |unwrapped_method_name|
|
149
|
+
define_method "wrapped_#{unwrapped_method_name}" do |*args,&block|
|
150
|
+
#class_eval %Q"
|
151
|
+
# def wrapped_#{unwrapped_method_name}(*args,&block)
|
152
|
+
method = args[0]
|
153
|
+
# content = @template.field_wrapper(method,:class => '#{unwrapped_method_name}') do
|
154
|
+
content = @template.field_wrapper(method,:class => unwrapped_method_name) do
|
155
|
+
options = args.detect{|i| i.is_a?(Hash) }
|
156
|
+
label_text = options.delete(:label_text) unless options.nil?
|
157
|
+
post_text = options.delete(:post_text) unless options.nil?
|
158
|
+
# removing these from the options hash will stop them from being
|
159
|
+
# passed on to the unwrapped_method
|
160
|
+
|
161
|
+
# s = self.label( method, label_text ) <<
|
162
|
+
# #{unwrapped_method_name}(*args)
|
163
|
+
## #{unwrapped_method_name}(*args,&block)
|
164
|
+
## why pass the block along? usually a good idea, but these methods don't use it. (at least I don't see any)
|
165
|
+
## if they did, then why capture it again too?
|
166
|
+
# s << (( block_given? )? @template.capture(&block) : '')
|
167
|
+
# s << (( post_text.blank? ) ? '' : \"<span>\#{post_text}</span>\".html_safe )
|
168
|
+
|
169
|
+
# I would prefer to do this the newer way, but
|
170
|
+
# when a wrapped method has a block with a wrapped method
|
171
|
+
# it ends up being rendered a couple times ??
|
172
|
+
|
173
|
+
s = self.label( method, label_text )
|
174
|
+
s << send(unwrapped_method_name,*args,&block)
|
175
|
+
# s << (( block )? block.call : '')
|
176
|
+
# s << (( block_given? )? @template.capture(&block) : '')
|
177
|
+
# the new way won't work with block_given?, but template.capture still does.
|
178
|
+
s << (( block )? @template.capture(&block) : '')
|
179
|
+
#if block #block_given?
|
180
|
+
# puts "BLOCK GIVEN"
|
181
|
+
##puts @template.concat(&block)
|
182
|
+
#puts @template.capture(&block)
|
183
|
+
#else
|
184
|
+
# puts "NO BLOCK GIVEN"
|
185
|
+
#end
|
186
|
+
s << (( post_text.blank? ) ? '' : "<span>#{post_text}</span>".html_safe )
|
187
|
+
|
188
|
+
|
189
|
+
end
|
190
|
+
content.html_safe
|
191
|
+
end
|
192
|
+
#"
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
ActionView::Helpers::FormBuilder.send(:include,
|
197
|
+
CommonLib::ActionViewExtension::FormBuilder )
|