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.
Files changed (155) hide show
  1. data/CHANGES.txt +234 -282
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/app/controllers/dev_controller.rb +2 -2
  5. data/bin/hobo +3 -3
  6. data/config/routes.rb +1 -1
  7. data/doctests/hobo/lifecycles.rdoctest +1 -0
  8. data/doctests/hobo/model.rdoctest +5 -0
  9. data/doctests/hobo/multi_model_forms.rdoctest +5 -4
  10. data/doctests/hobo/scopes.rdoctest +8 -11
  11. data/doctests/prepare_testapp.rb +1 -2
  12. data/hobo.gemspec +2 -2
  13. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
  14. data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
  15. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
  16. data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
  17. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
  18. data/lib/generators/hobo/basic/basic_generator.rb +17 -0
  19. data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
  20. data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
  21. data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
  22. data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
  23. data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
  24. data/lib/generators/hobo/controller.rb +1 -6
  25. data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
  26. data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
  27. data/lib/generators/hobo/hints/hints_generator.rb +12 -0
  28. data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
  29. data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
  30. data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
  31. data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
  32. data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
  33. data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
  34. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
  35. data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
  36. data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
  37. data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
  38. data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
  39. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
  40. data/lib/generators/hobo/model.rb +13 -0
  41. data/lib/generators/hobo/model/USAGE +3 -2
  42. data/lib/generators/hobo/model/model_generator.rb +1 -2
  43. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
  44. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
  45. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
  46. data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
  47. data/lib/generators/hobo/rapid/templates/reset.css +1 -1
  48. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
  49. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  50. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
  51. data/lib/generators/hobo/resource/resource_generator.rb +1 -1
  52. data/lib/generators/hobo/routes/router.rb +4 -4
  53. data/lib/generators/hobo/routes/routes_generator.rb +1 -12
  54. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
  55. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
  56. data/lib/generators/hobo/subsite.rb +5 -18
  57. data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
  58. data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
  59. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
  60. data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
  61. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
  62. data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
  63. data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
  64. data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
  65. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
  66. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
  67. data/lib/generators/hobo/user_model/USAGE +9 -2
  68. data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
  69. data/lib/hobo.rb +7 -13
  70. data/lib/hobo/controller.rb +14 -21
  71. data/lib/hobo/controller/authentication_support.rb +23 -1
  72. data/lib/hobo/controller/model.rb +53 -48
  73. data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
  74. data/lib/hobo/engine.rb +11 -25
  75. data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
  76. data/lib/hobo/extensions/active_model/translation.rb +1 -1
  77. data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
  78. data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
  79. data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
  80. data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
  81. data/lib/hobo/extensions/active_record/scopes.rb +31 -0
  82. data/lib/hobo/extensions/array.rb +1 -13
  83. data/lib/hobo/helper.rb +6 -27
  84. data/lib/hobo/helper/translations.rb +90 -39
  85. data/lib/hobo/model.rb +20 -72
  86. data/lib/hobo/model/lifecycles.rb +11 -12
  87. data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
  88. data/lib/hobo/model/lifecycles/transition.rb +0 -1
  89. data/lib/hobo/model/permissions.rb +3 -2
  90. data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
  91. data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
  92. data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
  93. data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
  94. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
  95. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
  96. data/lib/hobo/rapid/helper.rb +5 -10
  97. data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
  98. data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
  99. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
  100. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
  101. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
  102. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
  103. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
  104. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
  105. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
  106. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
  107. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
  108. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
  109. data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
  110. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
  111. data/lib/hobo/routes.rb +23 -22
  112. data/lib/hobo/view_hints.rb +101 -0
  113. data/test/irt/generators/admin_subsite.irt +1 -1
  114. data/test/irt/generators/{assets.irt → basic.irt} +2 -2
  115. data/test/irt/generators/front_controller.irt +4 -2
  116. data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
  117. data/test/irt/generators/subsite.irt +1 -1
  118. data/test/permissions/test_permissions.rb +103 -103
  119. metadata +108 -69
  120. data/lib/generators/hobo/admin_subsite/USAGE +0 -25
  121. data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
  122. data/lib/generators/hobo/assets/USAGE +0 -5
  123. data/lib/generators/hobo/assets/assets_generator.rb +0 -18
  124. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
  125. data/lib/generators/hobo/controller/USAGE +0 -3
  126. data/lib/generators/hobo/i18n/USAGE +0 -3
  127. data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
  128. data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
  129. data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
  130. data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
  131. data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
  132. data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
  133. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
  134. data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
  135. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
  136. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  137. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  138. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  139. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
  140. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
  141. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
  142. data/lib/generators/hobo/resource/USAGE +0 -39
  143. data/lib/generators/hobo/subsite/USAGE +0 -24
  144. data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
  145. data/lib/generators/hobo/test_framework/USAGE +0 -2
  146. data/lib/generators/hobo/user_controller/USAGE +0 -3
  147. data/lib/generators/hobo/user_mailer/USAGE +0 -2
  148. data/lib/generators/hobo/user_resource/USAGE +0 -10
  149. data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
  150. data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
  151. data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
  152. data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
  153. data/lib/hobo/extensions/i18n.rb +0 -17
  154. data/lib/hobo/helper/translations/normalizer.rb +0 -39
  155. 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
- case
34
+
35
35
  # --- Association Queries --- #
36
36
 
37
37
  # with_players(player1, player2)
38
- when name =~ /^with_(.*)/ && (refl = reflection($1))
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
- when name =~ /^with_(.*)/ && (refl = reflection($1.pluralize))
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
- when name =~ /^any_of_(.*)/ && (refl = reflection($1))
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
- when name =~ /^without_(.*)/ && (refl = reflection($1))
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
- when name =~ /^without_(.*)/ && (refl = reflection($1.pluralize))
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
- when name =~ /^(.*)_is$/ && (refl = reflection($1)) && refl.macro.in?([:has_one, :belongs_to])
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
- when name =~ /^(.*)_is_not$/ && (refl = reflection($1)) && refl.macro.in?([:has_one, :belongs_to])
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
- when name =~ /^(.*)_is$/ && (col = column($1))
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
- when name =~ /^(.*)_is_not$/ && (col = column($1))
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
- when name =~ /^(.*)_contains$/ && (col = column($1))
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
- when name =~ /^(.*)_does_not_contain$/ && (col = column($1))
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
- when name =~ /^(.*)_starts$/ && (col = column($1))
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
- when name =~ /^(.*)_does_not_start$/ && (col = column($1))
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
- when name =~ /^(.*)_ends$/ && (col = column($1))
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
- when name =~ /^(.*)_does_not_end$/ && (col = column($1))
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
- when (col = column(name)) && (col.type == :boolean)
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
- when name =~ /^not_(.*)$/ && (col = column($1)) && (col.type == :boolean)
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
- when name =~ /^(.*)_before$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp])
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
- when name =~ /^(.*)_after$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp])
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
- when name =~ /^(.*)_between$/ && (col = column("#{$1}_at") || column("#{$1}_date") || column("#{$1}_on")) && col.type.in?([:date, :datetime, :time, :timestamp])
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
- when @klass.has_lifecycle? && name.to_sym.in?(@klass::Lifecycle.state_names)
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.scoped }
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
- when name == "is"
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
- when name == "is_not"
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
- when name == "by_most_recent"
269
- return true if check_only
269
+ case name
270
270
 
271
- def_scope do
272
- @klass.order "#{@klass.table_name}.created_at DESC"
273
- end
271
+ when "by_most_recent"
272
+ return true if check_only
274
273
 
275
- when name == "recent"
276
- return true if check_only
274
+ def_scope do
275
+ @klass.order "#{@klass.table_name}.created_at DESC"
276
+ end
277
277
 
278
- if "created_at".in?(@klass.columns.*.name)
279
- def_scope do |*args|
280
- count = args.first || 6
281
- @klass.order("#{@klass.table_name}.created_at DESC").limit(count)
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
- else
292
+
293
+ when "order_by"
294
+ return true if check_only
295
+
296
+ klass = @klass
284
297
  def_scope do |*args|
285
- count = args.first || 6
286
- limit(count)
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
- klass = @klass
294
- def_scope do |*args|
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
- when name == "include"
309
- # DEPRECATED: it clashes with Module.include when called on an ActiveRecord::Relation
310
- # after a scope chain, if you didn't call it on the class itself first
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
- def_scope do |inclusions|
315
- @klass.includes(inclusions)
316
- end
319
+ when "search"
320
+ return true if check_only
317
321
 
318
- when name == "search"
319
- return true if check_only
322
+ def_scope do |query, *fields|
323
+ match_keyword = ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
320
324
 
321
- def_scope do |query, *fields|
322
- match_keyword = ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
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
- words = query.split
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
- @klass.where *([word_queries.join(" AND ")] + args)
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 UserBase
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
- validate :validate_password
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.to_s.underscore
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="<%= model.reflect_on_association(primary_collection).klass.to_s.underscore %>.collection.count" count="&this.<%= primary_collection %>.size">
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.to_s.underscore
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.uniq{|s| s.name}.each do |transition| -%>
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="#{t 'activerecord.attributes.<%= model_key %>.lifecycle.transitions.<%= transition.name.to_s %>', :default=>['<%= transition.name.to_s.titleize %>']}" param/><or-cancel param="cancel"/>
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.to_s.underscore %>.nav_item" count="100"><model-name-human count="100"/></ht></nav-item>
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
- <% next unless @controller < Hobo::Controller::Model %>
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.to_s.underscore
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=>100)] }">
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="&collection_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::UserBase
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 %>'], :name => name(:no_wrapper => true) }">
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">&laquo; <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="#{name(:no_wrapper => true)}">
145
- <%= model_name %> <name/>
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="#{name(:no_wrapper => true)}">
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="<%= collection_class.to_s.underscore %>.collection.heading" count="&this.<%= collection.to_s %>.count" >
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="<%= collection_class.to_s.underscore %>.actions.new" count="1">
193
- New <%= collection_class.to_s.titleize %>
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="<%= collection_class.to_s.underscore %>.collection.add_form_heading" count="1">
201
- Add <%= a_or_an collection_class.to_s.titleize %>
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 collection_class.to_s.underscore %>.actions.add', :default=>['Add'] }"/>
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 reverse_refl && linkable?(refl.klass, :"index_for_#{reverse_refl.name}") -%>
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.klass.to_s.underscore %>.collection.heading" count="&this.<%= refl.name.to_s %>.count" >
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 %>'], :name => name(:no_wrapper => true) }">
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="#{name(:no_wrapper => true)}">
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::UserBase
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', :count=>100, :default=>['<%= sq_escape(model_name(:plural)) %> for']} #{name :with => @<%= owner %>, :no_wrapper => true}">
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="&collection_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="&@<%= owner %>.<%= collection_name %>" param="new-link">
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