hobo 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.txt +18 -0
- data/bin/hobo +81 -0
- data/hobo_files/plugin/CHANGES.txt +963 -0
- data/hobo_files/plugin/LICENSE.txt +22 -0
- data/hobo_files/plugin/README +4 -0
- data/hobo_files/plugin/Rakefile +11 -0
- data/hobo_files/plugin/generators/hobo/hobo_generator.rb +37 -0
- data/hobo_files/plugin/generators/hobo/templates/application.dryml +2 -0
- data/hobo_files/plugin/generators/hobo/templates/guest.rb +31 -0
- data/hobo_files/plugin/generators/hobo_front_controller/USAGE +11 -0
- data/hobo_files/plugin/generators/hobo_front_controller/hobo_front_controller_generator.rb +90 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/controller.rb +51 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/functional_test.rb +18 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/helper.rb +2 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml +43 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/login.dryml +44 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml +18 -0
- data/hobo_files/plugin/generators/hobo_front_controller/templates/signup.dryml +45 -0
- data/hobo_files/plugin/generators/hobo_model/USAGE +26 -0
- data/hobo_files/plugin/generators/hobo_model/hobo_model_generator.rb +38 -0
- data/hobo_files/plugin/generators/hobo_model/templates/fixtures.yml +11 -0
- data/hobo_files/plugin/generators/hobo_model/templates/migration.rb +13 -0
- data/hobo_files/plugin/generators/hobo_model/templates/model.rb +24 -0
- data/hobo_files/plugin/generators/hobo_model/templates/unit_test.rb +10 -0
- data/hobo_files/plugin/generators/hobo_model_controller/USAGE +30 -0
- data/hobo_files/plugin/generators/hobo_model_controller/hobo_model_controller_generator.rb +43 -0
- data/hobo_files/plugin/generators/hobo_model_controller/templates/controller.rb +5 -0
- data/hobo_files/plugin/generators/hobo_model_controller/templates/functional_test.rb +18 -0
- data/hobo_files/plugin/generators/hobo_model_controller/templates/helper.rb +2 -0
- data/hobo_files/plugin/generators/hobo_model_controller/templates/view.rhtml +2 -0
- data/hobo_files/plugin/generators/hobo_rapid/hobo_rapid_generator.rb +51 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/hobo_rapid.js +436 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/default_mapping.rb +11 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/banner.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_bodytop.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_corner_01.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_corner_02.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_corner_03.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_corner_04.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_shadow_bottom.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_shadow_left.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_shadow_right.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg_shadow_top.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header_blue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header_dblue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header_green.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header_purple.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header_red.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/logo.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/spinner.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt_list_img_dblue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt_list_img_green.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt_list_img_purple.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt_list_img_red.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_corner_01.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_corner_02.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_corner_03.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_corner_04.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_bottom.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_left.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_right.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window_shadow_top.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css +390 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml +104 -0
- data/hobo_files/plugin/generators/hobo_user_model/USAGE +26 -0
- data/hobo_files/plugin/generators/hobo_user_model/hobo_user_model_generator.rb +38 -0
- data/hobo_files/plugin/generators/hobo_user_model/templates/fixtures.yml +11 -0
- data/hobo_files/plugin/generators/hobo_user_model/templates/migration.rb +15 -0
- data/hobo_files/plugin/generators/hobo_user_model/templates/model.rb +58 -0
- data/hobo_files/plugin/generators/hobo_user_model/templates/unit_test.rb +10 -0
- data/hobo_files/plugin/init.rb +44 -0
- data/hobo_files/plugin/lib/action_view_extensions/base.rb +14 -0
- data/hobo_files/plugin/lib/active_record/has_many_association.rb +54 -0
- data/hobo_files/plugin/lib/active_record/has_many_through_association.rb +22 -0
- data/hobo_files/plugin/lib/active_record/table_definition.rb +34 -0
- data/hobo_files/plugin/lib/extensions.rb +245 -0
- data/hobo_files/plugin/lib/extensions/test_case.rb +130 -0
- data/hobo_files/plugin/lib/hobo.rb +353 -0
- data/hobo_files/plugin/lib/hobo/HtmlString +3 -0
- data/hobo_files/plugin/lib/hobo/authenticated_user.rb +106 -0
- data/hobo_files/plugin/lib/hobo/authentication_support.rb +108 -0
- data/hobo_files/plugin/lib/hobo/composite_model.rb +66 -0
- data/hobo_files/plugin/lib/hobo/controller.rb +134 -0
- data/hobo_files/plugin/lib/hobo/controller_helpers.rb +135 -0
- data/hobo_files/plugin/lib/hobo/core.rb +475 -0
- data/hobo_files/plugin/lib/hobo/define_tags.rb +56 -0
- data/hobo_files/plugin/lib/hobo/dryml.rb +161 -0
- data/hobo_files/plugin/lib/hobo/dryml/dryml_builder.rb +126 -0
- data/hobo_files/plugin/lib/hobo/dryml/tag_module.rb +9 -0
- data/hobo_files/plugin/lib/hobo/dryml/taglib.rb +57 -0
- data/hobo_files/plugin/lib/hobo/dryml/template.rb +586 -0
- data/hobo_files/plugin/lib/hobo/dryml/template_environment.rb +302 -0
- data/hobo_files/plugin/lib/hobo/dryml/template_handler.rb +19 -0
- data/hobo_files/plugin/lib/hobo/generator.rb +25 -0
- data/hobo_files/plugin/lib/hobo/html_string.rb +3 -0
- data/hobo_files/plugin/lib/hobo/lazy_hash.rb +28 -0
- data/hobo_files/plugin/lib/hobo/mapping_tags.rb +262 -0
- data/hobo_files/plugin/lib/hobo/markdown_string.rb +7 -0
- data/hobo_files/plugin/lib/hobo/model.rb +391 -0
- data/hobo_files/plugin/lib/hobo/model_controller.rb +676 -0
- data/hobo_files/plugin/lib/hobo/model_queries.rb +92 -0
- data/hobo_files/plugin/lib/hobo/model_support.rb +44 -0
- data/hobo_files/plugin/lib/hobo/password_string.rb +3 -0
- data/hobo_files/plugin/lib/hobo/predicate_dispatch.rb +78 -0
- data/hobo_files/plugin/lib/hobo/proc_binding.rb +32 -0
- data/hobo_files/plugin/lib/hobo/rapid.rb +447 -0
- data/hobo_files/plugin/lib/hobo/static_tags +92 -0
- data/hobo_files/plugin/lib/hobo/text.rb +3 -0
- data/hobo_files/plugin/lib/hobo/textile_string.rb +13 -0
- data/hobo_files/plugin/lib/hobo/undefined.rb +41 -0
- data/hobo_files/plugin/lib/hobo/undefined_access_error.rb +5 -0
- data/hobo_files/plugin/lib/hobo/where_fragment.rb +23 -0
- data/hobo_files/plugin/lib/rexml.rb +345 -0
- data/hobo_files/plugin/tags/core.dryml +6 -0
- data/hobo_files/plugin/tags/rapid.dryml +177 -0
- data/hobo_files/plugin/tags/rapid_editing.dryml +168 -0
- data/hobo_files/plugin/tags/rapid_navigation.dryml +95 -0
- data/hobo_files/plugin/tags/rapid_pages.dryml +175 -0
- data/hobo_files/plugin/tasks/environments.rake +19 -0
- data/hobo_files/plugin/tasks/hobo_tasks.rake +4 -0
- data/hobo_files/plugin/test/hobo_dryml_template_test.rb +7 -0
- data/hobo_files/plugin/test/hobo_test.rb +7 -0
- data/hobo_files/plugin/uninstall.rb +1 -0
- metadata +206 -0
@@ -0,0 +1,475 @@
|
|
1
|
+
module Hobo
|
2
|
+
|
3
|
+
module Core
|
4
|
+
|
5
|
+
include Hobo::DefineTags
|
6
|
+
|
7
|
+
include Hobo::ControllerHelpers
|
8
|
+
|
9
|
+
def debug(*args)
|
10
|
+
logger.debug("\n### DRYML Debug ###")
|
11
|
+
logger.debug(args.map {|a| PP.pp(a, "")}.join("-------\n"))
|
12
|
+
logger.debug("DRYML THIS = " + Hobo.dom_id(this).to_s)
|
13
|
+
logger.debug("###################\n")
|
14
|
+
args.first unless args.empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def add_classes!(options, *classes)
|
19
|
+
options[:class] = ([options[:class]] + classes).select{|x|x}.join(' ')
|
20
|
+
options
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def add_classes(options, *classes)
|
25
|
+
add_classes!({}.update(options), classes)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def map_this
|
30
|
+
res = []
|
31
|
+
this.each_index {|i| new_field_context(i) { res << yield } }
|
32
|
+
res
|
33
|
+
end
|
34
|
+
alias_method :collect_this, :map_this
|
35
|
+
|
36
|
+
|
37
|
+
def comma_split(x)
|
38
|
+
case x
|
39
|
+
when nil
|
40
|
+
[]
|
41
|
+
when Symbol
|
42
|
+
x.to_s
|
43
|
+
when String
|
44
|
+
x.split(/\s*,\s*/)
|
45
|
+
else
|
46
|
+
x.map{|e| comma_split(e)}.flatten
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def can_create?(object)
|
52
|
+
Hobo.can_create?(current_user, object)
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def can_update?(object, new)
|
57
|
+
Hobo.can_update?(current_user, object, new)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def can_edit?(object, field)
|
62
|
+
if !field and object.respond_to?(:proxy_reflection)
|
63
|
+
Hobo.can_edit?(current_user, object.proxy_owner, object.proxy_reflection.name)
|
64
|
+
else
|
65
|
+
Hobo.can_edit?(current_user, object, field)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def can_edit_this?
|
71
|
+
this_parent && this_field && can_edit?(this_parent, this_field)
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def can_delete?(object)
|
76
|
+
Hobo.can_delete?(current_user, object)
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def can_view?(object, field=nil)
|
81
|
+
if !field and object.respond_to?(:proxy_reflection)
|
82
|
+
Hobo.can_view?(current_user, object.proxy_owner, object.proxy_reflection.name)
|
83
|
+
else
|
84
|
+
Hobo.can_view?(current_user, object, field)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
def can_view_this?
|
90
|
+
if this_parent && this_field
|
91
|
+
can_view?(this_parent, this_field)
|
92
|
+
else
|
93
|
+
can_view?(this)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
def viewable(collection)
|
99
|
+
collection.select {|x| can_view?(x)}
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
def theme_asset(path)
|
104
|
+
"#{urlb}/hobothemes/#{Hobo.current_theme}/#{path}"
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def_tag :dynamic_tag, :name do
|
109
|
+
send(name, options)
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
def_tag :display_name do
|
114
|
+
name_tag = "display_name_for_#{this.class.name.underscore}"
|
115
|
+
if respond_to?(name_tag)
|
116
|
+
send(name_tag)
|
117
|
+
elsif this.is_a?(Array) && this.respond_to?(:proxy_reflection)
|
118
|
+
"(#{count})"
|
119
|
+
elsif this.is_a? Class and this < ActiveRecord::Base
|
120
|
+
this.name.pluralize.titleize
|
121
|
+
else
|
122
|
+
res = [:display_name, :name, :title].search do |m|
|
123
|
+
show(options.merge(:attr => m)) if this.respond_to?(m) and can_view?(this, m)
|
124
|
+
end
|
125
|
+
res || "#{this.class.name.humanize} #{this.id}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
def_tag :object_link, :view, :to, :params do
|
131
|
+
target = to || this
|
132
|
+
if target.nil?
|
133
|
+
"(Not Available)"
|
134
|
+
elsif to ? can_view?(to) : can_view_this?
|
135
|
+
content = tagbody ? tagbody.call : call_replaceable_tag(:display_name, options, options.delete(:name))
|
136
|
+
link_class = "#{target.class.name.underscore}_link"
|
137
|
+
link_to content, object_url(target, view, params), add_classes(options, link_class)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
def_tag :new_object_link, :for do
|
143
|
+
f = for_ || this
|
144
|
+
new = f.new
|
145
|
+
new.created_by(current_user)
|
146
|
+
if can_create?(new)
|
147
|
+
default = "New " + (f.is_a?(Array) ? f.proxy_reflection.klass.name : f.name).titleize
|
148
|
+
content = tagbody ? tagbody.call : default
|
149
|
+
link_class = "new_#{new.class.name.underscore}_link"
|
150
|
+
link_to content, object_url(f, "new"), add_classes(options, link_class)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def_tag :tag_for_object, :name do
|
156
|
+
opts = {}.update(options)
|
157
|
+
opts.delete(:name)
|
158
|
+
|
159
|
+
if this_type and m = "#{name}_for_#{this_type.name.underscore}" and respond_to?(m)
|
160
|
+
send(m, opts)
|
161
|
+
else
|
162
|
+
send(name, opts)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
def_tag :show, :no_span, :truncate_tail do
|
168
|
+
# We can't do this as a declared attribute as it will hide the truncate helper
|
169
|
+
trunc = options.delete(:truncate)
|
170
|
+
|
171
|
+
raise HoboError, "show of non-viewable field '#{this_field}' of #{this_parent.typed_id rescue this_parent}" unless
|
172
|
+
can_view_this?
|
173
|
+
|
174
|
+
res = if this_type.respond_to?(:macro)
|
175
|
+
if this_type.macro == :belongs_to
|
176
|
+
show_belongs_to
|
177
|
+
elsif this_type.macro == :has_many
|
178
|
+
show_has_many
|
179
|
+
end
|
180
|
+
|
181
|
+
else
|
182
|
+
res2 = case this
|
183
|
+
when nil
|
184
|
+
this_type <= String ? "" : "(Not Available)"
|
185
|
+
|
186
|
+
when Date
|
187
|
+
if respond_to?(:show_date)
|
188
|
+
show_date
|
189
|
+
else
|
190
|
+
this.to_s(:long)
|
191
|
+
end
|
192
|
+
|
193
|
+
when Time
|
194
|
+
if respond_to?(:show_datetime)
|
195
|
+
show_datetime
|
196
|
+
else
|
197
|
+
this.to_s(:long)
|
198
|
+
end
|
199
|
+
|
200
|
+
when Numeric
|
201
|
+
format = options[:format]
|
202
|
+
format ? format % this : this.to_s
|
203
|
+
|
204
|
+
when Hobo::HtmlString
|
205
|
+
this
|
206
|
+
|
207
|
+
when Hobo::MarkdownString
|
208
|
+
markdown(this)
|
209
|
+
|
210
|
+
when Hobo::TextileString
|
211
|
+
textilize(this)
|
212
|
+
|
213
|
+
when Hobo::PasswordString
|
214
|
+
"[password withheld]"
|
215
|
+
|
216
|
+
when String
|
217
|
+
h(this).gsub("\n", "<br/>")
|
218
|
+
|
219
|
+
when TrueClass
|
220
|
+
"Yes"
|
221
|
+
|
222
|
+
when FalseClass
|
223
|
+
"No"
|
224
|
+
|
225
|
+
else
|
226
|
+
raise HoboError, "Cannot show: #{this.inspect} (field is #{this_field}, type is #{this.class})"
|
227
|
+
end
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
if !no_span && this_parent.respond_to?(:typed_id)
|
232
|
+
"<span hobo_model_id='#{this_field_dom_id}'>#{res2}</span>"
|
233
|
+
else
|
234
|
+
res2
|
235
|
+
end
|
236
|
+
end
|
237
|
+
trunc ? truncate(res2, trunc.to_i, truncate_tail || "...") : res
|
238
|
+
end
|
239
|
+
|
240
|
+
|
241
|
+
def_tag :show_belongs_to do
|
242
|
+
object_link
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
def_tag :show_has_many do
|
247
|
+
if this.empty?
|
248
|
+
"(none)"
|
249
|
+
else
|
250
|
+
map_this { object_link }.join(", ")
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
|
255
|
+
def js_str(s)
|
256
|
+
if s.is_a? Hobo::RawJs
|
257
|
+
s.to_s
|
258
|
+
else
|
259
|
+
"'" + s.gsub("'"){"\\'"} + "'"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
|
264
|
+
def make_params_js(*args)
|
265
|
+
("'" + make_params(*args) + "'").sub(/ \+ ''$/,'')
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
def render_params(*args)
|
270
|
+
parts = args.map{|x| x.split(/, */) if x}.compact.flatten
|
271
|
+
{ :part_page => view_name,
|
272
|
+
:render => parts.map do |part_id|
|
273
|
+
{ :object => Hobo::RawJs.new("hoboParts.#{part_id}"),
|
274
|
+
:part => part_id }
|
275
|
+
end
|
276
|
+
}
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
def nl_to_br(s)
|
281
|
+
s.to_s.gsub("\n", "<br/>") if s
|
282
|
+
end
|
283
|
+
|
284
|
+
|
285
|
+
def xattrs(options, klass=nil)
|
286
|
+
options ||= {}
|
287
|
+
if klass
|
288
|
+
options = add_classes(options.symbolize_keys, [klass])
|
289
|
+
end
|
290
|
+
options.map do |n,v|
|
291
|
+
v = v.to_s
|
292
|
+
val = v.include?("'") ? '"' + v + '"' : "'" + v + "'"
|
293
|
+
"#{n}=#{val}"
|
294
|
+
end.join(' ')
|
295
|
+
end
|
296
|
+
|
297
|
+
|
298
|
+
def param_name_for(object, field_path)
|
299
|
+
field_path = field_path.to_s.split(".") if field_path.is_a?(String, Symbol)
|
300
|
+
attrs = field_path.map{|part| "[#{part}]"}.join
|
301
|
+
"#{object.class.name.underscore}#{attrs}"
|
302
|
+
end
|
303
|
+
|
304
|
+
|
305
|
+
def param_name_for_this(association_foreign_key=false)
|
306
|
+
return "" unless form_this
|
307
|
+
name = if association_foreign_key and this_type.respond_to?(:macro) and this_type.macro == :belongs_to
|
308
|
+
param_name_for(form_this, form_field_path[0..-2] + [this_type.primary_key_name])
|
309
|
+
else
|
310
|
+
param_name_for(form_this, form_field_path)
|
311
|
+
end
|
312
|
+
register_form_field(name)
|
313
|
+
name
|
314
|
+
end
|
315
|
+
|
316
|
+
|
317
|
+
def selector_type
|
318
|
+
if this.is_a? ActiveRecord::Base
|
319
|
+
this.class
|
320
|
+
elsif this.respond_to? :member_class
|
321
|
+
this.member_class
|
322
|
+
elsif this == @this
|
323
|
+
@model
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
|
328
|
+
def_tag :human_type, :style do
|
329
|
+
if can_view_this?
|
330
|
+
res = if this.respond_to? :proxy_reflection
|
331
|
+
this.proxy_reflection.klass.name.pluralize
|
332
|
+
elsif this.is_a? Class
|
333
|
+
this.name
|
334
|
+
else
|
335
|
+
this.class.name
|
336
|
+
end
|
337
|
+
res.underscore.humanize.send(style || :titleize)
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
|
342
|
+
def_tag :partial, :as do
|
343
|
+
render(:partial => find_partial(this, as), :locals => { :this => this })
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
def_tag :repeat, :even_odd, :else do
|
348
|
+
if this.empty?
|
349
|
+
else_
|
350
|
+
else
|
351
|
+
if even_odd
|
352
|
+
map_this do
|
353
|
+
klass = [options[:class], cycle("even", "odd")].compact.join(' ')
|
354
|
+
content_tag(even_odd, tagbody.call, options.merge(:class => klass, :hobo_model_id => dom_id(this)))
|
355
|
+
end
|
356
|
+
else
|
357
|
+
map_this { tagbody.call }
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
|
363
|
+
def_tag :transpose_and_repeat, :with_field do
|
364
|
+
matrix = this.map {|obj| obj.send(with_field) }
|
365
|
+
max_length = matrix.omap{ length }.max
|
366
|
+
matrix = matrix.map do |a|
|
367
|
+
a + [nil] * (max_length - a.length)
|
368
|
+
end
|
369
|
+
repeat(:obj => matrix.transpose) { tagbody.call }
|
370
|
+
end
|
371
|
+
|
372
|
+
|
373
|
+
def_tag :count, :label, :prefix do
|
374
|
+
raise Exception.new("asked for count of a string") if this.is_a?(String)
|
375
|
+
|
376
|
+
l = label
|
377
|
+
if this.is_a?(Class) and this < ActiveRecord::Base
|
378
|
+
c = this.count
|
379
|
+
l ||= this.name.titleize
|
380
|
+
else
|
381
|
+
unless label
|
382
|
+
assoc_name = this.proxy_reflection.name.to_s
|
383
|
+
l = assoc_name.singularize.titleize
|
384
|
+
end
|
385
|
+
c = this.size
|
386
|
+
end
|
387
|
+
|
388
|
+
main = l.blank? ? c : pluralize(c, l)
|
389
|
+
|
390
|
+
if prefix == "are"
|
391
|
+
p = c == 1 ? "is" : "are"
|
392
|
+
p + ' ' + main
|
393
|
+
else
|
394
|
+
main
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
|
399
|
+
def_tag :with do
|
400
|
+
tagbody.call
|
401
|
+
end
|
402
|
+
|
403
|
+
|
404
|
+
def_tag :join, :with do
|
405
|
+
map_this { tagbody.call }.join(with)
|
406
|
+
end
|
407
|
+
|
408
|
+
|
409
|
+
def_tag :link_tag, :href, :controller, :action, :id do
|
410
|
+
link_to(tagbody.call, href ? href : { :controller => controller, :action => action, :id => id })
|
411
|
+
end
|
412
|
+
|
413
|
+
|
414
|
+
def_tag :if, :q do
|
415
|
+
res = q ? tagbody.call : ""
|
416
|
+
Dryml.last_if = q
|
417
|
+
res
|
418
|
+
end
|
419
|
+
|
420
|
+
|
421
|
+
def_tag :else do
|
422
|
+
tagbody.call unless Dryml.last_if
|
423
|
+
end
|
424
|
+
|
425
|
+
|
426
|
+
def_tag :unless, :q do
|
427
|
+
if_(:q => !q) { tagbody.call }
|
428
|
+
end
|
429
|
+
|
430
|
+
|
431
|
+
def_tag :if_blank do
|
432
|
+
if_(:q => this.blank?) { tagbody.call }
|
433
|
+
end
|
434
|
+
|
435
|
+
|
436
|
+
def_tag :unless_blank do
|
437
|
+
if_(:q => !this.blank?) { tagbody.call }
|
438
|
+
end
|
439
|
+
|
440
|
+
|
441
|
+
def_tag :if_empty do
|
442
|
+
if_(:q => this.empty?) { tagbody.call }
|
443
|
+
end
|
444
|
+
|
445
|
+
|
446
|
+
def_tag :unless_empty do
|
447
|
+
if_(:q => !this.empty?) { tagbody.call }
|
448
|
+
end
|
449
|
+
|
450
|
+
|
451
|
+
def_tag :if_this do
|
452
|
+
if_(:q => this) { tagbody.call }
|
453
|
+
end
|
454
|
+
|
455
|
+
|
456
|
+
def_tag :if_can_delete do
|
457
|
+
if_(:q => can_delete?(this)) { tagbody.call }
|
458
|
+
end
|
459
|
+
|
460
|
+
|
461
|
+
def_tag :if_can_create do
|
462
|
+
if_(:q => can_create?(this)) { tagbody.call }
|
463
|
+
end
|
464
|
+
|
465
|
+
|
466
|
+
def_tag :if_can_view do
|
467
|
+
if_(:q => can_view?(this)) { tagbody.call }
|
468
|
+
end
|
469
|
+
|
470
|
+
def_tag :if_can_edit do
|
471
|
+
if_(:q => can_edit_this?) { tagbody.call }
|
472
|
+
end
|
473
|
+
|
474
|
+
end
|
475
|
+
end
|