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
@@ -1,22 +1,18 @@
1
1
  module Hobo::Dryml
2
2
 
3
- class TemplateHandler
3
+ class TemplateHandler < ActionView::TemplateHandler
4
4
 
5
- def initialize(view)
6
- @view = view
7
- end
8
-
9
- def render(src, local_assigns)
10
- renderer = Hobo::Dryml.page_renderer(@view, local_assigns.keys)
11
- this = @view.instance_variable_set("@this", @view.controller.send(:dryml_context) || local_assigns[:this])
12
- s = renderer.render_page(this, local_assigns)
5
+ def render(template)
6
+ renderer = Hobo::Dryml.page_renderer_for_template(@view, template)
7
+ this = @view.instance_variable_set("@this", @view.controller.send(:dryml_context) || template.locals[:this])
8
+ s = renderer.render_page(this, template.locals)
13
9
 
14
10
  # Important to strip whitespace, or the browser hangs around for ages (FF2)
15
11
  s = s.strip
16
-
12
+
17
13
  # TODO: Temporary hack to get the dryml metadata comments in the right place
18
14
  if RAILS_ENV == "development"
19
- s.gsub(/^(.*?)(<!DOCTYPE.*?>).*?(<html.*?>)/m, "\\2\\3\\1")
15
+ s.gsub(/^(.*?)(<!DOCTYPE.*?>).*?(<html.*?>)/m, "\\2\\3\\1")
20
16
  else
21
17
  s
22
18
  end
@@ -27,33 +23,32 @@ module Hobo::Dryml
27
23
  end
28
24
 
29
25
  module ActionController
30
-
31
26
 
32
27
  class Base
33
-
28
+
34
29
  def dryml_context
35
30
  @this
36
31
  end
37
-
32
+
38
33
  def dryml_fallback_tag(tag_name)
39
34
  @dryml_fallback_tag = tag_name
40
35
  end
41
-
42
-
36
+
37
+
43
38
  def call_dryml_tag(tag, options={})
44
39
  add_variables_to_assigns
45
-
40
+
46
41
  # TODO: Figure out what this bit is all about :-)
47
42
  if options[:with]
48
43
  @this = options[:with] unless options[:field]
49
44
  else
50
45
  options[:with] = dryml_context
51
46
  end
52
-
47
+
53
48
  Hobo::Dryml.render_tag(@template, tag, options)
54
49
  end
55
-
56
-
50
+
51
+
57
52
  # TODO: This is namespace polution, should be called render_dryml_tag
58
53
  def render_tag(tag, options={}, render_options={})
59
54
  text = call_dryml_tag(tag, options)
@@ -61,17 +56,17 @@ module ActionController
61
56
  end
62
57
 
63
58
  def render_for_file_with_dryml(template_path, *args)
64
- if template_path !~ /^\// && # not an absolute path (e.g. an exception ERB template)
59
+ if template_path !~ /^([a-z]:)?\//i && # not an absolute path (e.g. an exception ERB template)
65
60
  !template_exists?(template_path) && # no template available in app/views
66
61
  tag_name = @dryml_fallback_tag || "#{File.basename(template_path).dasherize}-page"
67
62
 
68
- # The template was missing, try to use a DRYML <page> tag instead
69
- render_tag(tag_name) or raise ActionController::MissingTemplate, "Missing template #{template_path}.html.erb in view path #{RAILS_ROOT}/app/views"
63
+ # The template was missing, try to use a DRYML <page> tag instead
64
+ render_tag(tag_name) or raise ActionView::MissingTemplate, "Missing template #{template_path}.html.erb in view path #{RAILS_ROOT}/app/views"
70
65
  else
71
66
  render_for_file_without_dryml(template_path, *args)
72
67
  end
73
68
  end
74
69
  alias_method_chain :render_for_file, :dryml
75
-
70
+
76
71
  end
77
72
  end
@@ -0,0 +1,95 @@
1
+ module Hobo
2
+
3
+ # FIXME: should be FindByBelongsTo maybe
4
+ module FindFor
5
+
6
+ def self.included(base)
7
+ base.alias_method_chain :method_missing, :find_for
8
+ end
9
+
10
+ def method_missing_with_find_for(name, *args, &block)
11
+ if name.to_s =~ /(.*)_by_(.*)/
12
+ # name matches the general form
13
+
14
+ collection_name = $1.to_sym
15
+ anchor_association_name = $2.to_sym
16
+ if (refl = self.class.reflections[collection_name]) && refl.macro == :has_many
17
+ # the association name matches (e.g. comment_for_...)
18
+
19
+ if (anchor_refl = refl.klass.reflections[anchor_association_name]) && anchor_refl.macro == :belongs_to
20
+ # the whole thing matches (e.g. comment_for_user)
21
+
22
+
23
+ #self.class.class_eval %{
24
+ # def #{name}(anchor)
25
+ # result = if #{collection_name}.loaded?
26
+ # #{collection_name}.detect { |x| x.#{anchor_association_name}_is?(anchor) }
27
+ # else
28
+ # #{collection_name}.#{anchor_association_name}_is(anchor).first
29
+ # end
30
+ # result ||= #{collection_name}.new(:#{anchor_association_name} => anchor)
31
+ # result.origin = self
32
+ # result.origin_attribute = "#{name}.'#{anchor_id_expr}'"
33
+ # result
34
+ # end
35
+ #}
36
+
37
+ self.class.class_eval %{
38
+ def #{name}
39
+ Hobo::FindFor::Finder.new(self, '#{name}', :#{collection_name}, :#{anchor_association_name})
40
+ end
41
+ }
42
+
43
+ return send(name, *args)
44
+ end
45
+ end
46
+ end
47
+
48
+ method_missing_without_find_for(name, *args, &block)
49
+ end
50
+
51
+ class Finder
52
+
53
+ def initialize(owner, name, collection, anchor_association)
54
+ @association = owner.send(collection)
55
+ @anchor_reflection = @association.member_class.reflections[anchor_association]
56
+ @name = name
57
+ end
58
+
59
+ def origin
60
+ @association.proxy_owner
61
+ end
62
+
63
+ def origin_attribute
64
+ @name
65
+ end
66
+
67
+ def [](anchor_or_id)
68
+ anchor = if anchor_or_id.is_a?(String)
69
+ id, klass = anchor_or_id.split(':')
70
+ (klass.constantize || @anchor_reflection.klass).find(id)
71
+ else
72
+ anchor_or_id
73
+ end
74
+ result = if @association.loaded?
75
+ @association.detect { |x| x.send("#{@anchor_reflection.name}_is?", anchor) }
76
+ else
77
+ @association.send("#{@anchor_reflection.name}_is", anchor).first
78
+ end
79
+ result ||= @association.new(@anchor_reflection.name => anchor)
80
+
81
+
82
+ result.origin = self
83
+ result.origin_attribute = if @anchor_reflection.options[:polymorphic]
84
+ "#{anchor.id}:#{anchor.class.name}"
85
+ else
86
+ "#{anchor.id}"
87
+ end
88
+ result
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+
95
+ end
@@ -1,4 +1,5 @@
1
- require 'find'
1
+ require 'find'
2
+ require "rails_generator"
2
3
 
3
4
  class Hobo::Generator < Rails::Generator::Base
4
5
 
@@ -1,9 +1,9 @@
1
- module Hobo
1
+ module Hobo
2
2
 
3
3
  class Guest
4
-
4
+
5
5
  alias_method :has_hobo_method?, :respond_to?
6
-
6
+
7
7
  def to_s
8
8
  "Guest"
9
9
  end
@@ -12,14 +12,22 @@ module Hobo
12
12
  true
13
13
  end
14
14
 
15
+ def signed_up?
16
+ false
17
+ end
18
+
15
19
  def super_user?
16
20
  false
17
21
  end
18
-
22
+
19
23
  def administrator?
20
24
  false
21
25
  end
22
26
 
27
+ def login
28
+ "Guest"
29
+ end
30
+
23
31
  end
24
32
 
25
33
  end
@@ -1,21 +1,21 @@
1
1
  module Hobo
2
-
2
+
3
3
  module HoboHelper
4
-
4
+
5
5
  def self.add_to_controller(controller)
6
6
  controller.send(:include, self)
7
7
  controller.hide_action(self.instance_methods)
8
8
  end
9
-
9
+
10
10
  protected
11
-
12
-
11
+
12
+
13
13
  def uid
14
14
  @hobo_uid ||= 0
15
15
  @hobo_uid += 1
16
16
  end
17
-
18
-
17
+
18
+
19
19
  def current_user
20
20
  # simple one-hit-per-request cache
21
21
  @current_user ||= begin
@@ -23,18 +23,18 @@ module Hobo
23
23
  (id && Hobo.object_from_dom_id(id) rescue nil) || ::Guest.new
24
24
  end
25
25
  end
26
-
27
-
26
+
27
+
28
28
  def logged_in?
29
29
  !current_user.guest?
30
30
  end
31
-
32
-
31
+
32
+
33
33
  def base_url
34
34
  request.relative_url_root
35
35
  end
36
-
37
-
36
+
37
+
38
38
  def controller_for(obj)
39
39
  if obj.is_a? Class
40
40
  obj.name.underscore.pluralize
@@ -42,31 +42,39 @@ module Hobo
42
42
  obj.class.name.underscore.pluralize
43
43
  end
44
44
  end
45
-
46
-
45
+
46
+
47
47
  def subsite
48
48
  params[:controller].match(/([^\/]+)\//)._?[1]
49
49
  end
50
50
 
51
-
51
+
52
52
  IMPLICIT_ACTIONS = [:index, :show, :create, :update, :destroy]
53
-
53
+
54
54
  def object_url(obj, *args)
55
55
  params = args.extract_options!
56
56
  action = args.first._?.to_sym
57
57
  options, params = params.partition_hash([:subsite, :method, :format])
58
58
  options[:subsite] ||= self.subsite
59
-
60
- if obj.respond_to?(:origin)
59
+ subsite, method = options.get :subsite, :method
60
+
61
+ if obj.respond_to?(:member_class)
61
62
  # Asking for URL of a collection, e.g. category/1/adverts or category/1/adverts/new
63
+
64
+ owner_name = obj.origin.class.reverse_reflection(obj.origin_attribute).name.to_s
62
65
  if action == :new
63
66
  action_path = "#{obj.origin_attribute}/new"
64
- action = "new_#{obj.origin_attribute.to_s.singularize}"
67
+ action = :"new_for_#{owner_name}"
65
68
  elsif action.nil?
66
- action = obj.origin_attribute
69
+ action_path = obj.origin_attribute
70
+ if method.to_s == 'post'
71
+ action = :"create_for_#{owner_name}"
72
+ else
73
+ action = :"index_for_#{owner_name}"
74
+ end
67
75
  end
76
+ klass = obj.member_class
68
77
  obj = obj.origin
69
-
70
78
  else
71
79
  action ||= case options[:method].to_s
72
80
  when 'put'; :update
@@ -75,26 +83,31 @@ module Hobo
75
83
  else; obj.is_a?(Class) ? :index : :show
76
84
  end
77
85
 
78
- if action == :create && obj.try.new_record?
86
+ if options[:method].to_s == 'post' && obj.try.new_record?
79
87
  # Asking for url to post new record to
80
88
  obj = obj.class
81
89
  end
90
+
91
+ klass = obj.is_a?(Class) ? obj : obj.class
82
92
  end
83
-
84
- klass = obj.is_a?(Class) ? obj : obj.class
85
- if Hobo::ModelRouter.linkable?(klass, action, options)
86
93
 
87
- path = obj.to_url_path or HoboError.new("cannot create url for #{obj.inspect} (#{obj.class})")
88
- url = "#{base_url}#{'/' + subsite unless subsite.blank?}/#{path}"
94
+ if Hobo::ModelRouter.linkable?(klass, action, options)
89
95
 
96
+ url = base_url_for(obj, subsite, action)
90
97
  url += "/#{action_path || action}" unless action.in?(IMPLICIT_ACTIONS)
91
98
 
92
99
  params = make_params(params)
93
100
  params.blank? ? url : "#{url}?#{params}"
94
101
  end
95
102
  end
96
-
97
-
103
+
104
+
105
+ def base_url_for(object, subsite, action)
106
+ path = object.to_url_path or HoboError.new("cannot create url for #{object.inspect} (#{object.class})")
107
+ "#{base_url}#{'/' + subsite unless subsite.blank?}/#{path}"
108
+ end
109
+
110
+
98
111
  def _as_params(name, obj)
99
112
  if obj.is_a? Array
100
113
  obj.map {|x| _as_params("#{name}[]", x)}.join("&")
@@ -111,43 +124,56 @@ module Hobo
111
124
  "#{name}=#{v}"
112
125
  end
113
126
  end
114
-
115
-
127
+
128
+
116
129
  def make_params(*hashes)
117
130
  hash = {}
118
131
  hashes.each {|h| hash.update(h) if h}
119
132
  hash.map {|k,v| _as_params(k, v)}.join("&")
120
133
  end
121
-
122
-
134
+
135
+
123
136
  def type_id(type=nil)
124
137
  type ||= (this.is_a?(Class) && this) || this_type || this.class
125
138
  HoboFields.to_name(type) || type.name.underscore.gsub("/", "__")
126
139
  end
127
140
 
128
-
141
+
129
142
  def type_and_field(*args)
130
143
  type, field = args.empty? ? [this_parent.class, this_field] : args
131
144
  "#{type.typed_id}_#{field}" if type.respond_to?(:typed_id)
132
145
  end
133
-
134
-
135
- def map_this
146
+
147
+
148
+ def model_id_class(object=this, attribute=nil)
149
+ object.respond_to?(:typed_id) ? "model:#{dom_id(object, attribute).dasherize}" : ""
150
+ end
151
+
152
+
153
+ def context_map(enum = this)
136
154
  res = []
137
155
  empty = true
138
- if this.respond_to?(:each_index)
139
- this.each_index {|i| empty = false; new_field_context(i) { res << yield } }
140
- elsif this.is_a?(Hash)
141
- this.map {|key, value| empty = false; self.this_key = key; new_object_context(value) { res << yield } }
156
+ if enum.respond_to?(:each_pair)
157
+ enum.each_pair do |key, value|
158
+ empty = false;
159
+ self.this_key = key;
160
+ new_object_context(value) { res << yield }
161
+ end
142
162
  else
143
- this.map {|e| empty = false; new_object_context(e) { res << yield } }
163
+ enum.each do |e|
164
+ empty = false;
165
+ if e.respond_to?(:new_record?) && !e.new_record?
166
+ new_field_context(e.id.to_s, e) { res << yield }
167
+ else
168
+ new_object_context(e) { res << yield }
169
+ end
170
+ end
144
171
  end
145
172
  Dryml.last_if = !empty
146
173
  res
147
174
  end
148
- alias_method :collect_this, :map_this
149
-
150
-
175
+
176
+
151
177
  def comma_split(x)
152
178
  case x
153
179
  when nil
@@ -155,47 +181,49 @@ module Hobo
155
181
  when Symbol
156
182
  x.to_s
157
183
  when String
158
- x.split(/\s*[, ]\s*/)
184
+ x.strip.split(/\s*,\s*/)
159
185
  else
160
186
  x.compact.map{|e| comma_split(e)}.flatten
161
187
  end
162
188
  end
163
-
164
-
165
- def can_create?(object=nil)
166
- Hobo.can_create?(current_user, object || this)
189
+
190
+
191
+ def can_create?(object=this)
192
+ Hobo.can_create?(current_user, object)
167
193
  end
168
-
169
-
194
+
195
+
170
196
  def can_update?(object, new)
171
197
  Hobo.can_update?(current_user, object, new)
172
198
  end
173
-
174
-
199
+
200
+
175
201
  def can_edit?(*args)
176
202
  if args.empty?
177
- if this_parent && this_field
203
+ if this.respond_to?(:updatable_by?) && !this_field_reflection
204
+ can_edit?(this, nil)
205
+ elsif this_parent && this_field
178
206
  can_edit?(this_parent, this_field)
179
207
  else
180
208
  can_edit?(this, nil)
181
209
  end
182
210
  else
183
211
  object, field = args.length == 2 ? args : [this, args.first]
184
-
185
- if !field && object.respond_to?(:origin)
186
- Hobo.can_edit?(current_user, object.origin, object.origin_attribute)
212
+
213
+ if !field && (origin = object.try.origin)
214
+ Hobo.can_edit?(current_user, origin, object.origin_attribute)
187
215
  else
188
216
  Hobo.can_edit?(current_user, object, field)
189
217
  end
190
218
  end
191
219
  end
192
-
193
-
220
+
221
+
194
222
  def can_delete?(object=nil)
195
223
  Hobo.can_delete?(current_user, object || this)
196
224
  end
197
-
198
-
225
+
226
+
199
227
  def can_view?(object=nil, field=nil)
200
228
  if object.nil? && field.nil?
201
229
  if this_parent && this_field
@@ -206,25 +234,25 @@ module Hobo
206
234
  end
207
235
 
208
236
  @can_view_cache ||= {}
209
- @can_view_cache[ [object, field] ] ||=
237
+ @can_view_cache[ [object, field] ] ||=
210
238
  if !field && object.respond_to?(:origin)
211
239
  Hobo.can_view?(current_user, object.origin, object.origin_attribute)
212
240
  else
213
241
  Hobo.can_view?(current_user, object, field)
214
242
  end
215
243
  end
216
-
217
-
218
- def select_viewable(collection)
244
+
245
+
246
+ def select_viewable(collection=this)
219
247
  collection.select {|x| can_view?(x)}
220
248
  end
221
-
222
-
249
+
250
+
223
251
  def theme_asset(path)
224
252
  theme_path = Hobo.current_theme ? "hobothemes/#{Hobo.current_theme}/" : ""
225
253
  "#{base_url}/#{theme_path}#{path}"
226
254
  end
227
-
255
+
228
256
  def js_str(s)
229
257
  if s.is_a? Hobo::RawJs
230
258
  s.to_s
@@ -232,25 +260,25 @@ module Hobo
232
260
  "'" + s.to_s.gsub("'"){"\\'"} + "'"
233
261
  end
234
262
  end
235
-
236
-
263
+
264
+
237
265
  def make_params_js(*args)
238
266
  ("'" + make_params(*args) + "'").sub(/ \+ ''$/,'')
239
267
  end
240
-
241
-
268
+
269
+
242
270
  def nl_to_br(s)
243
271
  s.to_s.gsub("\n", "<br/>") if s
244
272
  end
245
-
246
-
273
+
274
+
247
275
  def param_name_for(object, field_path)
248
276
  field_path = field_path.to_s.split(".") if field_path.is_a?(String, Symbol)
249
277
  attrs = field_path.map{|part| "[#{part.to_s.sub /\?$/, ''}]"}.join
250
278
  "#{object.class.name.underscore}#{attrs}"
251
279
  end
252
-
253
-
280
+
281
+
254
282
  def param_name_for_this(foreign_key=false)
255
283
  return "" unless form_this
256
284
  name = if foreign_key && (refl = this_field_reflection) && refl.macro == :belongs_to
@@ -261,8 +289,8 @@ module Hobo
261
289
  register_form_field(name)
262
290
  name
263
291
  end
264
-
265
-
292
+
293
+
266
294
  def transpose_with_field(field, collection=nil)
267
295
  collection ||= this
268
296
  matrix = collection.map {|obj| obj.send(field) }
@@ -272,25 +300,36 @@ module Hobo
272
300
  end
273
301
  matrix.transpose
274
302
  end
275
-
276
-
303
+
304
+
277
305
  def new_for_current_user(model_or_assoc=nil)
278
306
  model_or_assoc ||= this
279
307
  model_or_assoc.user_new(current_user)
280
308
  end
281
-
282
-
309
+
310
+
283
311
  def defined_route?(r)
284
312
  @view.respond_to?("#{r}_url")
285
313
  end
286
-
287
-
314
+
315
+
288
316
  # Login url for a given user record or user class
289
- def login_url(user_or_class)
290
- c = user_or_class.is_a?(Class) ? user_or_class : user_or_class.class
291
- send("#{c.name.underscore}_login_url") rescue nil
317
+ def forgot_password_url(user_class=Hobo::User.default_user_model)
318
+ send("#{user_class.name.underscore}_forgot_password_url") rescue nil
292
319
  end
293
-
320
+
321
+
322
+ # Login url for a given user record or user class
323
+ def login_url(user_class=Hobo::User.default_user_model)
324
+ send("#{user_class.name.underscore}_login_url") rescue nil
325
+ end
326
+
327
+
328
+ # Sign-up url for a given user record or user class
329
+ def signup_url(user_class=Hobo::User.default_user_model)
330
+ send("#{user_class.name.underscore}_signup_url") rescue nil
331
+ end
332
+
294
333
 
295
334
  # Login url for a given user record or user class
296
335
  def logout_url(user_or_class=nil)
@@ -303,28 +342,18 @@ module Hobo
303
342
  end
304
343
  send("#{c.name.underscore}_logout_url") rescue nil
305
344
  end
306
-
307
345
 
308
- # Sign-up url for a given user record or user class
309
- def signup_url(user_or_class=nil)
310
- c = case user_or_class
311
- when Class; user_or_class
312
- when nil; Hobo::User.default_user_model
313
- else user_or_class
314
- end
315
- send("#{c.name.underscore}_signup_url") rescue nil
316
- end
317
-
346
+
318
347
  def current_page_url
319
348
  request.request_uri.match(/^([^?]*)/)._?[1]
320
349
  end
321
350
 
322
351
  def query_params
323
- query = request.request_uri.match(/(?:\?(.+))/)._?[1]
352
+ query = request.request_uri.match(/(?:\?([^?]+))/)._?[1]
324
353
  if query
325
354
  params = query.split('&')
326
355
  pairs = params.map do |param|
327
- pair = param.split('=')
356
+ pair = param.split('=', 2)
328
357
  pair.length == 1 ? pair + [''] : pair
329
358
  end
330
359
  HashWithIndifferentAccess[*pairs.flatten]
@@ -332,7 +361,7 @@ module Hobo
332
361
  HashWithIndifferentAccess.new
333
362
  end
334
363
  end
335
-
364
+
336
365
  def linkable?(*args)
337
366
  options = args.extract_options!
338
367
  target = args.empty? || args.first.is_a?(Symbol) ? this : args.shift
@@ -341,7 +370,7 @@ module Hobo
341
370
  if (origin = target.try.origin)
342
371
  klass = origin.class
343
372
  action = if action == :new
344
- "new_#{target.origin_attribute.to_s.singularize}"
373
+ "new_#{target.origin_attribute.to_s.singularize}"
345
374
  elsif action.nil?
346
375
  target.origin_attribute
347
376
  end
@@ -351,27 +380,27 @@ module Hobo
351
380
  else
352
381
  klass = target.class
353
382
  action ||= :show
354
- end
355
-
383
+ end
384
+
356
385
  Hobo::ModelRouter.linkable?(klass, action, options.reverse_merge(:subsite => subsite))
357
386
  end
358
-
359
-
387
+
388
+
360
389
  # Convenience helper for the default app
361
-
390
+
362
391
  # FIXME: this should interrogate the routes to find index methods, not the models
363
392
  def front_models
364
- Hobo.models.select {|m| linkable?(m) && !(m < Hobo::User)}
393
+ Hobo::Model.all_models.select {|m| linkable?(m) }
365
394
  end
366
-
367
-
368
-
395
+
396
+
397
+
369
398
  # debugging support
370
-
399
+
371
400
  def abort_with(*args)
372
401
  raise args.map{|arg| PP.pp(arg, "")}.join("-------\n")
373
402
  end
374
-
403
+
375
404
  def log_debug(*args)
376
405
  logger.debug("\n### DRYML Debug ###")
377
406
  logger.debug(args.map {|a| PP.pp(a, "")}.join("-------\n"))
@@ -379,7 +408,7 @@ module Hobo
379
408
  logger.debug("###################\n")
380
409
  args.first unless args.empty?
381
410
  end
382
-
411
+
383
412
  end
384
413
 
385
414
  end