hobo 1.3.0.RC4 → 1.3.0.pre10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +234 -282
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/app/controllers/dev_controller.rb +2 -2
- data/bin/hobo +3 -3
- data/config/routes.rb +1 -1
- data/doctests/hobo/lifecycles.rdoctest +1 -0
- data/doctests/hobo/model.rdoctest +5 -0
- data/doctests/hobo/multi_model_forms.rdoctest +5 -4
- data/doctests/hobo/scopes.rdoctest +8 -11
- data/doctests/prepare_testapp.rb +1 -2
- data/hobo.gemspec +2 -2
- data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
- data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
- data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
- data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
- data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
- data/lib/generators/hobo/basic/basic_generator.rb +17 -0
- data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
- data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
- data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
- data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
- data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
- data/lib/generators/hobo/controller.rb +1 -6
- data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
- data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
- data/lib/generators/hobo/hints/hints_generator.rb +12 -0
- data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
- data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
- data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
- data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
- data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
- data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
- data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
- data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
- data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
- data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
- data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
- data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
- data/lib/generators/hobo/model.rb +13 -0
- data/lib/generators/hobo/model/USAGE +3 -2
- data/lib/generators/hobo/model/model_generator.rb +1 -2
- data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
- data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
- data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
- data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
- data/lib/generators/hobo/rapid/templates/reset.css +1 -1
- data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
- data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
- data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
- data/lib/generators/hobo/resource/resource_generator.rb +1 -1
- data/lib/generators/hobo/routes/router.rb +4 -4
- data/lib/generators/hobo/routes/routes_generator.rb +1 -12
- data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
- data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
- data/lib/generators/hobo/subsite.rb +5 -18
- data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
- data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
- data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
- data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
- data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
- data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
- data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
- data/lib/generators/hobo/user_model/USAGE +9 -2
- data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
- data/lib/hobo.rb +7 -13
- data/lib/hobo/controller.rb +14 -21
- data/lib/hobo/controller/authentication_support.rb +23 -1
- data/lib/hobo/controller/model.rb +53 -48
- data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
- data/lib/hobo/engine.rb +11 -25
- data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
- data/lib/hobo/extensions/active_model/translation.rb +1 -1
- data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
- data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
- data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
- data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
- data/lib/hobo/extensions/active_record/scopes.rb +31 -0
- data/lib/hobo/extensions/array.rb +1 -13
- data/lib/hobo/helper.rb +6 -27
- data/lib/hobo/helper/translations.rb +90 -39
- data/lib/hobo/model.rb +20 -72
- data/lib/hobo/model/lifecycles.rb +11 -12
- data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
- data/lib/hobo/model/lifecycles/transition.rb +0 -1
- data/lib/hobo/model/permissions.rb +3 -2
- data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
- data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
- data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
- data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
- data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
- data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
- data/lib/hobo/rapid/helper.rb +5 -10
- data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
- data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
- data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
- data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
- data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
- data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
- data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
- data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
- data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
- data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
- data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
- data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
- data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
- data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
- data/lib/hobo/routes.rb +23 -22
- data/lib/hobo/view_hints.rb +101 -0
- data/test/irt/generators/admin_subsite.irt +1 -1
- data/test/irt/generators/{assets.irt → basic.irt} +2 -2
- data/test/irt/generators/front_controller.irt +4 -2
- data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
- data/test/irt/generators/subsite.irt +1 -1
- data/test/permissions/test_permissions.rb +103 -103
- metadata +108 -69
- data/lib/generators/hobo/admin_subsite/USAGE +0 -25
- data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
- data/lib/generators/hobo/assets/USAGE +0 -5
- data/lib/generators/hobo/assets/assets_generator.rb +0 -18
- data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
- data/lib/generators/hobo/controller/USAGE +0 -3
- data/lib/generators/hobo/i18n/USAGE +0 -3
- data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
- data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
- data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
- data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
- data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
- data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
- data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
- data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
- data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
- data/lib/generators/hobo/resource/USAGE +0 -39
- data/lib/generators/hobo/subsite/USAGE +0 -24
- data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
- data/lib/generators/hobo/test_framework/USAGE +0 -2
- data/lib/generators/hobo/user_controller/USAGE +0 -3
- data/lib/generators/hobo/user_mailer/USAGE +0 -2
- data/lib/generators/hobo/user_resource/USAGE +0 -10
- data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
- data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
- data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
- data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
- data/lib/hobo/extensions/i18n.rb +0 -17
- data/lib/hobo/helper/translations/normalizer.rb +0 -39
- data/lib/hobo/model/view_hints.rb +0 -123
@@ -31,11 +31,11 @@ module Hobo
|
|
31
31
|
def create_scope(check_only=false)
|
32
32
|
matched_scope = true
|
33
33
|
|
34
|
-
|
34
|
+
|
35
35
|
# --- Association Queries --- #
|
36
36
|
|
37
37
|
# with_players(player1, player2)
|
38
|
-
|
38
|
+
if name =~ /^with_(.*)/ && (refl = reflection($1))
|
39
39
|
return true if check_only
|
40
40
|
|
41
41
|
def_scope do |*records|
|
@@ -49,7 +49,7 @@ module Hobo
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# with_player(a_player)
|
52
|
-
|
52
|
+
elsif name =~ /^with_(.*)/ && (refl = reflection($1.pluralize))
|
53
53
|
return true if check_only
|
54
54
|
|
55
55
|
exists_sql = exists_sql_condition(refl)
|
@@ -59,7 +59,7 @@ module Hobo
|
|
59
59
|
end
|
60
60
|
|
61
61
|
# any_of_players(player1, player2)
|
62
|
-
|
62
|
+
elsif name =~ /^any_of_(.*)/ && (refl = reflection($1))
|
63
63
|
return true if check_only
|
64
64
|
|
65
65
|
def_scope do |*records|
|
@@ -73,7 +73,7 @@ module Hobo
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# without_players(player1, player2)
|
76
|
-
|
76
|
+
elsif name =~ /^without_(.*)/ && (refl = reflection($1))
|
77
77
|
return true if check_only
|
78
78
|
|
79
79
|
def_scope do |*records|
|
@@ -87,7 +87,7 @@ module Hobo
|
|
87
87
|
end
|
88
88
|
|
89
89
|
# without_player(a_player)
|
90
|
-
|
90
|
+
elsif name =~ /^without_(.*)/ && (refl = reflection($1.pluralize))
|
91
91
|
return true if check_only
|
92
92
|
|
93
93
|
exists_sql = exists_sql_condition(refl)
|
@@ -97,7 +97,7 @@ module Hobo
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# team_is(a_team)
|
100
|
-
|
100
|
+
elsif name =~ /^(.*)_is$/ && (refl = reflection($1)) && refl.macro.in?([:has_one, :belongs_to])
|
101
101
|
return true if check_only
|
102
102
|
|
103
103
|
if refl.options[:polymorphic]
|
@@ -113,7 +113,7 @@ module Hobo
|
|
113
113
|
end
|
114
114
|
|
115
115
|
# team_is_not(a_team)
|
116
|
-
|
116
|
+
elsif name =~ /^(.*)_is_not$/ && (refl = reflection($1)) && refl.macro.in?([:has_one, :belongs_to])
|
117
117
|
return true if check_only
|
118
118
|
|
119
119
|
if refl.options[:polymorphic]
|
@@ -132,7 +132,7 @@ module Hobo
|
|
132
132
|
# --- Column Queries --- #
|
133
133
|
|
134
134
|
# name_is(str)
|
135
|
-
|
135
|
+
elsif name =~ /^(.*)_is$/ && (col = column($1))
|
136
136
|
return true if check_only
|
137
137
|
|
138
138
|
def_scope do |str|
|
@@ -140,7 +140,7 @@ module Hobo
|
|
140
140
|
end
|
141
141
|
|
142
142
|
# name_is_not(str)
|
143
|
-
|
143
|
+
elsif name =~ /^(.*)_is_not$/ && (col = column($1))
|
144
144
|
return true if check_only
|
145
145
|
|
146
146
|
def_scope do |str|
|
@@ -148,7 +148,7 @@ module Hobo
|
|
148
148
|
end
|
149
149
|
|
150
150
|
# name_contains(str)
|
151
|
-
|
151
|
+
elsif name =~ /^(.*)_contains$/ && (col = column($1))
|
152
152
|
return true if check_only
|
153
153
|
|
154
154
|
def_scope do |str|
|
@@ -156,7 +156,7 @@ module Hobo
|
|
156
156
|
end
|
157
157
|
|
158
158
|
# name_does_not_contain
|
159
|
-
|
159
|
+
elsif name =~ /^(.*)_does_not_contain$/ && (col = column($1))
|
160
160
|
return true if check_only
|
161
161
|
|
162
162
|
def_scope do |str|
|
@@ -164,7 +164,7 @@ module Hobo
|
|
164
164
|
end
|
165
165
|
|
166
166
|
# name_starts(str)
|
167
|
-
|
167
|
+
elsif name =~ /^(.*)_starts$/ && (col = column($1))
|
168
168
|
return true if check_only
|
169
169
|
|
170
170
|
def_scope do |str|
|
@@ -172,7 +172,7 @@ module Hobo
|
|
172
172
|
end
|
173
173
|
|
174
174
|
# name_does_not_start
|
175
|
-
|
175
|
+
elsif name =~ /^(.*)_does_not_start$/ && (col = column($1))
|
176
176
|
return true if check_only
|
177
177
|
|
178
178
|
def_scope do |str|
|
@@ -180,7 +180,7 @@ module Hobo
|
|
180
180
|
end
|
181
181
|
|
182
182
|
# name_ends(str)
|
183
|
-
|
183
|
+
elsif name =~ /^(.*)_ends$/ && (col = column($1))
|
184
184
|
return true if check_only
|
185
185
|
|
186
186
|
def_scope do |str|
|
@@ -188,7 +188,7 @@ module Hobo
|
|
188
188
|
end
|
189
189
|
|
190
190
|
# name_does_not_end(str)
|
191
|
-
|
191
|
+
elsif name =~ /^(.*)_does_not_end$/ && (col = column($1))
|
192
192
|
return true if check_only
|
193
193
|
|
194
194
|
def_scope do |str|
|
@@ -196,7 +196,7 @@ module Hobo
|
|
196
196
|
end
|
197
197
|
|
198
198
|
# published (a boolean column)
|
199
|
-
|
199
|
+
elsif (col = column(name)) && (col.type == :boolean)
|
200
200
|
return true if check_only
|
201
201
|
|
202
202
|
def_scope do
|
@@ -204,7 +204,7 @@ module Hobo
|
|
204
204
|
end
|
205
205
|
|
206
206
|
# not_published
|
207
|
-
|
207
|
+
elsif name =~ /^not_(.*)$/ && (col = column($1)) && (col.type == :boolean)
|
208
208
|
return true if check_only
|
209
209
|
|
210
210
|
def_scope do
|
@@ -212,7 +212,7 @@ module Hobo
|
|
212
212
|
end
|
213
213
|
|
214
214
|
# published_before(time)
|
215
|
-
|
215
|
+
elsif name =~ /^(.*)_before$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp])
|
216
216
|
return true if check_only
|
217
217
|
|
218
218
|
def_scope do |time|
|
@@ -220,7 +220,7 @@ module Hobo
|
|
220
220
|
end
|
221
221
|
|
222
222
|
# published_after(time)
|
223
|
-
|
223
|
+
elsif name =~ /^(.*)_after$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp])
|
224
224
|
return true if check_only
|
225
225
|
|
226
226
|
def_scope do |time|
|
@@ -228,7 +228,7 @@ module Hobo
|
|
228
228
|
end
|
229
229
|
|
230
230
|
# published_between(time1, time2)
|
231
|
-
|
231
|
+
elsif name =~ /^(.*)_between$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp])
|
232
232
|
return true if check_only
|
233
233
|
|
234
234
|
def_scope do |time1, time2|
|
@@ -236,12 +236,12 @@ module Hobo
|
|
236
236
|
end
|
237
237
|
|
238
238
|
# active (a lifecycle state)
|
239
|
-
|
239
|
+
elsif @klass.has_lifecycle? && name.to_sym.in?(@klass::Lifecycle.state_names)
|
240
240
|
return true if check_only
|
241
241
|
|
242
242
|
if @klass::Lifecycle.state_names.length == 1
|
243
243
|
# nothing to check for - create a dummy scope
|
244
|
-
def_scope { @klass.
|
244
|
+
def_scope { @klass.where '' }
|
245
245
|
true
|
246
246
|
else
|
247
247
|
def_scope do
|
@@ -250,92 +250,94 @@ module Hobo
|
|
250
250
|
end
|
251
251
|
|
252
252
|
# self is / is not
|
253
|
-
|
253
|
+
elsif name == "is"
|
254
254
|
return true if check_only
|
255
255
|
|
256
256
|
def_scope do |record|
|
257
257
|
@klass.where "#{@klass.table_name}.#{@klass.primary_key} = ?", record
|
258
258
|
end
|
259
259
|
|
260
|
-
|
260
|
+
elsif name == "is_not"
|
261
261
|
return true if check_only
|
262
262
|
|
263
263
|
def_scope do |record|
|
264
264
|
@klass.where "#{@klass.table_name}.#{@klass.primary_key} <> ?", record
|
265
265
|
end
|
266
266
|
|
267
|
+
else
|
267
268
|
|
268
|
-
|
269
|
-
return true if check_only
|
269
|
+
case name
|
270
270
|
|
271
|
-
|
272
|
-
|
273
|
-
end
|
271
|
+
when "by_most_recent"
|
272
|
+
return true if check_only
|
274
273
|
|
275
|
-
|
276
|
-
|
274
|
+
def_scope do
|
275
|
+
@klass.order "#{@klass.table_name}.created_at DESC"
|
276
|
+
end
|
277
277
|
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
278
|
+
when "recent"
|
279
|
+
return true if check_only
|
280
|
+
|
281
|
+
if "created_at".in?(@klass.columns.*.name)
|
282
|
+
def_scope do |*args|
|
283
|
+
count = args.first || 6
|
284
|
+
@klass.order("#{@klass.table_name}.created_at DESC").limit(count)
|
285
|
+
end
|
286
|
+
else
|
287
|
+
def_scope do |*args|
|
288
|
+
count = args.first || 6
|
289
|
+
limit(count)
|
290
|
+
end
|
282
291
|
end
|
283
|
-
|
292
|
+
|
293
|
+
when "order_by"
|
294
|
+
return true if check_only
|
295
|
+
|
296
|
+
klass = @klass
|
284
297
|
def_scope do |*args|
|
285
|
-
|
286
|
-
|
298
|
+
field, asc = args
|
299
|
+
type = klass.attr_type(field)
|
300
|
+
if type.nil? #a virtual attribute from an SQL alias, e.g., 'total' from 'COUNT(*) AS total'
|
301
|
+
colspec = "#{field}" # don't prepend the table name
|
302
|
+
elsif type.respond_to?(:name_attribute) && (name = type.name_attribute)
|
303
|
+
include = field
|
304
|
+
colspec = "#{type.table_name}.#{name}"
|
305
|
+
else
|
306
|
+
colspec = "#{klass.table_name}.#{field}"
|
307
|
+
end
|
308
|
+
@klass.includes(include).order("#{colspec} #{asc._?.upcase}")
|
287
309
|
end
|
288
|
-
end
|
289
310
|
|
290
|
-
when name == "order_by"
|
291
|
-
return true if check_only
|
292
311
|
|
293
|
-
|
294
|
-
|
295
|
-
field, asc = args
|
296
|
-
type = klass.attr_type(field)
|
297
|
-
if type.nil? #a virtual attribute from an SQL alias, e.g., 'total' from 'COUNT(*) AS total'
|
298
|
-
colspec = "#{field}" # don't prepend the table name
|
299
|
-
elsif type.respond_to?(:name_attribute) && (name = type.name_attribute)
|
300
|
-
include = field
|
301
|
-
colspec = "#{type.table_name}.#{name}"
|
302
|
-
else
|
303
|
-
colspec = "#{klass.table_name}.#{field}"
|
304
|
-
end
|
305
|
-
@klass.includes(include).order("#{colspec} #{asc._?.upcase}")
|
306
|
-
end
|
312
|
+
when "include"
|
313
|
+
return true if check_only
|
307
314
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
Rails.logger.warn "Automatic scope :include has been deprecated: use :includes instead."
|
312
|
-
return true if check_only
|
315
|
+
def_scope do |inclusions|
|
316
|
+
@klass.includes(inclusions)
|
317
|
+
end
|
313
318
|
|
314
|
-
|
315
|
-
|
316
|
-
end
|
319
|
+
when "search"
|
320
|
+
return true if check_only
|
317
321
|
|
318
|
-
|
319
|
-
|
322
|
+
def_scope do |query, *fields|
|
323
|
+
match_keyword = ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
320
324
|
|
321
|
-
|
322
|
-
|
325
|
+
words = query.split
|
326
|
+
args = []
|
327
|
+
word_queries = words.map do |word|
|
328
|
+
field_query = '(' + fields.map { |field| "(#{@klass.table_name}.#{field} #{match_keyword} ?)" }.join(" OR ") + ')'
|
329
|
+
args += ["%#{word}%"] * fields.length
|
330
|
+
field_query
|
331
|
+
end
|
323
332
|
|
324
|
-
|
325
|
-
args = []
|
326
|
-
word_queries = words.map do |word|
|
327
|
-
field_query = '(' + fields.map { |field| "(#{@klass.table_name}.#{field} #{match_keyword} ?)" }.join(" OR ") + ')'
|
328
|
-
args += ["%#{word}%"] * fields.length
|
329
|
-
field_query
|
333
|
+
@klass.where *([word_queries.join(" AND ")] + args)
|
330
334
|
end
|
331
335
|
|
332
|
-
|
336
|
+
else
|
337
|
+
matched_scope = false
|
333
338
|
end
|
334
339
|
|
335
|
-
else
|
336
|
-
matched_scope = false
|
337
340
|
end
|
338
|
-
|
339
341
|
matched_scope
|
340
342
|
end
|
341
343
|
|
@@ -2,7 +2,7 @@ require 'digest/sha1'
|
|
2
2
|
|
3
3
|
module Hobo
|
4
4
|
module Model
|
5
|
-
module
|
5
|
+
module User
|
6
6
|
|
7
7
|
@user_models = []
|
8
8
|
|
@@ -32,7 +32,7 @@ module Hobo
|
|
32
32
|
end
|
33
33
|
|
34
34
|
validates_confirmation_of :password, :if => :new_password_required?
|
35
|
-
|
35
|
+
password_validations
|
36
36
|
validate :validate_current_password_when_changing_password
|
37
37
|
|
38
38
|
# Virtual attributes for setting and changing the password
|
@@ -56,6 +56,10 @@ module Hobo
|
|
56
56
|
# Additional classmethods for authentication
|
57
57
|
module ClassMethods
|
58
58
|
|
59
|
+
# Validation of the plaintext password
|
60
|
+
def password_validations
|
61
|
+
validates_length_of :password, :within => 4..40, :if => :new_password_required?
|
62
|
+
end
|
59
63
|
|
60
64
|
def login_attribute=(attr, validate=true)
|
61
65
|
@login_attribute = attr = attr.to_sym
|
@@ -168,15 +172,9 @@ module Hobo
|
|
168
172
|
(new_record? && password) || lifecycle_changing_password? || changing_password?
|
169
173
|
end
|
170
174
|
|
171
|
-
# Validation of the plaintext password. Override this function to change your validation.
|
172
|
-
def validate_password
|
173
|
-
errors.add(:password, I18n.t("hobo.messages.validate_password", :default => "must be at least 6 characters long and must not consist solely of lowercase letters")) \
|
174
|
-
if new_password_required? && (password.nil? || password.length<6 || /^[[:lower:]]*$/.match(password))
|
175
|
-
end
|
176
175
|
|
177
176
|
def validate_current_password_when_changing_password
|
178
|
-
errors.add :current_password, I18n.t("hobo.messages.current_password_is_not_correct", :default => "is not correct")
|
179
|
-
if changing_password? && !authenticated?(current_password)
|
177
|
+
changing_password? && !authenticated?(current_password) and errors.add :current_password, I18n.t("hobo.messages.current_password_is_not_correct", :default => "is not correct")
|
180
178
|
end
|
181
179
|
|
182
180
|
end
|
@@ -19,7 +19,7 @@ has_body = (!show_link && description_attribute) || creator_link || creator_a
|
|
19
19
|
|
20
20
|
show_title = !show_link && (name_attribute || !has_body)
|
21
21
|
|
22
|
-
model_key = model.
|
22
|
+
model_key = model.name.pluralize.underscore
|
23
23
|
-%>
|
24
24
|
<def tag="card" for="<%= model.name %>">
|
25
25
|
<card class="<%= model_class %>" param="default" merge>
|
@@ -53,7 +53,7 @@ model_key = model.to_s.underscore
|
|
53
53
|
<view:<%= creator_attribute %> param="creator"/>
|
54
54
|
<% end -%>
|
55
55
|
<% if primary_collection -%>
|
56
|
-
<ht key="<%=
|
56
|
+
<ht key="<%= primary_collection.to_s.pluralize.underscore %>.collection.count" count="&this.<%= primary_collection %>.size">
|
57
57
|
<count:<%= primary_collection%> param/>
|
58
58
|
</ht>
|
59
59
|
<% end -%>
|
@@ -1,11 +1,10 @@
|
|
1
1
|
<% each_controller do -%>
|
2
2
|
<%
|
3
|
-
next unless @controller < Hobo::Controller::Model
|
4
3
|
form_fields = standard_fields :belongs_to, :has_many
|
5
4
|
|
6
5
|
cancel_to_show_page = linkable?(:show)
|
7
6
|
cancel_to_index_page = !cancel_to_index_page && linkable?(:index)
|
8
|
-
model_key = model.
|
7
|
+
model_key = model.name.tableize
|
9
8
|
-%>
|
10
9
|
<def tag="form" for="<%= model.name %>">
|
11
10
|
<form merge param="default">
|
@@ -30,7 +29,7 @@ model_key = model.to_s.underscore
|
|
30
29
|
</def>
|
31
30
|
<% end -%>
|
32
31
|
|
33
|
-
<% transitions.
|
32
|
+
<% transitions.each do |transition| -%>
|
34
33
|
<def tag="<%= transition.name.to_s.dasherize %>-form" polymorphic/>
|
35
34
|
<def tag="<%= transition.name.to_s.dasherize %>-form" for="<%= model.name %>">
|
36
35
|
<form lifecycle="<%= transition.name %>" merge param="default">
|
@@ -38,10 +37,10 @@ model_key = model.to_s.underscore
|
|
38
37
|
<input type="hidden" name="key" value="&this.lifecycle.provided_key" if="&this.lifecycle.provided_key"/>
|
39
38
|
<field-list fields="<%= transition.parameters * ', ' %>" param/>
|
40
39
|
<div param="actions">
|
41
|
-
<submit label="#{
|
40
|
+
<submit label="#{ht '<%= model_key %>.actions.<%= transition.name.to_s %>', :default=>['<%= transition.name.to_s.titleize %>']}" param/><or-cancel param="cancel"/>
|
42
41
|
</div>
|
43
42
|
</form>
|
44
43
|
</def>
|
45
44
|
<% end -%>
|
46
45
|
|
47
|
-
<% end # of each_model do -%>
|
46
|
+
<% end # of each_model do -%>
|
@@ -3,8 +3,8 @@
|
|
3
3
|
<def tag="main-nav">
|
4
4
|
<navigation class="main-nav" merge-attrs param="default">
|
5
5
|
<nav-item href="#{base_url}/">Home</nav-item>
|
6
|
-
<% models.select { |m| linkable?(m, :index) }.each do |m| -%>
|
7
|
-
<nav-item with="&<%= m.name %>"><ht key="<%= m.
|
6
|
+
<% models.select { |m| linkable?(m, :index) }[0..4].each do |m| -%>
|
7
|
+
<nav-item with="&<%= m.name %>"><ht key="<%= m.name.tableize %>.nav_item"><model-name-human/></ht></nav-item>
|
8
8
|
<% end -%>
|
9
9
|
</navigation>
|
10
10
|
</def>
|
@@ -12,16 +12,16 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
<% each_controller do -%>
|
15
|
-
|
15
|
+
|
16
16
|
<!-- ====== <%= model.name %> Pages ====== -->
|
17
17
|
<%
|
18
18
|
new_link = linkable?(:new)
|
19
19
|
new_form = !new_link && linkable?(model, :create, :method => :post)
|
20
|
-
model_key = model.
|
20
|
+
model_key = model.name.tableize
|
21
21
|
-%>
|
22
22
|
|
23
23
|
<def tag="index-page" for="<%= model.name %>">
|
24
|
-
<page merge title="#{ht '<%= model_key %>.index.title', :default=>[model.model_name.human(:count=>
|
24
|
+
<page merge title="#{ht '<%= model_key %>.index.title', :default=>[model.model_name.human(:count=>model.count)] }">
|
25
25
|
<body: class="index-page <%= model_class %>" param/>
|
26
26
|
|
27
27
|
<content: param>
|
@@ -33,7 +33,7 @@ model_key = model.to_s.underscore
|
|
33
33
|
</h2>
|
34
34
|
|
35
35
|
<p param="count" if>
|
36
|
-
<ht key="<%= model_key %>.collection.count" count="&
|
36
|
+
<ht key="<%= model_key %>.collection.count" count="&this.size">
|
37
37
|
<count summary/>
|
38
38
|
</ht>
|
39
39
|
</p>
|
@@ -110,7 +110,7 @@ edit_link = linkable?(:edit)
|
|
110
110
|
main_content = model.primary_content_attribute
|
111
111
|
show_fields = standard_fields(:belongs_to).*.to_s - [model.name_attribute, main_content, creator, back_link, *boolean_fields].*.to_s
|
112
112
|
|
113
|
-
is_user_model = model < Hobo::Model::
|
113
|
+
is_user_model = model < Hobo::Model::User
|
114
114
|
|
115
115
|
collection = model.view_hints.primary_children
|
116
116
|
if collection
|
@@ -124,10 +124,11 @@ end
|
|
124
124
|
|
125
125
|
unless model.view_hints.secondary_children.empty?
|
126
126
|
aside_collections = model.view_hints.secondary_children.map { |c| [model.reflections[c], model.reverse_reflection(c)] }
|
127
|
+
aside_collections.reject! { |refl, reverse| reverse.nil? }
|
127
128
|
end
|
128
129
|
-%>
|
129
130
|
<def tag="show-page" for="<%= model.name %>">
|
130
|
-
<page merge title="#{ht '<%=model_key %>.show.title', :default=>['<%=sq_escape model_name %>']
|
131
|
+
<page merge title="#{ht '<%=model_key %>.show.title', :default=>['<%=sq_escape model_name %>'] }">
|
131
132
|
|
132
133
|
<body: class="show-page <%= model_class %>" param/>
|
133
134
|
|
@@ -141,8 +142,8 @@ end
|
|
141
142
|
<a:<%= back_link %> param="parent-link">« <ht key="<%= model_key %>.actions.back_to_parent" parent="<%= back_link_human_name %>" name="&this">Back to <name/></ht></a:<%= back_link %>>
|
142
143
|
<% end -%>
|
143
144
|
<h2 param="heading">
|
144
|
-
<ht key="<%= model_key %>.show.heading" name="
|
145
|
-
|
145
|
+
<ht key="<%= model_key %>.show.heading" name="&this.respond_to?(:name) ? this.name : ''">
|
146
|
+
<name/>
|
146
147
|
</ht>
|
147
148
|
</h2>
|
148
149
|
<% if boolean_fields -%>
|
@@ -159,7 +160,7 @@ end
|
|
159
160
|
<% if edit_link -%>
|
160
161
|
|
161
162
|
<a action="edit" if="&can_edit?" param="edit-link">
|
162
|
-
<ht key="<%= model_key %>.actions.edit" name="
|
163
|
+
<ht key="<%= model_key %>.actions.edit" name="&this.respond_to?(:name) ? this.name : ''">
|
163
164
|
Edit <%= model_name %>
|
164
165
|
</ht>
|
165
166
|
</a>
|
@@ -168,7 +169,7 @@ end
|
|
168
169
|
|
169
170
|
<section param="content-body">
|
170
171
|
<% if main_content -%>
|
171
|
-
<view:<%= main_content %> param="description"
|
172
|
+
<view:<%= main_content %> param="description"/>
|
172
173
|
<% end -%>
|
173
174
|
<% if show_fields.any? -%>
|
174
175
|
<field-list fields="<%= show_fields * ', ' %>" param/>
|
@@ -176,7 +177,7 @@ end
|
|
176
177
|
<% if collection -%>
|
177
178
|
<section param="collection-section">
|
178
179
|
<h3 param="collection-heading">
|
179
|
-
<ht key="<%=
|
180
|
+
<ht key="<%= collection.to_s.tableize %>.collection.heading" count="&this.<%= collection.to_s %>.count" >
|
180
181
|
<human-collection-name collection="<%= collection %>" your/>
|
181
182
|
</ht>
|
182
183
|
</h3>
|
@@ -189,21 +190,21 @@ end
|
|
189
190
|
<% if add_link -%>
|
190
191
|
|
191
192
|
<a:<%= collection %> action="new" if="&can_create?(@<%= model.name.underscore %>.<%= collection %>)" param="new-link">
|
192
|
-
<ht key="<%=
|
193
|
-
New <%=
|
193
|
+
<ht key="<%= collection.to_s.tableize %>.actions.new" count="1">
|
194
|
+
New <%= collection.to_s.singularize.titleize %>
|
194
195
|
</ht>
|
195
196
|
</a:<%= collection %>>
|
196
197
|
<% elsif add_form -%>
|
197
198
|
|
198
199
|
<section param="add-to-collection" if="&can_create?(@<%= model.name.underscore %>.<%= collection %>)">
|
199
200
|
<h3 param="add-form-heading">
|
200
|
-
<ht key="<%=
|
201
|
-
Add <%= a_or_an
|
201
|
+
<ht key="<%= collection.to_s.pluralize %>.collection.add_form_heading" count="1">
|
202
|
+
Add <%= a_or_an collection.to_s.singularize.titleize %>
|
202
203
|
</ht>
|
203
204
|
</h3>
|
204
205
|
<form with="&@<%= collection_class.name.underscore %> || new_for_current_user(@<%= model.name.underscore %>.<%= collection %>)" owner="<%= owner %>" without-cancel param>
|
205
206
|
<field-list: skip="<%= owner %>"/>
|
206
|
-
<submit: label="#{ht '<%= sq_escape
|
207
|
+
<submit: label="#{ht '<%= sq_escape collection.to_s.pluralize %>.actions.add', :default=>['Add'] }"/>
|
207
208
|
</form>
|
208
209
|
</section>
|
209
210
|
<% end -%>
|
@@ -215,14 +216,14 @@ end
|
|
215
216
|
|
216
217
|
<aside param>
|
217
218
|
<% for refl, reverse_refl in aside_collections -%>
|
218
|
-
<% if
|
219
|
+
<% if linkable?(refl.klass, :"index_for_#{reverse_refl.name}") -%>
|
219
220
|
<collection-preview:<%= refl.name %>.recent param="<%= refl.name %>-preview">
|
220
221
|
<heading-content:><human-collection-name with="&this.origin" collection="<%= refl.name %>" your/></heading-content:>
|
221
222
|
</collection-preview:<%= refl.name %>.recent>
|
222
223
|
<% else -%>
|
223
224
|
<section param="<%= refl.name %>-collection-section">
|
224
225
|
<h3 param="<%= refl.name %>-collection-heading">
|
225
|
-
<ht key="<%= refl.
|
226
|
+
<ht key="<%= refl.name.to_s.tableize %>.collection.heading" count="&this.<%= refl.name.to_s %>.count" >
|
226
227
|
<human-collection-name collection="<%= refl.name %>" your/>
|
227
228
|
</ht>
|
228
229
|
</h3>
|
@@ -243,14 +244,14 @@ end
|
|
243
244
|
name_attribute = model.name_attribute
|
244
245
|
-%>
|
245
246
|
<def tag="edit-page" for="<%= model.name %>">
|
246
|
-
<page merge title="#{ht '<%= model_key %>.edit.title', :default=>['Edit <%= sq_escape model_name %>']
|
247
|
+
<page merge title="#{ht '<%= model_key %>.edit.title', :default=>['Edit <%= sq_escape model_name %>'] }">
|
247
248
|
|
248
249
|
<body: class="edit-page <%= model_class %>" param/>
|
249
250
|
|
250
251
|
<content:>
|
251
252
|
<section param="content-header">
|
252
253
|
<h2 param="heading">
|
253
|
-
<ht key="<%= model_key %>.edit.heading" name="
|
254
|
+
<ht key="<%= model_key %>.edit.heading" name="&this.respond_to?(:name) ? this.name : ''">
|
254
255
|
Edit <%= model_name %>
|
255
256
|
</ht>
|
256
257
|
</h2>
|
@@ -272,7 +273,7 @@ owner_model = model.reflections[owner].klass
|
|
272
273
|
linkable_owner = linkable?(owner_model, :show)
|
273
274
|
owner_tag = linkable_owner ? "a" : "name"
|
274
275
|
|
275
|
-
owner_is_user = owner_model < Hobo::Model::
|
276
|
+
owner_is_user = owner_model < Hobo::Model::User
|
276
277
|
|
277
278
|
owner = model.reflections[owner].macro == :has_many ? owner.to_s.singularize : owner.to_s
|
278
279
|
-%>
|
@@ -282,7 +283,7 @@ new_link = :new.in?(actions)
|
|
282
283
|
-%>
|
283
284
|
<def tag="index-for-<%= owner.dasherize %>-page" polymorphic/>
|
284
285
|
<def tag="index-for-<%= owner.dasherize %>-page" for="<%= model.name %>">
|
285
|
-
<page merge title="#{ht '<%= model_key %>.index_for_owner.title', :
|
286
|
+
<page merge title="#{ht '<%= model_key %>.index_for_owner.title', :default=>['<%= sq_escape(model_name(:plural)) %> for']} #{name :with => @<%= owner %>, :no_wrapper => true}">
|
286
287
|
<body: class="index-for-owner-page <%= owner.dasherize %> <%= model_class %>" param/>
|
287
288
|
<content: param>
|
288
289
|
<header param="content-header">
|
@@ -305,7 +306,7 @@ new_link = :new.in?(actions)
|
|
305
306
|
</h3>
|
306
307
|
<% end -%>
|
307
308
|
<p param="count" if>
|
308
|
-
<ht key="<%= model_key %>.collection.count" count="&
|
309
|
+
<ht key="<%= model_key %>.collection.count" count="&this.size">
|
309
310
|
<count summary/>
|
310
311
|
</ht>
|
311
312
|
</p>
|
@@ -313,7 +314,7 @@ new_link = :new.in?(actions)
|
|
313
314
|
|
314
315
|
<section param="content-body">
|
315
316
|
<% if new_link -%>
|
316
|
-
<a action="new" to="
|
317
|
+
<a action="new" to="&model" param="new-link">
|
317
318
|
<ht key="<%= model_key %>.actions.new" >New <%=model_name %></ht>
|
318
319
|
</a>
|
319
320
|
|