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
@@ -0,0 +1,210 @@
1
+ require 'set'
2
+ require 'fileutils'
3
+
4
+ module Hobo
5
+
6
+ module Dryml
7
+
8
+ class DrymlGenerator
9
+
10
+ TEMPLATES = "#{HOBO_ROOT}/dryml_generators"
11
+ OUTPUT = "#{RAILS_ROOT}/app/views/taglibs/auto"
12
+
13
+ HEADER = "<!-- AUTOMATICALLY GENERATED FILE - DO NOT EDIT -->\n\n"
14
+
15
+ def self.run
16
+ @generator ||= DrymlGenerator.new
17
+ @generator.run
18
+ end
19
+
20
+
21
+ def initialize
22
+ @templates = {}
23
+ @digests = {}
24
+ load_templates
25
+ end
26
+
27
+ attr_accessor :subsite
28
+
29
+
30
+ def load_templates
31
+ Dir["#{TEMPLATES}/**/*.dryml.erb"].each do |f|
32
+ name = f[TEMPLATES.length + 1..-11]
33
+ erb = File.read(f)
34
+ @templates[name] = ERB.new(erb, nil, '-').src
35
+
36
+ # Create output directories and parents as required
37
+ [nil, *Hobo.subsites].each do |s|
38
+ FileUtils.mkdir_p(File.dirname("#{output_dir s}/#{name}"))
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+ def run
45
+ [nil, *Hobo.subsites].each { |s| run_for_subsite(s) }
46
+ end
47
+
48
+
49
+ def run_for_subsite(subsite)
50
+ self.subsite = subsite
51
+ @templates.each_pair do |name, src|
52
+ run_one(name, src)
53
+ end
54
+ end
55
+
56
+
57
+ def output_dir(s=subsite)
58
+ s ? "#{OUTPUT}/#{s}" : OUTPUT
59
+ end
60
+
61
+
62
+ def run_one(name, src)
63
+ dryml = instance_eval(src, name)
64
+ if dryml_changed?(name, dryml)
65
+ out = HEADER + dryml
66
+ File.open("#{output_dir}/#{name}.dryml", 'w') { |f| f.write(out) }
67
+ end
68
+ end
69
+
70
+
71
+ def dryml_changed?(name, dryml)
72
+ key = "#{subsite}/#{name}"
73
+ d = digest dryml
74
+ if d != @digests[key]
75
+ @digests[key] = d
76
+ true
77
+ else
78
+ false
79
+ end
80
+ end
81
+
82
+
83
+ def digest(s)
84
+ OpenSSL::Digest::Digest.digest('sha1', s)
85
+ end
86
+
87
+
88
+ # --- Helper methods for the templates --- #
89
+
90
+ attr_reader :controller
91
+
92
+
93
+ def controllers
94
+ Hobo::ModelController.all_controllers(subsite).sort_by &:name
95
+ end
96
+
97
+
98
+ def models
99
+ Hobo::Model.all_models.sort_by &:name
100
+ end
101
+
102
+ def each_controller
103
+ controllers.each do |controller|
104
+ @controller = controller
105
+ yield
106
+ end
107
+ @controller = nil
108
+ end
109
+
110
+
111
+ def each_model
112
+ models.each do |model|
113
+ @model = model
114
+ yield
115
+ end
116
+ @model = nil
117
+ end
118
+
119
+
120
+ def model
121
+ @model || @controller.model
122
+ end
123
+
124
+
125
+ def model_name(*options)
126
+ name = model.name
127
+ name = name.pluralize if :plural.in?(options)
128
+ name = name.titleize if :title.in?(options)
129
+ name = name.titleize.downcase if :lowercase.in?(options)
130
+ name = name.underscore.gsub('_', '-').gsub('/', '--') if :dashed.in?(options)
131
+ name
132
+ end
133
+
134
+
135
+ def model_class
136
+ model_name(:dashed)
137
+ end
138
+
139
+
140
+ def primary_collection_name(klass=model)
141
+ dependent_collection_names = klass.reflections.values.select do |refl|
142
+ refl.macro == :has_many && refl.options[:dependent]
143
+ end.*.name
144
+
145
+ (dependent_collection_names - through_collection_names(klass)).first
146
+ end
147
+
148
+
149
+ def through_collection_names(klass=model)
150
+ klass.reflections.values.select do |refl|
151
+ refl.macro == :has_many && refl.options[:through]
152
+ end.map {|x| x.options[:through]}
153
+ end
154
+
155
+
156
+ def linkable?(*args)
157
+ options = args.extract_options!
158
+ options[:subsite] = subsite
159
+ klass, action = if args.length == 1
160
+ [model, args.first]
161
+ else
162
+ args
163
+ end
164
+ Hobo::ModelRouter.linkable?(klass, action, options)
165
+ end
166
+
167
+
168
+ def sortable_collection?(collection, model=self.model)
169
+ # There's no perfect way to detect for this, given that acts_as_list
170
+ # does not provide any metadata to reflect on, but if the :order
171
+ # option is the same as the target classes position_column, that's a
172
+ # pretty safe bet
173
+ if defined? ActiveRecord::Acts::List::InstanceMethods
174
+ refl = model.reflections[collection]
175
+ klass = refl.klass
176
+ klass < ActiveRecord::Acts::List::InstanceMethods &&
177
+ klass.new.position_column == refl.options[:order].to_s
178
+ end
179
+ end
180
+
181
+
182
+ def standard_fields(*args)
183
+ klass = args.first.is_a?(Class) ? args.shift : model
184
+ extras = args
185
+
186
+ fields = klass.attr_order.*.to_s & klass.content_columns.*.name
187
+
188
+ fields -= %w{created_at updated_at created_on updated_on deleted_at} unless extras.include?(:include_timestamps)
189
+
190
+ bt = extras.include?(:belongs_to)
191
+ hm = extras.include?(:has_many)
192
+ klass.reflections.values.sort_by { |refl| refl.name.to_s }.map do |refl|
193
+ fields << refl.name.to_s if bt && refl.macro == :belongs_to
194
+ fields << refl.name.to_s if hm && refl.macro == :has_many
195
+ end
196
+
197
+ fields.reject! { |f| model.never_show? f }
198
+ fields
199
+ end
200
+
201
+
202
+ def a_or_an(word)
203
+ (word =~ /^[aeiou]/i ? "an " : "a ") + word
204
+ end
205
+
206
+ end
207
+
208
+ end
209
+
210
+ end
@@ -1,5 +1,5 @@
1
1
  class Hobo::Dryml::DrymlSupportController < ActionController::Base
2
-
2
+
3
3
  def edit_source
4
4
  dryml_editor = ENV['DRYML_EDITOR']
5
5
  if dryml_editor
@@ -0,0 +1,3 @@
1
+ module Hobo::Dryml::Parser
2
+
3
+ end
@@ -1,14 +1,14 @@
1
1
  module Hobo::Dryml::Parser
2
-
2
+
3
3
  class Attribute < REXML::Attribute
4
-
4
+
5
5
  def initialize(first, second=nil, parent=nil)
6
6
  super
7
7
  if first.is_a?(String) && second == true
8
8
  @value = true
9
9
  end
10
10
  end
11
-
11
+
12
12
  def value
13
13
  if has_rhs?
14
14
  super
@@ -24,18 +24,18 @@ module Hobo::Dryml::Parser
24
24
  @expanded_name
25
25
  end
26
26
  end
27
-
27
+
28
28
  def has_rhs?
29
29
  @value != true
30
30
  end
31
31
 
32
-
32
+
33
33
  # Override to supress Text.check call
34
34
  def element=( element )
35
35
  @element = element
36
36
  self
37
37
  end
38
-
38
+
39
39
  end
40
40
 
41
41
  end
@@ -1,9 +1,9 @@
1
1
  module Hobo::Dryml::Parser
2
-
2
+
3
3
  class BaseParser < REXML::Parsers::BaseParser
4
-
5
- NEW_REX = REXML::VERSION =~ /3\.1\.(\d)(?:\.(\d))?/ && $1.to_i*1000 + $2.to_i >= 7002
6
-
4
+
5
+ NEW_REX = defined?(REXML::VERSION) && REXML::VERSION =~ /3\.1\.(\d)(?:\.(\d))?/ && $1.to_i*1000 + $2.to_i >= 7002
6
+
7
7
  DRYML_NAME_STR = "#{NCNAME_STR}(?::(?:#{NCNAME_STR})?)?"
8
8
  DRYML_ATTRIBUTE_PATTERN = if NEW_REX
9
9
  /\s*(#{NAME_STR})(?:\s*=\s*(["'])(.*?)\4)?/um
@@ -16,10 +16,10 @@ module Hobo::Dryml::Parser
16
16
  /^<((?>#{DRYML_NAME_STR}))\s*((?>\s+#{NAME_STR}(?:\s*=\s*(["']).*?\3)?)*)\s*(\/)?>/um
17
17
  end
18
18
  DRYML_CLOSE_MATCH = /^\s*<\/(#{DRYML_NAME_STR})\s*>/um
19
-
19
+
20
20
  # For compatibility with REXML 3.1.7.3
21
- IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'](.*?)['"])?(\s+['"](.*?)["'])?/u
22
-
21
+ IDENTITY = /^([!\*\w\-]+)(\s+#{NCNAME_STR})?(\s+["'](.*?)['"])?(\s+['"](.*?)["'])?/u
22
+
23
23
  def pull
24
24
  if @closed
25
25
  x, @closed = @closed, nil
@@ -87,7 +87,7 @@ module Hobo::Dryml::Parser
87
87
  if @document_status == :in_doctype
88
88
  md = @source.match(/\s*(.*?>)/um)
89
89
  case md[1]
90
- when SYSTEMENTITY
90
+ when SYSTEMENTITY
91
91
  match = @source.match( SYSTEMENTITY, true )[1]
92
92
  return [ :externalentity, match ]
93
93
 
@@ -165,10 +165,10 @@ module Hobo::Dryml::Parser
165
165
  last_tag, line_no = @tags.pop
166
166
  #md = @source.match_to_consume( '>', CLOSE_MATCH)
167
167
  md = @source.match(DRYML_CLOSE_MATCH, true)
168
-
169
- valid_end_tag = last_tag =~ /^#{Regexp.escape(md[1])}(:.*)?/
168
+
169
+ valid_end_tag = last_tag =~ /^#{Regexp.escape(md[1])}(:.*)?$/
170
170
  raise REXML::ParseException.new( "Missing end tag for "+
171
- "'#{last_tag}' (line #{line_no}) (got \"#{md[1]}\")",
171
+ "'#{last_tag}' (line #{line_no}) (got \"#{md[1]}\")",
172
172
  @source) unless valid_end_tag
173
173
  return [ :end_element, last_tag, true ]
174
174
  elsif @source.buffer[1] == ?!
@@ -202,15 +202,15 @@ module Hobo::Dryml::Parser
202
202
  # Check for missing attribute quotes
203
203
  raise REXML::ParseException.new("missing attribute quote", @source) if
204
204
  defined?(MISSING_ATTRIBUTE_QUOTES) && @source.match(MISSING_ATTRIBUTE_QUOTES)
205
- raise REXML::ParseException.new("malformed XML: missing tag start", @source)
206
-
205
+ raise REXML::ParseException.new("malformed XML: missing tag start", @source)
206
+
207
207
  end
208
208
  attributes = {}
209
209
  #@nsstack.unshift(curr_ns=Set.new)
210
210
  if md[2].size > 0
211
211
  attrs = md[2].scan(DRYML_ATTRIBUTE_PATTERN)
212
212
  raise REXML::ParseException.new( "error parsing attributes: [#{attrs.join ', '}], excess = \"#$'\"", @source) if $' and $'.strip.size > 0
213
- attrs.each { |a,b,c,d,e|
213
+ attrs.each { |a,b,c,d,e|
214
214
  val = NEW_REX ? e : c
215
215
  if attributes.has_key? a
216
216
  msg = "Duplicate attribute #{a.inspect}"
@@ -219,7 +219,7 @@ module Hobo::Dryml::Parser
219
219
  attributes[a] = val || true
220
220
  }
221
221
  end
222
-
222
+
223
223
  if md[NEW_REX ? 6 : 4]
224
224
  @closed = md[1]
225
225
  #@nsstack.shift
@@ -250,5 +250,5 @@ module Hobo::Dryml::Parser
250
250
  return [ :dummy ]
251
251
  end
252
252
  end
253
-
253
+
254
254
  end
@@ -0,0 +1,57 @@
1
+ module Hobo::Dryml
2
+
3
+ module Parser
4
+
5
+ class Document < REXML::Document
6
+
7
+ def initialize(source, path)
8
+ super(nil)
9
+
10
+ # Replace <%...%> scriptlets with xml-safe references into a hash of scriptlets
11
+ @scriptlets = {}
12
+ source = source.gsub(/<%(.*?)%>/m) do
13
+ _, scriptlet = *Regexp.last_match
14
+ id = @scriptlets.size + 1
15
+ @scriptlets[id] = scriptlet
16
+ newlines = "\n" * scriptlet.count("\n")
17
+ "[![DRYML-ERB#{id}#{newlines}]!]"
18
+ end
19
+
20
+
21
+ @reference_src = "<dryml_page>" + source + "</dryml_page>"
22
+ rex_src = Hobo::Dryml::Parser::Source.new(@reference_src)
23
+
24
+ @elements = Hobo::Dryml::Parser::Elements.new(self)
25
+ build(rex_src)
26
+
27
+ rescue REXML::ParseException => e
28
+ raise Hobo::Dryml::DrymlSyntaxError, "File: #{path}\n#{e}"
29
+ end
30
+
31
+
32
+ def element_line_num(el)
33
+ offset = el.source_offset
34
+ @reference_src[0..offset].count("\n") + 1
35
+ end
36
+
37
+
38
+ def default_attribute_value
39
+ "&true"
40
+ end
41
+
42
+
43
+ def restore_erb_scriptlets(src)
44
+ src.gsub(/\[!\[DRYML-ERB(\d+)\s*\]!\]/m) {|s| "<%#{@scriptlets[$1.to_i]}%>" }
45
+ end
46
+
47
+
48
+ private
49
+ def build( source )
50
+ Hobo::Dryml::Parser::TreeParser.new( source, self ).parse
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -1,27 +1,27 @@
1
1
  module Hobo::Dryml::Parser
2
2
 
3
3
  class Element < REXML::Element
4
-
4
+
5
5
  def initialize(*args)
6
6
  super
7
7
  @elements = Hobo::Dryml::Parser::Elements.new(self)
8
8
  end
9
-
9
+
10
10
  def dryml_name
11
11
  expanded_name.sub(/:.*/, "")
12
12
  end
13
-
13
+
14
14
  attr_accessor :start_tag_source, :source_offset
15
-
15
+
16
16
  attr_writer :has_end_tag
17
17
  def has_end_tag?
18
18
  @has_end_tag
19
19
  end
20
-
20
+
21
21
  def parameter_tag?
22
22
  expanded_name =~ /:$/
23
23
  end
24
-
24
+
25
25
  end
26
-
26
+
27
27
  end
@@ -1,31 +1,31 @@
1
1
  module Hobo::Dryml::Parser
2
2
 
3
3
  class Element < REXML::Element
4
-
4
+
5
5
  def initialize(*args)
6
6
  super
7
7
  @elements = Hobo::Dryml::Parser::Elements.new(self)
8
8
  end
9
-
9
+
10
10
  def dryml_name
11
11
  expanded_name.sub(/:.*/, "")
12
12
  end
13
-
13
+
14
14
  attr_accessor :start_tag_source, :source_offset
15
-
15
+
16
16
  attr_writer :has_end_tag
17
17
  def has_end_tag?
18
18
  @has_end_tag
19
19
  end
20
-
20
+
21
21
  def parameter_tag?
22
22
  expanded_name =~ /:$/
23
23
  end
24
-
24
+
25
25
  end
26
-
26
+
27
27
  class Elements < REXML::Elements
28
-
28
+
29
29
  # Override to ensure DRYML elements are created
30
30
  def add(element=nil)
31
31
  rv = nil
@@ -39,7 +39,7 @@ module Hobo::Dryml::Parser
39
39
  element
40
40
  end
41
41
  end
42
-
42
+
43
43
  end
44
44
 
45
45
  end