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,26 +1,26 @@
1
1
  module Hobo::Dryml
2
2
 
3
3
  class TemplateEnvironment
4
-
4
+
5
5
  class << self
6
6
  def inherited(subclass)
7
7
  subclass.compiled_local_names = []
8
8
  end
9
9
  attr_accessor :load_time, :compiled_local_names
10
-
11
-
10
+
11
+
12
12
  def _register_tag_attrs(tag_name, attrs)
13
13
  @tag_attrs ||= {}
14
14
  @tag_attrs[tag_name] = attrs
15
15
  end
16
-
17
-
16
+
17
+
18
18
  def tag_attrs
19
19
  @tag_attrs ||= {}
20
20
  end
21
-
21
+
22
22
  alias_method :delayed_alias_method_chain, :alias_method_chain
23
-
23
+
24
24
  end
25
25
 
26
26
  for mod in ActionView::Helpers.constants.grep(/Helper$/).map {|m| ActionView::Helpers.const_get(m)}
@@ -49,18 +49,24 @@ module Hobo::Dryml
49
49
  end
50
50
  end
51
51
 
52
-
53
52
  for attr in [:erb_binding, :part_contexts, :view_name,
54
53
  :this, :this_parent, :this_field, :this_key,
55
- :form_field_path, :form_this, :form_field_names]
54
+ :form_this, :form_field_names]
56
55
  class_eval "def #{attr}; @_#{attr}; end"
57
56
  end
58
57
 
58
+ def form_field_path
59
+ @_form_field_path.nil? and raise Hobo::Dryml::DrymlException,
60
+ "DRYML cannot provide the correct form-field name here (this_field = #{this_field.inspect}, this = #{this.inspect})"
61
+ @_form_field_path
62
+ end
63
+
64
+
59
65
  def this_key=(key)
60
66
  @_this_key = key
61
67
  end
62
-
63
-
68
+
69
+
64
70
  # The type of this, or when this is nil, the type that would be expected in the current field
65
71
  def this_type
66
72
  @_this_type ||= if this == false || this == true
@@ -83,25 +89,25 @@ module Hobo::Dryml
83
89
  type
84
90
  end
85
91
  else
86
- # Nothing to go on at all
92
+ # Nothing to go on at all
87
93
  Object
88
94
  end
89
95
  end
90
-
91
-
96
+
97
+
92
98
  def this_field_reflection
93
99
  this.try.proxy_reflection ||
94
100
  (this_parent && this_field && this_parent.class.respond_to?(:reflections) && this_parent.class.reflections[this_field.to_sym])
95
101
  end
96
-
97
-
102
+
103
+
98
104
  def attrs_for(name)
99
105
  self.class.tag_attrs[name.to_sym]
100
106
  end
101
-
102
-
107
+
108
+
103
109
  def add_classes!(attributes, *classes)
104
- classes = classes.flatten.select{|x|x}.map{|x| x.to_s.dasherize}
110
+ classes = classes.flatten.select{|x|x}
105
111
  current = attributes[:class]
106
112
  attributes[:class] = (current ? current.split + classes : classes).uniq.join(' ')
107
113
  attributes
@@ -112,7 +118,7 @@ module Hobo::Dryml
112
118
  add_classes!(HashWithIndifferentAccess.new(attributes), classes)
113
119
  end
114
120
 
115
-
121
+
116
122
  def merge_attrs(attrs, overriding_attrs)
117
123
  return {}.update(attrs) if overriding_attrs.nil?
118
124
  attrs = attrs.with_indifferent_access unless attrs.is_a?(HashWithIndifferentAccess)
@@ -120,19 +126,14 @@ module Hobo::Dryml
120
126
  attrs = add_classes(attrs, *classes.split) if classes
121
127
  attrs.update(overriding_attrs - [:class])
122
128
  end
123
-
124
-
129
+
130
+
125
131
  def scope
126
132
  @_scoped_variables
127
133
  end
128
134
 
129
135
 
130
- def attr_extension(s)
131
- AttributeExtensionString.new(s)
132
- end
133
-
134
-
135
- def dom_id(object=nil, attribute=nil)
136
+ def dom_id(object=nil, attribute=nil)
136
137
  if object.nil?
137
138
  # nothing passed -- use context
138
139
  if this_parent && this_field
@@ -142,15 +143,14 @@ module Hobo::Dryml
142
143
  end
143
144
  end
144
145
 
145
- id = object.try.typed_id
146
- if id
146
+ if (id = object.try.typed_id)
147
147
  attribute ? "#{id}_#{attribute}" : id
148
148
  else
149
149
  "nil"
150
150
  end
151
151
  end
152
-
153
-
152
+
153
+
154
154
  def call_part(part_node_id, part_name, part_this=nil, *locals)
155
155
  res = ''
156
156
  if part_this
@@ -167,24 +167,24 @@ module Hobo::Dryml
167
167
  res
168
168
  end
169
169
 
170
-
170
+
171
171
  def call_polymorphic_tag(name, *args)
172
172
  name = name.to_s.gsub('-', '_')
173
173
  type = args.first.is_a?(Class) ? args.shift : nil
174
174
  attributes, parameters = args
175
-
175
+
176
176
  tag = find_polymorphic_tag(name, type)
177
177
  if tag != name
178
178
  send(tag, attributes || {}, parameters || {})
179
179
  else
180
- nil
180
+ block_given? ? yield : nil
181
181
  end
182
182
  end
183
183
 
184
-
185
- def find_polymorphic_tag(name, call_type=nil)
186
- call_type ||= (this.is_a?(Array) && this.respond_to?(:member_class) && this.member_class) || this_type
187
184
 
185
+ def find_polymorphic_tag(name, call_type=nil)
186
+ call_type ||= (this.respond_to?(:member_class) && this.member_class) || this_type
187
+
188
188
  while true
189
189
  if respond_to?(poly_name = "#{name}__for_#{call_type.name.to_s.underscore.gsub('/', '__')}")
190
190
  return poly_name
@@ -197,20 +197,26 @@ module Hobo::Dryml
197
197
  end
198
198
  end
199
199
  end
200
-
201
-
202
- def repeat_attribute(array, &b)
203
- res = array.map { |x| new_object_context(x, &b) }.join
204
- Hobo::Dryml.last_if = !array.empty?
205
- res
200
+
201
+
202
+ def repeat_attribute(string_or_array)
203
+ res = nil
204
+ if string_or_array.instance_of?(String)
205
+ new_field_context(string_or_array) do
206
+ res = context_map { yield }
207
+ end
208
+ else
209
+ res = context_map(string_or_array) { yield }
210
+ end
211
+ res.join
206
212
  end
207
213
 
208
-
214
+
209
215
  def _erbout
210
216
  @_erb_output
211
217
  end
212
-
213
-
218
+
219
+
214
220
  def _output(s)
215
221
  @_erb_output.concat(s)
216
222
  end
@@ -230,35 +236,75 @@ module Hobo::Dryml
230
236
 
231
237
  def new_object_context(new_this)
232
238
  new_context do
233
- @_this_parent, @_this_field = [new_this.origin, new_this.origin_attribute] if new_this.respond_to?(:origin)
239
+ if new_this.respond_to?(:origin)
240
+ @_this_parent, @_this_field = new_this.origin, new_this.origin_attribute
241
+ else
242
+ @_this_parent, @_this_field = [nil, nil]
243
+ end
234
244
  @_this = new_this
245
+
246
+ # We might have lost track of where 'this' is relative to the form_this
247
+ # check if this or this_parent are objects we've seen before in this form
248
+ @_form_field_path = find_form_field_path(new_this) if @_form_field_path
249
+
235
250
  yield
236
251
  end
237
252
  end
238
253
 
239
254
 
240
- def new_field_context(field_path, tag_this=nil)
255
+ def new_field_context(field_path, new_this=nil)
241
256
  new_context do
242
- path = if field_path.is_a? Array
243
- field_path
244
- elsif field_path.is_a? String
257
+ path = if field_path.is_a? String
245
258
  field_path.split('.')
246
259
  else
247
- [field_path]
260
+ Array(field_path)
248
261
  end
249
- parent, field, obj = Hobo.get_field_path(tag_this || this, path)
250
- @_this, @_this_parent, @_this_field = obj, parent, field
251
- @_form_field_path += path if @_form_field_path
262
+ if new_this
263
+ raise ArgumentError, "invlaid context change" unless path.length == 1
264
+ @_this_parent, @_this_field, @_this = this, path.first, new_this
265
+ else
266
+ parent, field, obj = Hobo.get_field_path(this, path)
267
+ @_this, @_this_parent, @_this_field = obj, parent, field
268
+ end
269
+
270
+ if @_form_field_path
271
+ @_form_field_path += path
272
+ @_form_field_paths_by_object[@_this] = @_form_field_path
273
+ end
274
+
252
275
  yield
253
276
  end
254
277
  end
278
+
279
+
280
+ def find_form_field_path(object)
281
+ back = []
282
+ while object
283
+ path = @_form_field_paths_by_object[object]
284
+ if path
285
+ path = path + back unless back.empty?
286
+ return path
287
+ end
288
+ if object.respond_to? :origin
289
+ back.unshift object.origin_attribute
290
+ object = object.origin
291
+ else
292
+ return nil
293
+ end
294
+ end
295
+ end
296
+
297
+
255
298
 
256
299
 
257
300
  def _tag_context(attributes)
258
- with = attributes[:with] == "page" ? @this : attributes[:with]
259
-
260
- if attributes.has_key?(:field)
261
- new_field_context(attributes[:field], with) { yield }
301
+ with = attributes[:with]
302
+ field = attributes[:field]
303
+
304
+ if with && field
305
+ new_object_context(with) { new_field_context(field) { yield } }
306
+ elsif field
307
+ new_field_context(field) { yield }
262
308
  elsif attributes.has_key?(:with)
263
309
  new_object_context(with) { yield }
264
310
  else
@@ -271,13 +317,14 @@ module Hobo::Dryml
271
317
  @_form_this = this
272
318
  @_form_field_path = []
273
319
  @_form_field_names = []
320
+ @_form_field_paths_by_object = { @_form_this => [] }
274
321
  res = yield
275
322
  field_names = @_form_field_names
276
- @_form_this = @_form_field_path = @_form_field_names = nil
323
+ @_form_this = @_form_field_path = @_form_field_names = @_form_field_paths_by_object = nil
277
324
  [res, field_names]
278
325
  end
279
-
280
-
326
+
327
+
281
328
  def register_form_field(name)
282
329
  @_form_field_names << name
283
330
  end
@@ -288,16 +335,16 @@ module Hobo::Dryml
288
335
  #ensure with and field are not in attributes
289
336
  attributes.delete(:with)
290
337
  attributes.delete(:field)
291
-
338
+
292
339
  # declared attributes don't appear in the attributes hash
293
340
  stripped_attributes = HashWithIndifferentAccess.new.update(attributes)
294
341
  locals.each {|a| stripped_attributes.delete(a.to_sym) }
295
-
342
+
296
343
  # Return locals declared as local variables (attrs="...")
297
344
  locals.map {|a| attributes[a.to_sym]} + [stripped_attributes]
298
345
  end
299
-
300
-
346
+
347
+
301
348
  def call_tag_parameter_with_default_content(the_tag, attributes, default_content, overriding_content_proc)
302
349
  if the_tag.is_a?(String, Symbol) && the_tag.to_s.in?(Hobo.static_tags)
303
350
  body = if overriding_content_proc
@@ -317,45 +364,54 @@ module Hobo::Dryml
317
364
  send(the_tag, attributes, { :default => d })
318
365
  end
319
366
  end
320
-
321
-
367
+
368
+
322
369
  def call_tag_parameter(the_tag, attributes, parameters, caller_parameters, param_name)
323
370
  overriding_proc = caller_parameters[param_name]
324
371
  replacing_proc = caller_parameters[:"#{param_name}_replacement"]
325
372
 
373
+ unless param_name == the_tag || param_name == :default
374
+ classes = attributes[:class]
375
+ param_class = param_name.to_s.gsub('_', '-')
376
+ attributes[:class] = if classes
377
+ classes =~ /\b#{param_class}\b/ ? classes : "#{classes} #{param_class}"
378
+ else
379
+ param_class
380
+ end
381
+ end
382
+
326
383
  if param_name == :default && overriding_proc
327
384
  # :default content is handled specially
328
-
385
+
329
386
  call_tag_parameter_with_default_content(the_tag, attributes, parameters[:default], overriding_proc)
330
387
 
331
388
  elsif replacing_proc
332
389
  # The caller is replacing this parameter. Don't call the tag
333
390
  # at all, just the overriding proc, but pass the restorable
334
391
  # tag as a parameter to the overriding proc
335
-
392
+
336
393
  tag_restore = proc do |restore_attrs, restore_params|
337
394
  # Call the replaced tag with the attributes and parameters
338
395
  # as given in the original tag definition, and with the
339
396
  # specialisation given on the 'restore' call
340
-
397
+
341
398
  if overriding_proc
342
399
  overriding_attributes, overriding_parameters = overriding_proc.call
343
400
  restore_attrs = overriding_attributes.merge(restore_attrs)
344
401
  restore_params = overriding_parameters.merge(restore_params)
345
402
  end
346
-
403
+
347
404
  override_and_call_tag(the_tag, attributes, parameters, restore_attrs, restore_params)
348
405
  end
349
406
  replacing_proc.call(tag_restore)
350
-
351
-
407
+
352
408
  else
353
409
  overriding_attributes, overriding_parameters = overriding_proc._?.call
354
410
  override_and_call_tag(the_tag, attributes, parameters, overriding_attributes, overriding_parameters)
355
- end
411
+ end
356
412
  end
357
-
358
-
413
+
414
+
359
415
  def override_and_call_tag(the_tag, general_attributes, general_parameters, overriding_attributes, overriding_parameters)
360
416
  attributes = overriding_attributes ? merge_attrs(general_attributes, overriding_attributes) : general_attributes
361
417
  if overriding_parameters
@@ -364,12 +420,12 @@ module Hobo::Dryml
364
420
  else
365
421
  parameters = general_parameters
366
422
  end
367
-
423
+
368
424
  default_content = parameters[:default]
369
-
425
+
370
426
  if the_tag.is_a?(String, Symbol) && the_tag.to_s.in?(Hobo.static_tags)
371
427
  body = if overriding_default_content
372
- new_context { overriding_default_content.call(proc { default_content._?.call(nil) }) }
428
+ new_context { overriding_default_content.call(proc { default_content.call(nil) if default_content }) }
373
429
  elsif default_content
374
430
  new_context { default_content.call(nil) }
375
431
  else
@@ -377,13 +433,15 @@ module Hobo::Dryml
377
433
  end
378
434
  element(the_tag, attributes, body)
379
435
  else
380
- d = if overriding_default_content
381
- proc { |default| overriding_default_content.call(proc { default_content._?.call(default) }) }
382
- else
383
- proc { |default| default_content._?.call(default) }
384
- end
385
- parameters = parameters.merge(:default => d)
386
-
436
+ if default_content || overriding_default_content
437
+ d = if overriding_default_content
438
+ proc { |default| overriding_default_content.call(proc { default_content.call(default) if default_content }) }
439
+ else
440
+ proc { |default| default_content.call(default) if default_content }
441
+ end
442
+ parameters = parameters.merge(:default => d)
443
+ end
444
+
387
445
  if the_tag.is_a?(String, Symbol)
388
446
  # It's a defined DRYML tag
389
447
  send(the_tag, attributes, parameters)
@@ -408,18 +466,18 @@ module Hobo::Dryml
408
466
  # The override is a replace parameter - just pass it on
409
467
  overriding_proc
410
468
  else
411
- proc do
469
+ proc do
412
470
  overriding_attrs, overriding_parameters = overriding_proc.call
413
471
  general_attrs, general_parameters = general_proc.call
414
-
472
+
415
473
  attrs = merge_attrs(general_attrs, overriding_attrs)
416
474
  overriding_default = overriding_parameters.delete(:default)
417
475
  params = general_parameters.merge(overriding_parameters)
418
-
476
+
419
477
  # The overrider should provide its :default as the new
420
478
  # 'default_content'
421
479
  if overriding_default
422
- params[:default] =
480
+ params[:default] =
423
481
  if general_parameters[:default]
424
482
  proc do |default|
425
483
  overriding_default.call(proc { new_context { _output(general_parameters[:default].call(default)) } } )
@@ -436,27 +494,27 @@ module Hobo::Dryml
436
494
  end
437
495
  end
438
496
  end
439
-
497
+
440
498
 
441
499
  def part_contexts_javascripts
442
500
  storage = part_contexts_storage
443
- storage.blank? ? "" : "<script>\n#{storage}</script>\n"
501
+ storage.blank? ? "" : "<script type=\"text/javascript\">\n#{storage}</script>\n"
444
502
  end
445
-
446
-
503
+
504
+
447
505
  def part_contexts_storage
448
506
  PartContext.client_side_storage(@_part_contexts, session)
449
507
  end
450
-
451
-
508
+
509
+
452
510
  def render_tag(tag_name, attributes)
453
- method_name = tag_name.gsub('-', '_')
511
+ method_name = tag_name.to_s.gsub('-', '_')
454
512
  if respond_to?(method_name)
455
- res = (send(method_name, attributes) + part_contexts_javascripts).strip
513
+ res = send(method_name, attributes).strip
456
514
 
457
515
  # TODO: Temporary hack to get the dryml metadata comments in the right place
458
516
  if false && RAILS_ENV == "development"
459
- res.gsub(/^(.*?)(<!DOCTYPE.*?>).*?(<html.*?>)/m, "\\2\\3\\1")
517
+ res.gsub(/^(.*?)(<!DOCTYPE.*?>).*?(<html.*?>)/m, "\\2\\3\\1")
460
518
  else
461
519
  res
462
520
  end
@@ -464,16 +522,16 @@ module Hobo::Dryml
464
522
  false
465
523
  end
466
524
  end
467
-
468
-
469
- def element(name, attributes, content=nil, escape = true, &block)
525
+
526
+
527
+ def element(name, attributes, content=nil, escape = true, empty = false, &block)
470
528
  unless attributes.blank?
471
529
  attrs = []
472
530
  if escape
473
531
  attributes.each do |key, value|
474
532
  next unless value
475
- key = key.to_s.gsub("_", "-")
476
-
533
+ key = key.to_s.gsub("_", "-")
534
+
477
535
  value = if ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES.include?(key)
478
536
  key
479
537
  else
@@ -482,7 +540,7 @@ module Hobo::Dryml
482
540
  end
483
541
  attrs << %(#{key}="#{value}")
484
542
  end
485
-
543
+
486
544
  else
487
545
  attrs = options.map do |key, value|
488
546
  key = key.to_s.gsub("_", "-")
@@ -491,12 +549,12 @@ module Hobo::Dryml
491
549
  end
492
550
  attr_string = " #{attrs.sort * ' '}" unless attrs.empty?
493
551
  end
494
-
495
- content = new_context(&block) if block_given?
496
- res = if content
497
- "<#{name}#{attr_string}>#{content}</#{name}>"
552
+
553
+ content = new_context { yield } if block_given?
554
+ res = if empty
555
+ "<#{name}#{attr_string}#{scope.xmldoctype ? ' /' : ''}>"
498
556
  else
499
- "<#{name}#{attr_string} />"
557
+ "<#{name}#{attr_string}>#{content}</#{name}>"
500
558
  end
501
559
  if block && eval("defined? _erbout", block.binding) # in erb context
502
560
  _output(res)
@@ -505,11 +563,11 @@ module Hobo::Dryml
505
563
  end
506
564
  end
507
565
 
508
-
566
+
509
567
  def session
510
568
  @view ? @view.session : {}
511
569
  end
512
-
570
+
513
571
 
514
572
  def method_missing(name, *args, &b)
515
573
  if @view
@@ -518,7 +576,7 @@ module Hobo::Dryml
518
576
  raise NoMethodError, name.to_s
519
577
  end
520
578
  end
521
-
579
+
522
580
  end
523
581
 
524
582
  end