hobo 0.7.5 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (212) hide show
  1. data/{hobo_files/plugin/CHANGES.txt → CHANGES.txt} +391 -0
  2. data/Manifest +146 -0
  3. data/{hobo_files/plugin/README → README} +0 -0
  4. data/bin/hobo +13 -26
  5. data/dryml_generators/rapid/cards.dryml.erb +55 -0
  6. data/dryml_generators/rapid/forms.dryml.erb +43 -0
  7. data/dryml_generators/rapid/pages.dryml.erb +284 -0
  8. data/hobo.gemspec +168 -0
  9. data/init.rb +9 -0
  10. data/lib/action_view_extensions/helpers/tag_helper.rb +7 -0
  11. data/lib/active_record/association_collection.rb +54 -0
  12. data/{hobo_files/plugin/lib → lib}/active_record/association_proxy.rb +12 -4
  13. data/{hobo_files/plugin/lib → lib}/active_record/association_reflection.rb +7 -1
  14. data/{hobo_files/plugin/lib → lib}/extensions/test_case.rb +17 -17
  15. data/{hobo_files/plugin/lib → lib}/hobo.rb +193 -100
  16. data/{hobo_files/plugin/lib → lib}/hobo/authentication_support.rb +8 -8
  17. data/{hobo_files/plugin/lib → lib}/hobo/bundle.rb +90 -89
  18. data/{hobo_files/plugin/lib → lib}/hobo/composite_model.rb +21 -21
  19. data/{hobo_files/plugin/lib → lib}/hobo/controller.rb +38 -25
  20. data/{hobo_files/plugin/lib → lib}/hobo/dev_controller.rb +10 -6
  21. data/lib/hobo/dryml.rb +167 -0
  22. data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_builder.rb +28 -25
  23. data/lib/hobo/dryml/dryml_generator.rb +210 -0
  24. data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_support_controller.rb +1 -1
  25. data/lib/hobo/dryml/parser.rb +3 -0
  26. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/attribute.rb +6 -6
  27. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/base_parser.rb +16 -16
  28. data/lib/hobo/dryml/parser/document.rb +57 -0
  29. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/element.rb +7 -7
  30. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/elements.rb +9 -9
  31. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/source.rb +3 -3
  32. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/text.rb +3 -3
  33. data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/tree_parser.rb +3 -3
  34. data/{hobo_files/plugin/lib → lib}/hobo/dryml/part_context.rb +26 -26
  35. data/{hobo_files/plugin/lib → lib}/hobo/dryml/scoped_variables.rb +15 -15
  36. data/{hobo_files/plugin/lib → lib}/hobo/dryml/tag_parameters.rb +10 -10
  37. data/{hobo_files/plugin/lib → lib}/hobo/dryml/taglib.rb +43 -37
  38. data/{hobo_files/plugin/lib → lib}/hobo/dryml/template.rb +290 -208
  39. data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_environment.rb +173 -115
  40. data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_handler.rb +19 -24
  41. data/lib/hobo/find_for.rb +95 -0
  42. data/{hobo_files/plugin/lib → lib}/hobo/generator.rb +2 -1
  43. data/{hobo_files/plugin/lib → lib}/hobo/guest.rb +12 -4
  44. data/{hobo_files/plugin/lib → lib}/hobo/hobo_helper.rb +146 -117
  45. data/lib/hobo/include_in_save.rb +43 -0
  46. data/lib/hobo/lifecycles.rb +94 -0
  47. data/lib/hobo/lifecycles/actions.rb +73 -0
  48. data/lib/hobo/lifecycles/creator.rb +76 -0
  49. data/lib/hobo/lifecycles/lifecycle.rb +205 -0
  50. data/lib/hobo/lifecycles/state.rb +23 -0
  51. data/lib/hobo/lifecycles/transition.rb +66 -0
  52. data/{hobo_files/plugin/lib → lib}/hobo/model.rb +306 -217
  53. data/{hobo_files/plugin/lib → lib}/hobo/model_controller.rb +342 -213
  54. data/{hobo_files/plugin/lib → lib}/hobo/model_router.rb +151 -120
  55. data/{hobo_files/plugin/lib → lib}/hobo/model_support.rb +9 -9
  56. data/{hobo_files/plugin/lib → lib}/hobo/rapid_helper.rb +30 -23
  57. data/{hobo_files/plugin/lib → lib}/hobo/scopes.rb +22 -68
  58. data/{hobo_files/plugin/lib → lib}/hobo/scopes/apply_scopes.rb +5 -5
  59. data/lib/hobo/scopes/association_proxy_extensions.rb +47 -0
  60. data/{hobo_files/plugin/lib → lib}/hobo/scopes/automatic_scopes.rb +104 -79
  61. data/lib/hobo/scopes/named_scope_extensions.rb +27 -0
  62. data/{hobo_files/plugin/lib → lib}/hobo/static_tags +1 -11
  63. data/{hobo_files/plugin/lib → lib}/hobo/undefined.rb +1 -1
  64. data/{hobo_files/plugin/lib → lib}/hobo/undefined_access_error.rb +0 -0
  65. data/{hobo_files/plugin/lib → lib}/hobo/user.rb +27 -25
  66. data/{hobo_files/plugin/lib → lib}/hobo/user_controller.rb +80 -34
  67. data/{hobo_files/plugin/generators → rails_generators}/hobo/hobo_generator.rb +7 -7
  68. data/rails_generators/hobo/templates/application.css +0 -0
  69. data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/application.dryml +0 -2
  70. data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/dryml-support.js +0 -0
  71. data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/guest.rb +0 -0
  72. data/rails_generators/hobo/templates/initializer.rb +9 -0
  73. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/USAGE +0 -0
  74. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/hobo_front_controller_generator.rb +1 -3
  75. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/controller.rb +1 -1
  76. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/functional_test.rb +0 -0
  77. data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/helper.rb +0 -0
  78. data/rails_generators/hobo_front_controller/templates/index.dryml +25 -0
  79. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/USAGE +0 -0
  80. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/hobo_model_generator.rb +0 -0
  81. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/fixtures.yml +0 -0
  82. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/model.rb +0 -0
  83. data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/unit_test.rb +0 -0
  84. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/USAGE +0 -0
  85. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/hobo_model_controller_generator.rb +0 -7
  86. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/controller.rb +0 -0
  87. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/functional_test.rb +0 -0
  88. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/helper.rb +0 -0
  89. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/hobo_model_resource_generator.rb +0 -0
  90. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/controller.rb +0 -0
  91. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/functional_test.rb +0 -0
  92. data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/helper.rb +0 -0
  93. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/hobo_rapid_generator.rb +21 -11
  94. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/IE7.js +1 -1
  95. data/rails_generators/hobo_rapid/templates/blank.gif +0 -0
  96. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.css +0 -0
  97. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.js +175 -104
  98. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/lowpro.js +0 -0
  99. data/rails_generators/hobo_rapid/templates/nicEditorIcons.gif +0 -0
  100. data/rails_generators/hobo_rapid/templates/nicedit.js +91 -0
  101. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/reset.css +0 -0
  102. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
  103. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/pencil.png +0 -0
  104. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/small_close.png +0 -0
  105. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/spinner.gif +0 -0
  106. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/clean.css +80 -71
  107. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +6 -1
  108. data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/views/clean.dryml +4 -4
  109. data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +73 -0
  110. data/rails_generators/hobo_subsite/templates/application.dryml +1 -0
  111. data/rails_generators/hobo_subsite/templates/controller.rb +5 -0
  112. data/rails_generators/hobo_subsite/templates/site_taglib.dryml +13 -0
  113. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/USAGE +0 -0
  114. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/hobo_user_controller_generator.rb +0 -0
  115. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/controller.rb +0 -0
  116. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/functional_test.rb +0 -0
  117. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/helper.rb +0 -0
  118. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/USAGE +0 -0
  119. data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +30 -0
  120. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/fixtures.yml +0 -0
  121. data/rails_generators/hobo_user_model/templates/forgot_password.erb +10 -0
  122. data/rails_generators/hobo_user_model/templates/mailer.rb +14 -0
  123. data/rails_generators/hobo_user_model/templates/model.rb +55 -0
  124. data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/unit_test.rb +0 -0
  125. data/script/destroy +14 -0
  126. data/script/generate +14 -0
  127. data/{hobo_files/plugin/taglibs → taglibs}/core.dryml +6 -7
  128. data/{hobo_files/plugin/taglibs → taglibs}/rapid.dryml +36 -67
  129. data/{hobo_files/plugin/taglibs → taglibs}/rapid_document_tags.dryml +7 -24
  130. data/{hobo_files/plugin/taglibs → taglibs}/rapid_editing.dryml +51 -50
  131. data/{hobo_files/plugin/taglibs → taglibs}/rapid_forms.dryml +62 -56
  132. data/taglibs/rapid_generics.dryml +33 -0
  133. data/taglibs/rapid_lifecycles.dryml +43 -0
  134. data/{hobo_files/plugin/taglibs → taglibs}/rapid_navigation.dryml +23 -23
  135. data/taglibs/rapid_pages.dryml +183 -0
  136. data/{hobo_files/plugin/taglibs → taglibs}/rapid_plus.dryml +30 -5
  137. data/{hobo_files/plugin/taglibs → taglibs}/rapid_support.dryml +3 -4
  138. data/taglibs/rapid_user_pages.dryml +179 -0
  139. data/{hobo_files/plugin/tasks → tasks}/environments.rake +0 -0
  140. data/{hobo_files/plugin/tasks → tasks}/fix_dryml.rake +0 -0
  141. data/{hobo_files/plugin/tasks → tasks}/generate_tag_reference.rb +21 -22
  142. data/tasks/hobo_tasks.rake +32 -0
  143. data/test/test_generator_helper.rb +29 -0
  144. data/test/test_helper.rb +1 -0
  145. data/test/test_hobo_model_controller_generator.rb +56 -0
  146. data/{hobo_files/plugin/uninstall.rb → uninstall.rb} +0 -0
  147. metadata +240 -225
  148. data/README.txt +0 -18
  149. data/hobo_files/plugin/LICENSE.txt +0 -22
  150. data/hobo_files/plugin/Rakefile +0 -96
  151. data/hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml +0 -24
  152. data/hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml +0 -19
  153. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/banner.gif +0 -0
  154. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-bodytop.gif +0 -0
  155. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-01.gif +0 -0
  156. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-02.gif +0 -0
  157. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-03.gif +0 -0
  158. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-04.gif +0 -0
  159. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-bottom.gif +0 -0
  160. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-left.gif +0 -0
  161. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-right.gif +0 -0
  162. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-top.gif +0 -0
  163. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-blue.gif +0 -0
  164. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-dblue.gif +0 -0
  165. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-green.gif +0 -0
  166. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-purple.gif +0 -0
  167. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-red.gif +0 -0
  168. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/logo.gif +0 -0
  169. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/plus.png +0 -0
  170. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/spinner.gif +0 -0
  171. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-dblue.gif +0 -0
  172. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-green.gif +0 -0
  173. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-purple.gif +0 -0
  174. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-red.gif +0 -0
  175. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-01.gif +0 -0
  176. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-02.gif +0 -0
  177. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-03.gif +0 -0
  178. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-04.gif +0 -0
  179. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-bottom.gif +0 -0
  180. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-left.gif +0 -0
  181. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-right.gif +0 -0
  182. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-top.gif +0 -0
  183. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css +0 -400
  184. data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml +0 -96
  185. data/hobo_files/plugin/generators/hobo_user_model/hobo_user_model_generator.rb +0 -25
  186. data/hobo_files/plugin/generators/hobo_user_model/templates/model.rb +0 -56
  187. data/hobo_files/plugin/init.rb +0 -101
  188. data/hobo_files/plugin/lib/action_view_extensions/base.rb +0 -15
  189. data/hobo_files/plugin/lib/active_record/has_many_association.rb +0 -55
  190. data/hobo_files/plugin/lib/active_record/has_many_through_association.rb +0 -20
  191. data/hobo_files/plugin/lib/hobo/dryml.rb +0 -165
  192. data/hobo_files/plugin/lib/hobo/dryml/parser/document.rb +0 -53
  193. data/hobo_files/plugin/lib/hobo/scopes/association_proxy_extensions.rb +0 -33
  194. data/hobo_files/plugin/lib/hobo/scopes/defined_scope_proxy_extender.rb +0 -90
  195. data/hobo_files/plugin/lib/hobo/scopes/scope_reflection.rb +0 -18
  196. data/hobo_files/plugin/lib/hobo/scopes/scoped_proxy.rb +0 -55
  197. data/hobo_files/plugin/taglib-docs/core.markdown +0 -165
  198. data/hobo_files/plugin/taglib-docs/rapid.markdown +0 -677
  199. data/hobo_files/plugin/taglib-docs/rapid_document_tags.markdown +0 -240
  200. data/hobo_files/plugin/taglib-docs/rapid_editing.markdown +0 -418
  201. data/hobo_files/plugin/taglib-docs/rapid_forms.markdown +0 -562
  202. data/hobo_files/plugin/taglib-docs/rapid_generics.markdown +0 -187
  203. data/hobo_files/plugin/taglib-docs/rapid_navigation.markdown +0 -214
  204. data/hobo_files/plugin/taglib-docs/rapid_pages.markdown +0 -530
  205. data/hobo_files/plugin/taglib-docs/rapid_plus.markdown +0 -65
  206. data/hobo_files/plugin/taglib-docs/rapid_support.markdown +0 -50
  207. data/hobo_files/plugin/taglib-docs/rapid_user_pages.markdown +0 -129
  208. data/hobo_files/plugin/taglibs/rapid_generics.dryml +0 -117
  209. data/hobo_files/plugin/taglibs/rapid_pages.dryml +0 -359
  210. data/hobo_files/plugin/taglibs/rapid_user_pages.dryml +0 -104
  211. data/hobo_files/plugin/tasks/dump_fixtures.rake +0 -70
  212. data/hobo_files/plugin/tasks/hobo_tasks.rake +0 -17
@@ -5,64 +5,85 @@ module Hobo
5
5
  include Hobo::Controller
6
6
 
7
7
  VIEWLIB_DIR = "taglibs"
8
-
8
+
9
9
  DONT_PAGINATE_FORMATS = [ Mime::CSV, Mime::YAML, Mime::JSON, Mime::XML, Mime::ATOM, Mime::RSS ]
10
-
10
+
11
11
  READ_ONLY_ACTIONS = [:index, :show]
12
12
  WRITE_ONLY_ACTIONS = [:create, :update, :destroy]
13
13
  FORM_ACTIONS = [:new, :edit]
14
-
14
+
15
15
  class << self
16
16
 
17
17
  def included(base)
18
- base.class_eval do
18
+ base.class_eval do
19
19
  @auto_actions ||= {}
20
20
 
21
- inheriting_cattr_reader :web_methods => [], :show_actions => [], :index_actions => []
22
-
21
+ inheriting_cattr_reader :web_methods => [], :show_actions => [], :index_actions => [],
22
+ :owner_actions => {}
23
+
23
24
  extend ClassMethods
24
-
25
-
25
+
26
+
26
27
  helper_method :model, :current_user
27
28
  before_filter :set_no_cache_headers
28
-
29
+
29
30
  rescue_from ActiveRecord::RecordNotFound, :with => :not_found
30
-
31
- rescue_from Hobo::Model::PermissionDeniedError, :with => :permission_denied
32
-
31
+
32
+ rescue_from Hobo::Model::PermissionDeniedError, :with => :permission_denied
33
+ rescue_from Hobo::Lifecycles::LifecycleKeyError, :with => :permission_denied
34
+
33
35
  alias_method_chain :render, :hobo_model
34
36
 
35
37
  end
38
+ register_controller(base)
36
39
 
37
40
  Hobo::Controller.included_in_class(base)
38
41
  end
42
+
43
+ end
44
+
45
+
46
+ def self.register_controller(controller)
47
+ @controller_names ||= Set.new
48
+ @controller_names << controller.name
49
+ end
50
+
51
+
52
+ def self.all_controllers(subsite=nil, force=false)
53
+ # Load every controller in app/controllers/<subsite>...
54
+ @controllers_loaded ||= {}
55
+ if force || !@controllers_loaded[subsite]
56
+ dir = "#{RAILS_ROOT}/app/controllers#{'/' + subsite if subsite}"
57
+ Dir.entries(dir).each do |f|
58
+ f =~ /^[a-zA-Z_][a-zA-Z0-9_]*_controller\.rb$/ and f.sub(/.rb$/, '').camelize.constantize
59
+ end
60
+ @controllers_loaded[subsite] = true
61
+ end
62
+
63
+ # ...but only return the ones that registered themselves
64
+ names = (@controller_names || []).select { |n| subsite ? n =~ /^#{subsite.camelize}::/ : n !~ /::/ }
39
65
 
66
+ names.map do |name|
67
+ begin
68
+ name.constantize
69
+ rescue NameError
70
+ @controller_names.delete name
71
+ nil
72
+ end
73
+ end.compact
40
74
  end
41
75
 
42
76
 
77
+
43
78
  module ClassMethods
44
79
 
45
80
  attr_writer :model
46
-
47
- def collections
48
- # FIXME The behaviour here is weird if the superclass does
49
- # define collections *and* this class adds some more. The
50
- # added ones won't be published
51
-
52
- # by default By default, all has_many associations are published
53
- @collections ||= if superclass.respond_to?(:collections)
54
- superclass.collections
55
- else
56
- model.reflections.values.map {|r| r.name if r.macro == :has_many}.compact
57
- end
58
- end
59
81
 
60
-
61
82
  def model
62
83
  @model ||= name.sub(/Controller$/, "").singularize.constantize
63
84
  end
64
-
65
-
85
+
86
+
66
87
  def autocomplete(name, options={}, &block)
67
88
  options = options.dup
68
89
  field = options.delete(:field) || name
@@ -70,7 +91,7 @@ module Hobo
70
91
  index_action "complete_#{name}", &block
71
92
  else
72
93
  index_action "complete_#{name}" do
73
- hobo_completetions name, model, options
94
+ hobo_completions name, model, options
74
95
  end
75
96
  end
76
97
  end
@@ -83,84 +104,91 @@ module Hobo
83
104
  define_method web_name do
84
105
  # Make sure we have a copy of the options - it is being mutated somewhere
85
106
  opts = {}.merge(options)
86
- @this = find_instance(opts) unless opts[:no_find]
107
+ self.this = find_instance(opts) unless opts[:no_find]
87
108
  raise Hobo::Model::PermissionDeniedError unless Hobo.can_call?(current_user, @this, method)
88
109
  if got_block
89
110
  instance_eval(&block)
90
111
  else
91
112
  @this.send(method)
92
113
  end
93
-
114
+
94
115
  hobo_ajax_response || render(:nothing => true) unless performed?
95
116
  end
96
117
  end
97
-
98
-
118
+
119
+
99
120
  def auto_actions(*args)
100
121
  options = args.extract_options!
101
-
122
+
102
123
  @auto_actions = case args.first
103
124
  when :all then available_auto_actions
104
- when :write_only then available_auto_write_actions + args.rest
105
- when :read_only then available_auto_read_actions + args.rest
125
+ when :write_only then available_auto_write_actions + args.rest
126
+ when :read_only then available_auto_read_actions + args.rest
127
+ when :lifecycle then available_auto_lifecycle_actions + args.rest
106
128
  else args
107
129
  end
108
130
 
109
131
  except = Array(options[:except])
110
132
  except_actions = except.map do |arg|
111
- if arg == :collections
112
- available_auto_collection_actions
113
- else
114
- arg
133
+ case arg
134
+ when :lifecycle then available_auto_lifecycle_actions
135
+ else arg
115
136
  end
116
137
  end
117
-
138
+
118
139
  @auto_actions -= except_actions.flatten
119
-
140
+
120
141
  def_auto_actions
121
142
  end
122
-
123
-
143
+
144
+
124
145
  def def_auto_actions
125
146
  self.class_eval do
126
- def index; hobo_index end if include_action?(:index)
127
- def show; hobo_show end if include_action?(:show)
128
- def new; hobo_new end if include_action?(:new)
129
- def create; hobo_create end if include_action?(:create)
130
- def edit; hobo_show end if include_action?(:edit)
131
- def update; hobo_update end if include_action?(:update)
132
- def destroy; hobo_destroy end if include_action?(:destroy)
133
-
147
+ def index; hobo_index end if include_action?(:index)
148
+ def show; hobo_show end if include_action?(:show)
149
+ def new; hobo_new end if include_action?(:new)
150
+ def create; hobo_create end if include_action?(:create)
151
+ def edit; hobo_show end if include_action?(:edit)
152
+ def update; hobo_update end if include_action?(:update)
153
+ def destroy; hobo_destroy end if include_action?(:destroy)
154
+
134
155
  def completions; hobo_completions end if include_action?(:completions)
135
-
136
- def reorder; hobo_reorder end if include_action?(:reorder)
156
+
157
+ def reorder; hobo_reorder end if include_action?(:reorder)
137
158
  end
138
159
 
139
- collections.each { |c| def_collection_actions(c.to_sym) }
160
+ def_lifecycle_actions
140
161
  end
141
-
142
-
143
- def def_collection_actions(name)
144
- defined_methods = instance_methods
145
-
146
- show_collection_method = name
147
- if show_collection_method.not_in?(defined_methods) && include_action?(show_collection_method)
148
- define_method show_collection_method do
149
- hobo_show_collection(name)
162
+
163
+
164
+ def def_auto_action(name, &block)
165
+ define_method name, &block if name.not_in?(instance_methods) && include_action?(name)
166
+ end
167
+
168
+
169
+ def def_lifecycle_actions
170
+ if model.has_lifecycle?
171
+ model::Lifecycle.creator_names.each do |creator|
172
+ def_auto_action creator do
173
+ creator_page_action creator
174
+ end
175
+ def_auto_action "do_#{creator}" do
176
+ do_creator_action creator
177
+ end
150
178
  end
151
- end
152
-
153
- if Hobo.simple_has_many_association?(model.reflections[name])
154
- new_method = "new_#{name.to_s.singularize}"
155
- if new_method.not_in?(defined_methods) && include_action?(new_method)
156
- define_method new_method do
157
- hobo_new_in_collection(name)
179
+
180
+ model::Lifecycle.transition_names.each do |transition|
181
+ def_auto_action transition do
182
+ transition_page_action transition
183
+ end
184
+ def_auto_action "do_#{transition}" do
185
+ do_transition_action transition
158
186
  end
159
187
  end
160
188
  end
161
189
  end
162
-
163
-
190
+
191
+
164
192
  def show_action(*names, &block)
165
193
  options = names.extract_options!
166
194
  show_actions.concat(names)
@@ -168,11 +196,12 @@ module Hobo
168
196
  if block
169
197
  define_method(name, &block)
170
198
  else
171
- define_method(name) { hobo_show options }
199
+ define_method(name) { hobo_show options.dup }
172
200
  end
173
201
  end
174
202
  end
175
-
203
+
204
+
176
205
  def index_action(*names, &block)
177
206
  options = names.extract_options!
178
207
  index_actions.concat(names)
@@ -181,38 +210,54 @@ module Hobo
181
210
  define_method(name, &block)
182
211
  else
183
212
  if scope = options.delete(:scope)
184
- define_method(name) { hobo_index scope, options }
213
+ define_method(name) { hobo_index scope, options.dup }
185
214
  else
186
- define_method(name) { hobo_index options }
215
+ define_method(name) { hobo_index options.dup }
187
216
  end
188
217
  end
189
218
  end
190
219
  end
191
220
 
192
- def publish_collection(*names)
193
- collections.concat(names)
194
- names.each {|n| def_collection_actions(n)}
195
- end
196
-
197
221
 
222
+ def auto_actions_for(owner, actions)
223
+ model.reverse_reflection(owner)._?.klass == model or
224
+ raise ArgumentError, "Invalid owner association '#{owner}' for #{model}"
225
+
226
+ owner_actions[owner] ||= []
227
+ Array(actions).each do |action|
228
+ case action
229
+ when :new
230
+ define_method("new_for_#{owner}") { hobo_new_for owner }
231
+ when :index
232
+ define_method("index_for_#{owner}") { hobo_index_for owner }
233
+ when :create
234
+ define_method("create_for_#{owner}") { hobo_create_for owner }
235
+ else
236
+ raise ArgumentError, "Invalid owner action: #{action}"
237
+ end
238
+ owner_actions[owner] << action
239
+ end
240
+ end
241
+
242
+
198
243
  def include_action?(name)
199
244
  name.to_sym.in?(@auto_actions)
200
245
  end
201
-
202
-
246
+
247
+
203
248
  def available_auto_actions
204
249
  (available_auto_read_actions +
205
- available_auto_write_actions +
206
- FORM_ACTIONS +
207
- available_auto_collection_actions).uniq
250
+ available_auto_write_actions +
251
+ FORM_ACTIONS +
252
+ available_auto_lifecycle_actions).uniq
208
253
  end
209
-
210
-
254
+
255
+
211
256
  def available_auto_read_actions
212
- READ_ONLY_ACTIONS + collections
257
+ READ_ONLY_ACTIONS
213
258
  end
214
-
215
-
259
+
260
+
216
261
  def available_auto_write_actions
217
262
  if "position_column".in?(model.instance_methods)
218
263
  WRITE_ONLY_ACTIONS + [:reorder]
@@ -220,18 +265,27 @@ module Hobo
220
265
  WRITE_ONLY_ACTIONS
221
266
  end
222
267
  end
223
-
224
-
225
- def available_auto_collection_actions
226
- collections + collections.map {|c| "new_#{c.to_s.singularize}".to_sym}
268
+
269
+
270
+ def available_auto_lifecycle_actions
271
+ # For each creator/transition there are two possible
272
+ # actions. e.g. for signup, 'signup' would be routed to
273
+ # GET users/signup, and would show the form, while 'do_signup'
274
+ # would be routed to POST /users/signup)
275
+ if model.has_lifecycle?
276
+ (model::Lifecycle.creator_names.map { |c| [c, "do_#{c}"] } +
277
+ model::Lifecycle.transition_names.map { |t| [t, "do_#{t}"] }).flatten.*.to_sym
278
+ else
279
+ []
280
+ end
227
281
  end
228
282
 
229
- end
230
-
283
+ end # of ClassMethods
284
+
231
285
 
232
286
  protected
233
-
234
-
287
+
288
+
235
289
  def parse_sort_param(*sort_fields)
236
290
  _, desc, field = *params[:sort]._?.match(/^(-)?([a-z_]+(?:\.[a-z_]+)?)$/)
237
291
 
@@ -239,61 +293,66 @@ module Hobo
239
293
  if field.in?(sort_fields.*.to_s)
240
294
  @sort_field = field
241
295
  @sort_direction = desc ? "desc" : "asc"
242
-
296
+
243
297
  [@sort_field, @sort_direction]
244
298
  end
245
299
  end
246
300
  end
247
-
248
-
301
+
302
+
249
303
  # --- Action implementation helpers --- #
250
-
304
+
251
305
 
252
306
  def find_instance(options={})
253
307
  model.user_find(current_user, params[:id], options)
254
308
  end
255
-
256
-
309
+
310
+
257
311
  def invalid?; !valid?; end
258
-
259
-
312
+
313
+
260
314
  def valid?; this.errors.empty?; end
261
315
 
262
-
316
+
263
317
  def re_render_form(default_action)
264
318
  if params[:page_path]
265
319
  controller, view = Controller.controller_and_view_for(params[:page_path])
266
320
  view = default_action if view == Dryml::EMPTY_PAGE
267
- render :action => view, :controller => controller
321
+ @this = instance_variable_get("@#{controller.singularize}")
322
+ render :template => "#{controller}/#{view}"
268
323
  else
269
324
  render :action => default_action
270
325
  end
271
326
  end
272
-
273
-
327
+
328
+
274
329
  def destination_after_submit(record=nil, destroyed=false)
275
330
  record ||= this
276
-
331
+
277
332
  after_submit = params[:after_submit]
278
-
333
+
279
334
  # The after_submit post parameter takes priority
280
- (after_submit == "stay-here" ? :back : after_submit) ||
281
-
282
-
335
+ (after_submit == "stay-here" ? :back : after_submit) ||
336
+
283
337
  # Then try the record's show page
284
- (!destroyed && object_url(@this)) ||
285
-
338
+ (!destroyed && object_url(@this)) ||
339
+
286
340
  # Then the show page of the 'owning' object if there is one
287
- (!destroyed && (@this.class.default_dependent_on && object_url(@this.send(@this.class.default_dependent_on)))) ||
288
-
341
+ (@this.class.default_dependent_on && object_url(@this.send(@this.class.default_dependent_on))) ||
342
+
289
343
  # Last try - the index page for this model
290
344
  object_url(@this.class) ||
291
-
345
+
292
346
  # Give up
293
347
  home_page
294
348
  end
295
349
 
296
350
 
351
+ def redirect_after_submit(*args)
352
+ redirect_to destination_after_submit(*args)
353
+ end
354
+
355
+
297
356
  def response_block(&b)
298
357
  if b
299
358
  if b.arity == 1
@@ -304,25 +363,37 @@ module Hobo
304
363
  performed?
305
364
  end
306
365
  end
307
-
308
-
366
+
367
+
309
368
  def request_requires_pagination?
310
369
  request.format.not_in?(DONT_PAGINATE_FORMATS)
311
370
  end
312
-
313
-
371
+
372
+
314
373
  def find_or_paginate(finder, options)
315
374
  options = options.reverse_merge(:paginate => request_requires_pagination?)
316
375
  do_pagination = options.delete(:paginate) && finder.respond_to?(:paginate)
317
-
376
+ options[:order] = :default unless options[:order] || finder.send(:scope, :find)._?[:order]
377
+
318
378
  if do_pagination
319
- finder.paginate(options.reverse_merge(:page => params[:page] || 1))
379
+ options.reverse_merge!(:page => params[:page] || 1)
380
+ finder.paginate(options)
320
381
  else
321
382
  finder.all(options)
322
383
  end
323
384
  end
324
385
 
325
386
 
387
+ def find_owner_and_association(owner_association)
388
+ refl = model.reflections[owner_association]
389
+ klass = refl.klass
390
+ id = params["#{klass.name.underscore}_id"]
391
+ owner = klass.find(id)
392
+ instance_variable_set("@#{owner_association}", owner)
393
+ [owner, owner.send(model.reverse_reflection(owner_association).name)]
394
+ end
395
+
396
+
326
397
  # --- Action implementations --- #
327
398
 
328
399
  def hobo_index(*args, &b)
@@ -332,86 +403,115 @@ module Hobo
332
403
  response_block(&b)
333
404
  end
334
405
 
406
+
407
+ def hobo_index_for(owner, *args, &b)
408
+ options = args.extract_options!
409
+ owner, association = find_owner_and_association(owner)
410
+ finder = args.first || association
411
+ self.this = find_or_paginate(finder, options)
412
+ response_block(&b)
413
+ end
414
+
335
415
 
336
416
  def hobo_show(*args, &b)
337
417
  options = args.extract_options!
338
418
  self.this = find_instance(options)
339
419
  response_block(&b)
340
420
  end
341
-
342
-
343
- def hobo_new(new_record=nil, &b)
344
- self.this = new_record || model.new
345
- this.user_changes!(current_user) # set_creator and permission check
421
+
422
+
423
+ def hobo_new(record=nil, &b)
424
+ self.this = record || model.user_new!(current_user)
346
425
  response_block(&b)
347
426
  end
348
427
 
349
428
 
429
+ def hobo_new_for(owner, record=nil, &b)
430
+ owner, association = find_owner_and_association(owner)
431
+ self.this = record || association.user_new(current_user)
432
+ response_block(&b)
433
+ end
434
+
435
+
350
436
  def hobo_create(*args, &b)
351
437
  options = args.extract_options!
352
438
  self.this = args.first || new_for_create
353
- this.user_save_changes(current_user, options[:attributes] || attribute_parameters)
354
- create_response(&b)
439
+ this.user_save_changes(current_user, options[:attributes] || attribute_parameters || {})
440
+ create_response(:new, &b)
355
441
  end
356
442
 
357
443
 
444
+ def hobo_create_for(owner, *args, &b)
445
+ options = args.extract_options!
446
+ owner, association = find_owner_and_association(owner)
447
+ self.this = args.first || association.new
448
+ this.user_save_changes(current_user, options[:attributes] || attribute_parameters || {})
449
+ create_response(:"new_for_#{owner}", &b)
450
+ end
451
+
452
+
358
453
  def attribute_parameters
359
- params[this.class.name.underscore]
454
+ params[(this ? this.class : model).name.underscore]
360
455
  end
361
-
456
+
362
457
 
363
458
  def new_for_create
364
- if model.has_inheritance_column? && (type_attr = params['type']) && type_attr.in?(model.send(:subclasses).*.name)
365
- type_attr.constantize
366
- else
367
- model
368
- end.new
459
+ type_param = subtype_for_create
460
+ create_model = type_param ? type_param.constantize : model
461
+ create_model.new
369
462
  end
370
463
 
371
464
 
372
- def create_response(&b)
373
- flash[:notice] = "The #{@this.class.name.titleize.downcase} was created successfully" if !request.xhr? && valid?
374
-
465
+ def subtype_for_create
466
+ model.has_inheritance_column? && (t = params['type']) && t.in?(model.send(:subclasses).*.name) and
467
+ t
468
+ end
469
+
470
+
471
+
472
+ def create_response(new_action, &b)
473
+ flash[:notice] = "The #{@this.class.name.titleize.downcase} was created successfully" if !request.xhr? && valid?
474
+
375
475
  response_block(&b) or
376
476
  if valid?
377
477
  respond_to do |wants|
378
- wants.html { redirect_to destination_after_submit }
478
+ wants.html { redirect_after_submit }
379
479
  wants.js { hobo_ajax_response || render(:nothing => true) }
380
480
  end
381
481
  else
382
482
  respond_to do |wants|
383
- wants.html { re_render_form(:new) }
483
+ wants.html { re_render_form(new_action) }
384
484
  wants.js { render(:status => 500,
385
485
  :text => ("Couldn't create the #{this.class.name.titleize.downcase}.\n" +
386
486
  this.errors.full_messages.join("\n"))) }
387
487
  end
388
488
  end
389
489
  end
390
-
490
+
391
491
 
392
492
  def hobo_update(*args, &b)
393
493
  options = args.extract_options!
394
-
494
+
395
495
  self.this = args.first || find_instance
396
- changes = options[:attributes] || attribute_parameters
496
+ changes = options[:attributes] || attribute_parameters or raise RuntimeError, "No update specified in params"
397
497
  this.user_save_changes(current_user, changes)
398
498
 
399
499
  # Ensure current_user isn't out of date
400
500
  @current_user = @this if @this == current_user
401
-
501
+
402
502
  in_place_edit_field = changes.keys.first if changes.size == 1 && params[:render]
403
503
  update_response(in_place_edit_field, &b)
404
504
  end
405
-
406
-
505
+
506
+
407
507
  def update_response(in_place_edit_field=nil, &b)
408
508
  flash[:notice] = "Changes to the #{@this.class.name.titleize.downcase} were saved" if !request.xhr? && valid?
409
-
410
- response_block(&b) or
509
+
510
+ response_block(&b) or
411
511
  if valid?
412
512
  respond_to do |wants|
413
513
  wants.html do
414
- redirect_to destination_after_submit
514
+ redirect_after_submit
415
515
  end
416
516
  wants.js do
417
517
  if in_place_edit_field
@@ -421,7 +521,7 @@ module Hobo
421
521
  else
422
522
  hobo_ajax_response(this)
423
523
  end
424
-
524
+
425
525
  # Maybe no ajax requests were made
426
526
  render :nothing => true unless performed?
427
527
  end
@@ -430,13 +530,13 @@ module Hobo
430
530
  respond_to do |wants|
431
531
  wants.html { re_render_form(:edit) }
432
532
  wants.js { render(:status => 500,
433
- :text => ("There was a problem with that change.\n" +
533
+ :text => ("There was a problem with that change.\n" +
434
534
  @this.errors.full_messages.join("\n"))) }
435
535
  end
436
536
  end
437
537
  end
438
-
439
-
538
+
539
+
440
540
  def hobo_destroy(*args, &b)
441
541
  options = args.extract_options!
442
542
  self.this = args.first || find_instance
@@ -444,63 +544,92 @@ module Hobo
444
544
  flash[:notice] = "The #{model.name.titleize.downcase} was deleted" unless request.xhr?
445
545
  destroy_response(&b)
446
546
  end
447
-
448
-
547
+
548
+
449
549
  def destroy_response(&b)
450
550
  response_block(&b) or
451
551
  respond_to do |wants|
452
- wants.html { redirect_to destination_after_submit(this, true) }
552
+ wants.html { redirect_after_submit(this, true) }
453
553
  wants.js { hobo_ajax_response || render(:nothing => true) }
454
554
  end
455
555
  end
456
-
457
-
458
- def hobo_show_collection(association, *args, &b)
459
- options = args.extract_options!
460
- association = find_instance.send(association) if association.is_a?(String, Symbol)
461
- if association.respond_to?(:origin)
462
- association.origin.user_view(current_user, association.origin_attribute) # permission check
463
- end
464
- self.this = find_or_paginate(association, options)
465
- dryml_fallback_tag("show_collection_page")
466
- response_block(&b)
556
+
557
+
558
+ # --- Lifecycle Actions --- #
559
+
560
+ def do_creator_action(name, &b)
561
+ @creator = model::Lifecycle.creators[name.to_s]
562
+ self.this = @creator.run!(current_user, attribute_parameters)
563
+ response_block(&b) or
564
+ if valid?
565
+ redirect_after_submit
566
+ else
567
+ re_render_form(name)
568
+ end
467
569
  end
468
-
469
-
470
- # TODO: This action needs some more tidying up
471
- def hobo_new_in_collection(association, *args, &b)
570
+
571
+
572
+ def creator_page_action(name)
573
+ self.this = model.new
574
+ @creator = model::Lifecycle.creators[name.to_s] or raise ArgumentError, "No such creator in lifecycle: #{name}"
575
+ end
576
+
577
+
578
+ def prepare_for_transition(name, options={})
579
+ self.this = find_instance
580
+ this.exempt_from_edit_checks = true
581
+ this.lifecycle.provided_key = params[:key]
582
+ @transition = this.lifecycle.find_transition(name, current_user)
583
+ end
584
+
585
+
586
+ def do_transition_action(name, *args, &b)
587
+ prepare_for_transition(name)
588
+ @transition.run!(this, current_user, attribute_parameters)
589
+ response_block(&b) or
590
+ if valid?
591
+ redirect_after_submit
592
+ else
593
+ re_render_form(name)
594
+ end
595
+ end
596
+
597
+
598
+ def transition_page_action(name, *args)
472
599
  options = args.extract_options!
473
- @association = association.is_a?(String, Symbol) ? find_instance.send(association) : association
474
- self.this = args.first || @association.new
475
- this.user_changes(current_user) # set_creator and permission check
476
- dryml_fallback_tag("new_in_collection_page")
477
- response_block(&b)
600
+ prepare_for_transition(name, options)
478
601
  end
479
-
602
+
603
+ # --- Miscelaneous Actions --- #
480
604
 
481
605
  def hobo_completions(attribute, finder, options={})
482
- options = options.reverse_merge(:limit => 10, :param => :query)
483
- finder = finder.limit(options[:limit]) unless finder.scope(:find, :limit)
484
- finder = finder.send("#{attribute}_contains", params[options[:param]])
606
+ options = options.reverse_merge(:limit => 10, :param => :query, :query_scope => "#{attribute}_contains")
607
+ finder = finder.limit(options[:limit]) unless finder.send(:scope, :find, :limit)
608
+ finder = finder.send(options[:query_scope], params[options[:param]])
485
609
  items = finder.find(:all)
486
610
  render :text => "<ul>\n" + items.map {|i| "<li>#{i.send(attribute)}</li>\n"}.join + "</ul>"
487
611
  end
488
-
489
-
612
+
613
+
490
614
  def hobo_reorder
491
- params["#{model.name.underscore}_ordering"].each_with_index do |id, position|
492
- model.user_update(current_user, id, :position => position+1)
615
+ ordering = params["#{model.name.underscore}_ordering"]
616
+ if ordering
617
+ ordering.each_with_index do |id, position|
618
+ model.user_update(current_user, id, :position => position+1)
619
+ end
620
+ hobo_ajax_response || render(:nothing => true)
621
+ else
622
+ render :nothing => true
493
623
  end
494
- hobo_ajax_response || render(:nothing => true)
495
624
  end
496
-
497
-
498
-
625
+
626
+
627
+
499
628
  # --- Response helpers --- #
500
-
629
+
501
630
  def permission_denied(error)
502
631
  self.this = nil # Otherwise this gets sent user_view
503
- if :permission_denied.in?(superclass.instance_methods)
632
+ if :permission_denied.in?(self.class.superclass.instance_methods)
504
633
  super
505
634
  else
506
635
  respond_to do |wants|
@@ -511,16 +640,16 @@ module Hobo
511
640
  render :text => "Permission Denied", :status => 403
512
641
  end
513
642
  end
514
- wants.js do
643
+ wants.js do
515
644
  render :text => "Permission Denied", :status => 403
516
645
  end
517
646
  end
518
647
  end
519
648
  end
520
-
521
-
649
+
650
+
522
651
  def not_found(error)
523
- if :not_found_response.in?(superclass.instance_methods)
652
+ if :not_found_response.in?(self.class.superclass.instance_methods)
524
653
  super
525
654
  elsif render_tag("not-found-page", {}, :status => 404)
526
655
  # cool
@@ -528,38 +657,38 @@ module Hobo
528
657
  render(:text => "The page you requested cannot be found.", :status => 404)
529
658
  end
530
659
  end
531
-
532
-
660
+
661
+
533
662
  def this
534
- @this ||= (instance_variable_get("@#{model.name.underscore}") ||
663
+ @this ||= (instance_variable_get("@#{model.name.underscore}") ||
535
664
  instance_variable_get("@#{model.name.underscore.pluralize}"))
536
665
  end
537
666
 
538
-
667
+
539
668
  def this=(object)
540
669
  ivar = if object.is_a?(Array)
541
670
  (object.try.member_class || model).name.underscore.pluralize
542
671
  else
543
- model.name.underscore
672
+ object.class.name.underscore
544
673
  end
545
674
  @this = instance_variable_set("@#{ivar}", object)
546
675
  end
547
-
548
-
676
+
677
+
549
678
  def dryml_context
550
679
  this
551
680
  end
552
681
 
553
-
682
+
554
683
  def render_with_hobo_model(*args, &block)
555
684
  options = args.extract_options!
556
685
  self.this = options[:object] if options[:object]
557
686
  this.user_view(current_user) if this && this.respond_to?(:user_view)
558
687
  render_without_hobo_model(*args + [options], &block)
559
688
  end
560
-
689
+
561
690
  # --- filters --- #
562
-
691
+
563
692
  def set_no_cache_headers
564
693
  headers["Pragma"] = "no-cache"
565
694
  #headers["Cache-Control"] = ["must-revalidate", "no-cache", "no-store"]
@@ -569,13 +698,13 @@ module Hobo
569
698
  end
570
699
 
571
700
  # --- end filters --- #
572
-
701
+
573
702
  public
574
703
 
575
704
  def model
576
705
  self.class.model
577
706
  end
578
-
707
+
579
708
  end
580
709
 
581
710
  end