rad_core 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) hide show
  1. data/Rakefile +10 -0
  2. data/lib/rad/controller/abstract_controller/micelaneous.rb +31 -0
  3. data/lib/rad/controller/abstract_controller/render.rb +160 -0
  4. data/lib/rad/controller/abstract_controller/responder.rb +17 -0
  5. data/lib/rad/controller/abstract_controller.rb +64 -0
  6. data/lib/rad/controller/controller_context.rb +15 -0
  7. data/lib/rad/controller/http_controller.rb +48 -0
  8. data/lib/rad/controller/processors/controller_caller.rb +28 -0
  9. data/lib/rad/controller/processors/controller_error_handling.rb +51 -0
  10. data/lib/rad/controller/processors/controller_logger.rb +12 -0
  11. data/lib/rad/controller.rb +28 -0
  12. data/lib/rad/conveyor/conveyor.rb +74 -0
  13. data/lib/rad/conveyor/conveyors.rb +20 -0
  14. data/lib/rad/conveyor/params.rb +14 -0
  15. data/lib/rad/conveyor/processor.rb +68 -0
  16. data/lib/rad/conveyor/processors/conveyor_logger.rb +25 -0
  17. data/lib/rad/conveyor/workspace.rb +36 -0
  18. data/lib/rad/conveyor.rb +29 -0
  19. data/lib/rad/environment/config.rb +111 -0
  20. data/lib/rad/environment/dependency_resolver.rb +107 -0
  21. data/lib/rad/environment/environment.rb +29 -0
  22. data/lib/rad/environment/files_helper.rb +55 -0
  23. data/lib/rad/environment/logger.rb +21 -0
  24. data/lib/rad/environment.rb +55 -0
  25. data/lib/rad/html/flash.rb +42 -0
  26. data/lib/rad/html/helpers/basic_html_helper.rb +83 -0
  27. data/lib/rad/html/helpers/flash_helper.rb +5 -0
  28. data/lib/rad/html/helpers/form_helper.rb +115 -0
  29. data/lib/rad/html/helpers/html_helper.rb +5 -0
  30. data/lib/rad/html/helpers/javascript_helper.rb +18 -0
  31. data/lib/rad/html/helpers/model_helper.rb +135 -0
  32. data/lib/rad/html/include_into_controller.rb +0 -0
  33. data/lib/rad/html/processors/prepare_flash.rb +26 -0
  34. data/lib/rad/html/processors/scoped_params.rb +26 -0
  35. data/lib/rad/html.rb +26 -0
  36. data/lib/rad/http/http.rb +21 -0
  37. data/lib/rad/http/http_adapter.rb +36 -0
  38. data/lib/rad/http/middleware/static_files.rb +21 -0
  39. data/lib/rad/http/processors/evaluate_format.rb +22 -0
  40. data/lib/rad/http/processors/http_logger.rb +15 -0
  41. data/lib/rad/http/processors/http_writer.rb +30 -0
  42. data/lib/rad/http/processors/prepare_params.rb +22 -0
  43. data/lib/rad/http/support/rack/fixes.rb +36 -0
  44. data/lib/rad/http/support/rack/rack_adapter.rb +67 -0
  45. data/lib/rad/http/support/rack/request.rb +42 -0
  46. data/lib/rad/http/support/rack/response.rb +86 -0
  47. data/lib/rad/http.rb +48 -0
  48. data/lib/rad/integration/controller_micelaneous_helper.rb +19 -0
  49. data/lib/rad/integration/router/abstract_routing_helper.rb +22 -0
  50. data/lib/rad/integration/router/controller_routing_helper.rb +58 -0
  51. data/lib/rad/integration/router/view_routing_helper.rb +104 -0
  52. data/lib/rad/integration.rb +30 -0
  53. data/lib/rad/mail/letter.rb +30 -0
  54. data/lib/rad/mail/mail_controller.rb +31 -0
  55. data/lib/rad/mail/mailer.rb +23 -0
  56. data/lib/rad/mail/processors/letter_builder.rb +36 -0
  57. data/lib/rad/mail.rb +15 -0
  58. data/lib/rad/profiles/mail.rb +16 -0
  59. data/lib/rad/profiles/web.rb +68 -0
  60. data/lib/rad/profiles/web_require.rb +5 -0
  61. data/lib/rad/remote/processors/remote_caller.rb +54 -0
  62. data/lib/rad/remote/processors/remote_logger.rb +13 -0
  63. data/lib/rad/remote/remote.rb +15 -0
  64. data/lib/rad/remote.rb +9 -0
  65. data/lib/rad/router/core/configurator.rb +25 -0
  66. data/lib/rad/router/core/core_routing_helper.rb +41 -0
  67. data/lib/rad/router/core/default_format_processor.rb +12 -0
  68. data/lib/rad/router/core/processors/router.rb +29 -0
  69. data/lib/rad/router/core/router.rb +271 -0
  70. data/lib/rad/router/core/simple_router.rb +23 -0
  71. data/lib/rad/router/routers/abstract_router.rb +62 -0
  72. data/lib/rad/router/routers/alias_router.rb +113 -0
  73. data/lib/rad/router/routers/restful_router.rb +113 -0
  74. data/lib/rad/router.rb +29 -0
  75. data/lib/rad/spec/controller.rb +41 -0
  76. data/lib/rad/spec/environment.rb +51 -0
  77. data/lib/rad/spec/http.rb +93 -0
  78. data/lib/rad/spec/mail.rb +31 -0
  79. data/lib/rad/spec/remote.rb +9 -0
  80. data/lib/rad/spec/router.rb +18 -0
  81. data/lib/rad/spec/template.rb +12 -0
  82. data/lib/rad/spec/view.rb +10 -0
  83. data/lib/rad/spec/xhtml.rb +33 -0
  84. data/lib/rad/spec.rb +11 -0
  85. data/lib/rad/support/active_support/locales/en/actionpack.yml +154 -0
  86. data/lib/rad/support/active_support/locales/en/activesupport.yml +36 -0
  87. data/lib/rad/support/active_support/micelaneous.rb +2 -0
  88. data/lib/rad/support/active_support/time.rb +105 -0
  89. data/lib/rad/support/active_support.rb +49 -0
  90. data/lib/rad/support/addressable.rb +45 -0
  91. data/lib/rad/support/buffered_logger.rb +44 -0
  92. data/lib/rad/support/callbacks.rb +168 -0
  93. data/lib/rad/support/exception.rb +31 -0
  94. data/lib/rad/support/filters.rb +34 -0
  95. data/lib/rad/support/format.rb +17 -0
  96. data/lib/rad/support/hacks_and_fixes.rb +23 -0
  97. data/lib/rad/support/micon.rb +13 -0
  98. data/lib/rad/support/mime.rb +13 -0
  99. data/lib/rad/support/module.rb +48 -0
  100. data/lib/rad/support/rson.rb +53 -0
  101. data/lib/rad/support/ruby_ext_with_active_support.rb +4 -0
  102. data/lib/rad/support/string.rb +26 -0
  103. data/lib/rad/support.rb +63 -0
  104. data/lib/rad/template/support/tilt.rb +68 -0
  105. data/lib/rad/template/support/tilt_fixes.rb +17 -0
  106. data/lib/rad/template/template.rb +250 -0
  107. data/lib/rad/template/template_context.rb +62 -0
  108. data/lib/rad/template.rb +25 -0
  109. data/lib/rad_core/gems.rb +31 -0
  110. data/readme.md +33 -0
  111. data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
  112. data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +11 -0
  113. data/spec/controller/abstract_controller_spec.rb +132 -0
  114. data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
  115. data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
  116. data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
  117. data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
  118. data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
  119. data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
  120. data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
  121. data/spec/controller/controller_context_spec.rb +123 -0
  122. data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
  123. data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
  124. data/spec/controller/controller_helper_spec.rb +53 -0
  125. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
  126. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
  127. data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
  128. data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
  129. data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
  130. data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
  131. data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
  132. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
  133. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
  134. data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
  135. data/spec/controller/controller_render_spec/views/MultipleActions/actions.haml +7 -0
  136. data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
  137. data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
  138. data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
  139. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +1 -0
  140. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +1 -0
  141. data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
  142. data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
  143. data/spec/controller/controller_render_spec.rb +217 -0
  144. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
  145. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
  146. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
  147. data/spec/controller/error_handling_spec.rb +117 -0
  148. data/spec/controller/http_controller_spec.rb +130 -0
  149. data/spec/controller/spec_helper.rb +19 -0
  150. data/spec/conveyor/conveyor_spec.rb +124 -0
  151. data/spec/conveyor/spec_helper.rb +3 -0
  152. data/spec/environment/config_spec/config.default.yml +3 -0
  153. data/spec/environment/config_spec/config.development.yml +3 -0
  154. data/spec/environment/config_spec/config.yml +5 -0
  155. data/spec/environment/config_spec.rb +30 -0
  156. data/spec/environment/environment_spec/path1/file1 +0 -0
  157. data/spec/environment/environment_spec/path1/some_folder/some_file +0 -0
  158. data/spec/environment/environment_spec/path2/file2 +0 -0
  159. data/spec/environment/environment_spec/path2/some_folder/some_file +0 -0
  160. data/spec/environment/environment_spec.rb +65 -0
  161. data/spec/environment/logger_spec.rb +19 -0
  162. data/spec/environment/minimal_app_spec/app.rb +1 -0
  163. data/spec/environment/minimal_app_spec.rb +25 -0
  164. data/spec/environment/spec_helper.rb +1 -0
  165. data/spec/environment/standard_app_spec/app/lib/app/init.rb +3 -0
  166. data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -0
  167. data/spec/environment/standard_app_spec/plugin_b/lib/emptygit +0 -0
  168. data/spec/environment/standard_app_spec.rb +48 -0
  169. data/spec/html/basic_html_helper_spec.rb +29 -0
  170. data/spec/html/form_helper_spec.rb +63 -0
  171. data/spec/html/javascript_helper_spec.rb +15 -0
  172. data/spec/html/model_helper_spec.rb +81 -0
  173. data/spec/html/scoped_params_spec.rb +15 -0
  174. data/spec/html/spec_helper.rb +28 -0
  175. data/spec/http/http_spec/app/lib/app/init.rb +10 -0
  176. data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
  177. data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
  178. data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +5 -0
  179. data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
  180. data/spec/http/http_spec.rb +51 -0
  181. data/spec/http/micelaneous_spec.rb +13 -0
  182. data/spec/http/spec_helper.rb +5 -0
  183. data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
  184. data/spec/integration/basic_spec.rb +79 -0
  185. data/spec/integration/controller_routing_helper_spec.rb +84 -0
  186. data/spec/integration/flash_spec.rb +206 -0
  187. data/spec/integration/spec_helper.rb +5 -0
  188. data/spec/integration/spec_helper_spec.rb +63 -0
  189. data/spec/integration/view_routing_helper_spec.rb +134 -0
  190. data/spec/mail/mail_controller_spec/views/body_template_spec/signup.erb +1 -0
  191. data/spec/mail/mail_controller_spec.rb +61 -0
  192. data/spec/mail/spec_helper.rb +7 -0
  193. data/spec/remote/remote_spec.rb +75 -0
  194. data/spec/remote/spec_helper.rb +17 -0
  195. data/spec/router/alias_router_spec.rb +98 -0
  196. data/spec/router/basic_spec.rb +111 -0
  197. data/spec/router/configurator_spec.rb +18 -0
  198. data/spec/router/integration_spec.rb +42 -0
  199. data/spec/router/persistent_params_spec.rb +65 -0
  200. data/spec/router/restful_router_spec.rb +120 -0
  201. data/spec/router/routing_helper_spec.rb +55 -0
  202. data/spec/router/spec_helper.rb +20 -0
  203. data/spec/support/callbacks_spec.rb +157 -0
  204. data/spec/support/filters_spec.rb +60 -0
  205. data/spec/support/spec_helper.rb +4 -0
  206. data/spec/template/spec_helper.rb +6 -0
  207. data/spec/template/template_spec/file.erb +1 -0
  208. data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
  209. data/spec/template/template_spec/views/basic/extension.erb +1 -0
  210. data/spec/template/template_spec/views/basic/general.html.erb +5 -0
  211. data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
  212. data/spec/template/template_spec/views/format/format.erb +1 -0
  213. data/spec/template/template_spec/views/format/format.html.erb +1 -0
  214. data/spec/template/template_spec/views/format/format.js.erb +1 -0
  215. data/spec/template/template_spec/views/format_for_partials/_form.html.erb +1 -0
  216. data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -0
  217. data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
  218. data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
  219. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
  220. data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
  221. data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
  222. data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
  223. data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
  224. data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
  225. data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
  226. data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
  227. data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
  228. data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
  229. data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
  230. data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
  231. data/spec/template/template_spec/views/nested/format/a.erb +1 -0
  232. data/spec/template/template_spec/views/nested/format/b.erb +1 -0
  233. data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
  234. data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
  235. data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
  236. data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
  237. data/spec/template/template_spec/views/nesting_format/_edit.html.erb +1 -0
  238. data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
  239. data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
  240. data/spec/template/template_spec/views/other/template.erb +1 -0
  241. data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
  242. data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
  243. data/spec/template/template_spec.rb +204 -0
  244. data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
  245. data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
  246. data/spec/template/tilt_spec/views/encoding/erb.erb +1 -0
  247. data/spec/template/tilt_spec/views/encoding/haml.haml +1 -0
  248. data/spec/template/tilt_spec/views/errors.erb +3 -0
  249. data/spec/template/tilt_spec/views/errors.haml +3 -0
  250. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
  251. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
  252. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
  253. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
  254. data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
  255. data/spec/template/tilt_spec/views/ugly.haml +3 -0
  256. data/spec/template/tilt_spec/views/yield.erb +1 -0
  257. data/spec/template/tilt_spec.rb +98 -0
  258. metadata +531 -0
@@ -0,0 +1,168 @@
1
+ module Rad
2
+ module Callbacks
3
+ class AbstractCallback
4
+ attr_accessor :executor, :terminator
5
+ attr_reader :conditions
6
+ def conditions= conditions
7
+ @conditions = {}
8
+ conditions.each do |k, v|
9
+ @conditions[k.to_sym] = if v.is_a? Symbol
10
+ v.to_s
11
+ elsif v.is_a? Array
12
+ v.collect{|e| e.to_s}
13
+ else
14
+ v
15
+ end
16
+ end
17
+ @conditions
18
+ end
19
+
20
+ def terminate? target, result
21
+ unless terminator.nil?
22
+ if terminator.is_a? Proc
23
+ terminator.call target, result
24
+ else
25
+ result == terminator
26
+ end
27
+ else
28
+ false
29
+ end
30
+ end
31
+
32
+ def run? target, inf
33
+ if cond = conditions[:if]
34
+ evaluate_if(cond, target, inf)
35
+ elsif cond = conditions[:unless]
36
+ !evaluate_if(cond, target, inf)
37
+ elsif cond = conditions[:only]
38
+ evaluate_only(cond, inf)
39
+ elsif cond = conditions[:except]
40
+ !evaluate_only(cond, inf)
41
+ else
42
+ true
43
+ end
44
+ end
45
+
46
+ def add_to_chain target, inf, &the_next
47
+ if run? target, inf
48
+ build_block target, &the_next
49
+ else
50
+ the_next
51
+ end
52
+ end
53
+
54
+ alias_method :deep_clone, :clone
55
+
56
+ protected
57
+ def evaluate_if cond, target, inf
58
+ if cond.is_a? String
59
+ target.send cond
60
+ elsif cond.is_a? Proc
61
+ cond.call target, inf
62
+ else
63
+ must_be.never_called
64
+ end
65
+ end
66
+
67
+ def evaluate_only cond, inf
68
+ method = inf[:method].to_s
69
+ if cond.is_a? String
70
+ cond == method
71
+ elsif cond.is_a? Array
72
+ cond.include? method
73
+ end
74
+ end
75
+ end
76
+
77
+ class BeforeCallback < AbstractCallback
78
+ def build_block target, &the_next
79
+ lambda do
80
+ result = if executor.string_or_symbol?
81
+ target.send executor
82
+ elsif executor.is_a? Proc
83
+ executor.call target
84
+ else
85
+ must_be.never_called
86
+ end
87
+
88
+ the_next.call unless terminate? target, result
89
+ end
90
+ end
91
+ end
92
+
93
+ class AroundCallback < AbstractCallback
94
+ def build_block target, &the_next
95
+ lambda do
96
+ if executor.string_or_symbol?
97
+ target.send executor, &the_next
98
+ elsif executor.is_a? Proc
99
+ executor.call target, the_next
100
+ else
101
+ must_be.never_called
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ class AfterCallback < AbstractCallback
108
+ def build_block target, &the_next
109
+ lambda do
110
+ result = if executor.string_or_symbol?
111
+ target.send executor
112
+ elsif executor.is_a? Proc
113
+ executor.call target
114
+ else
115
+ must_be.never_called
116
+ end
117
+
118
+ the_next.call unless terminate? target, result
119
+ end
120
+ end
121
+ end
122
+
123
+ def run_callbacks callback_name, additional_information = {}, &block
124
+ callback_name = callback_name.to_s
125
+ block.must_be.defined
126
+
127
+ callbacks = self.class.callbacks[callback_name]
128
+ chain_head = block
129
+ if callbacks and !callbacks.empty?
130
+ callbacks.reverse_each do |callback|
131
+ block = callback.add_to_chain self, additional_information, &chain_head
132
+ chain_head = block if block
133
+ end
134
+ end
135
+ chain_head.call
136
+ end
137
+
138
+ module ClassMethods
139
+ inheritable_accessor :callbacks, {}
140
+
141
+ def set_callback callback_name, type, *executor_or_options, &block
142
+ # parsing arguments
143
+ type, callback_name = type.to_s, callback_name.to_s
144
+ opt = executor_or_options.extract_options!
145
+ "You can't provide both method name and block for filter!" if block and !executor_or_options.empty?
146
+ executor = block || executor_or_options.first
147
+
148
+ type.must_be.in %w{before around after}
149
+ executor.must_be.defined
150
+
151
+ # creating callback
152
+ callback = case type
153
+ when 'before' then BeforeCallback.new
154
+ when 'around' then AroundCallback.new
155
+ when 'after' then AfterCallback.new
156
+ end
157
+
158
+ callback.executor = executor
159
+ callback.terminator = opt.delete :terminator
160
+ callback.conditions = opt
161
+
162
+ callbacks[callback_name] ||= []
163
+ callbacks[callback_name] << callback
164
+ end
165
+
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,31 @@
1
+ class Exception
2
+ class << self
3
+ attr_accessor :common_filters
4
+ end
5
+ end
6
+ Exception.common_filters = [
7
+ "/gems/haml",
8
+ "/gems/tilt",
9
+ "/gems/facets",
10
+ "/gems/rack",
11
+ "/gems/mongrel",
12
+ "/gems/rspec",
13
+ "/timeout.rb",
14
+ "/bin/spec",
15
+
16
+ "/rad/support/callbacks",
17
+ "/rad/template/template",
18
+ "/rad/template/support/tilt",
19
+
20
+ "/abstract_inteface/lib/abstract_interface/view_builder",
21
+ "/common_interface/lib/common_interface/view_helper",
22
+
23
+ # "/rad/template",
24
+ # "/rad/support",
25
+
26
+ "/monitor",
27
+ "/synchronize",
28
+ "/class_loader",
29
+ "/micon"
30
+ ]
31
+ # Exception.common_filters = []
@@ -0,0 +1,34 @@
1
+ module Rad
2
+ module Filters
3
+ inherit Callbacks
4
+
5
+ module ClassMethods
6
+ def before *args, &block
7
+ opt = args.extract_options!
8
+ if block
9
+ set_callback :action, :before, opt, &block
10
+ else
11
+ args.each{|executor| set_callback :action, :before, executor, opt}
12
+ end
13
+ end
14
+
15
+ def around *args, &block
16
+ opt = args.extract_options!
17
+ if block
18
+ set_callback :action, :around, opt, &block
19
+ else
20
+ args.each{|executor| set_callback :action, :around, executor, opt}
21
+ end
22
+ end
23
+
24
+ def after *args, &block
25
+ opt = args.extract_options!
26
+ if block
27
+ set_callback :action, :after, opt, &block
28
+ else
29
+ args.each{|executor| set_callback :action, :after, executor, opt}
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ # module Rad
2
+ # class Format < String
3
+ # def == other
4
+ # self.to_sym == other
5
+ # end
6
+ #
7
+ # def method_missing m
8
+ # m = m.to_s
9
+ # super unless m[-1..-1] == '?'
10
+ # self == m[0..-2].to_sym
11
+ # end
12
+ #
13
+ # def inspect
14
+ # self.to_sym.inspect
15
+ # end
16
+ # end
17
+ # end
@@ -0,0 +1,23 @@
1
+ #
2
+ # Problem: the Hash::slice method in ActiveSupport works a little differently than in Facets.
3
+ # And because Facets is overrides ActiveSupport version this causes problems (for example in to_json method)
4
+ # In ActiveSupport it returns :nil if there's no key in Facets it raises error.
5
+ #
6
+ # Use Case:
7
+ # hash = {:items=>[], "slug"=>"item-z8w", "name"=>"Item", "created_at"=>"2011-01-10T07:04:01Z", "dependent"=>"false", "viewers"=>["manager", "user:user1"], "updated_at"=>"2011-01-10T07:04:01Z", :icon_url=>"null", "text"=>"null", "tags"=>[], "owner_name"=>"user1", "_type"=>"Selector"}
8
+ # args = ["id", "_type", "slug", "name", "text", "tags", "dependent", "owner_name", "viewers", "created_at", "updated_at"]
9
+ # hash.slice *args
10
+ #
11
+ # Solution:
12
+ # Redefining :slice the same way as in ActiveSupport.
13
+ #
14
+ class Hash
15
+ def slice(*keep_keys)
16
+ hash = {}
17
+ keep_keys.each do |key|
18
+ # hash[key] = fetch(key)
19
+ hash[key] = self[key]
20
+ end
21
+ hash
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Rad
2
+ class << self
3
+ delegate :register, :[], :[]=, :before, :after, :before_scope, :after_scope, :activate, :include?, :clear, :delete, to: Micon
4
+ end
5
+ end
6
+
7
+ def rad &block
8
+ if block
9
+ Rad.class_eval &block
10
+ else
11
+ Rad
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Mime
2
+ class << self
3
+ def method_missing m, *args
4
+ raise "invalid usage of Mime!" unless args.empty?
5
+ self[m]
6
+ end
7
+
8
+ def [] type
9
+ type = ".#{type}" unless type =~ /^\./
10
+ Rack::Mime.mime_type(type) || raise("Unknown MIME type: #{type}")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,48 @@
1
+ class Module
2
+
3
+ #
4
+ # Dynamically enables cache in :production and disables in another environments.
5
+ # If no environment given uses non-cached version.
6
+ #
7
+ def cache_method_with_params_in_production method
8
+ method_with_cache, method_without_cache = "#{method}_with_cache", "#{method}_without_cache"
9
+ iv = "@#{method}_cache"
10
+
11
+ # raise "Method '#{method}' already defined!" if instance_methods.include?(method)
12
+ if instance_methods.include?(method_with_cache) or instance_methods.include?(method_without_cache)
13
+ warn "can't cache the :#{method} twice!"
14
+ else
15
+ alias_method method_without_cache, method
16
+
17
+ # create cached method
18
+ define_method method_with_cache do |*args|
19
+ unless results = instance_variable_get(iv)
20
+ results = Hash.new(NotDefined)
21
+ instance_variable_set iv, results
22
+ end
23
+
24
+ result = results[args]
25
+
26
+ if result.equal? NotDefined
27
+ result = send method_without_cache, *args
28
+ results[args] = result
29
+ end
30
+
31
+ result
32
+ end
33
+
34
+ # listen to environment events
35
+ rad.after :config do |config|
36
+ if config.production?
37
+ alias_method method, method_with_cache
38
+ else
39
+ alias_method method, method_without_cache
40
+ end
41
+ end
42
+
43
+ # by default uses non-cached version
44
+ # alias_method method, method_without_cache
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,53 @@
1
+ class Object
2
+ def rson?
3
+ false
4
+ end
5
+ end
6
+
7
+ [
8
+ FalseClass,
9
+ TrueClass,
10
+ Numeric,
11
+ String,
12
+ Symbol,
13
+ NilClass,
14
+ ].each do |klass|
15
+ klass.class_eval do
16
+ def to_rson options = {}
17
+ self
18
+ end
19
+
20
+ def rson?
21
+ true
22
+ end
23
+ end
24
+ end
25
+
26
+ Array.class_eval do
27
+ def to_rson options = {}
28
+ collect{|v| v.to_rson(options)}
29
+ end
30
+
31
+ def rson?
32
+ all?{|v| v.rson?}
33
+ end
34
+ end
35
+
36
+ [Hash, OpenObject].each do |klass|
37
+ klass.class_eval do
38
+ def to_rson options = {}
39
+ r = self.class.new
40
+ each do |k, v|
41
+ r[k.to_rson(options)] = v.to_rson(options)
42
+ end
43
+ r
44
+ end
45
+
46
+ def rson?
47
+ each do |k, v|
48
+ return false unless k.rson? and v.rson?
49
+ end
50
+ true
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ OpenObject.class_eval do
2
+ # support :extract_options for OpenObject
3
+ def extractable_options?; true end
4
+ end
@@ -0,0 +1,26 @@
1
+ class String
2
+ def json_escape
3
+ ERB::Util.json_escape self
4
+ end
5
+
6
+ def html_escape
7
+ # ERB::Util.html_escape self
8
+ Rack::Utils.escape_html self
9
+ end
10
+
11
+ JS_ESCAPE_MAP = {
12
+ '\\' => '\\\\',
13
+ '</' => '<\/',
14
+ "\r\n" => '\n',
15
+ "\n" => '\n',
16
+ "\r" => '\n',
17
+ '"' => '\\"',
18
+ "'" => "\\'"
19
+ }
20
+ def js_escape
21
+ gsub(/(\\|<\/|\r\n|[\n\r"'])/){JS_ESCAPE_MAP[$1]}
22
+ end
23
+
24
+ # String marks, like :format, :safe
25
+ def marks; @marks ||= OpenObject.new end
26
+ end
@@ -0,0 +1,63 @@
1
+ #
2
+ # ruby
3
+ #
4
+ raise 'ruby 1.9.2 or higher required!' unless RUBY_VERSION >= '1.9.2'
5
+
6
+ Encoding.default_external = Encoding::UTF_8
7
+ Encoding.default_internal = Encoding::UTF_8
8
+ warn " default source encoding is not UTF-8, something wroing is going on!" if __ENCODING__ != Encoding::UTF_8
9
+
10
+ # def ensure_utf8! string
11
+ # raise "invalid encoding (#{string})!" unless string.encoding == Encoding::UTF_8
12
+ # end
13
+
14
+
15
+ #
16
+ # gems
17
+ #
18
+ require 'rad_core/gems'
19
+
20
+ require 'rad/support/active_support'
21
+
22
+ require 'ruby_ext'
23
+
24
+ require 'vfs'
25
+
26
+ require 'ruby_ext/more/open_constructor'
27
+ require 'rad/support/ruby_ext_with_active_support'
28
+
29
+ require 'class_loader'
30
+
31
+ require 'micon'
32
+ require 'rad/support/micon'
33
+
34
+ require 'dictionary'
35
+
36
+ require 'thread'
37
+ require 'time'
38
+ require 'uri'
39
+ require 'json'
40
+
41
+
42
+ require 'addressable/uri'
43
+ require 'rad/support/addressable'
44
+ ::Uri = Addressable::URI
45
+
46
+ #
47
+ # support
48
+ #
49
+ require 'rad/support/hacks_and_fixes'
50
+
51
+
52
+ autoload :Nokogiri, 'nokogiri'
53
+
54
+ [
55
+ 'module',
56
+ 'buffered_logger',
57
+ 'callbacks',
58
+ 'filters',
59
+ 'mime',
60
+ 'string',
61
+ 'rson',
62
+ 'exception',
63
+ ].each{|f| require "rad/support/#{f}"}
@@ -0,0 +1,68 @@
1
+ module Tilt
2
+ #
3
+ # Include it into your template context class for :output, :capture and :concat support
4
+ #
5
+ module ContextExt
6
+ def output
7
+ _tilt_template.class.output(self)
8
+ end
9
+
10
+ def capture *args, &block
11
+ _tilt_template.class.capture self, &block
12
+ end
13
+
14
+ def concat value
15
+ _tilt_template.class.concat self, value
16
+ end
17
+ end
18
+
19
+ class Template
20
+ def self.get_output context
21
+ raise "Output variable for #{self.class} not defined!"
22
+ end
23
+
24
+ def self.capture context, &block
25
+ raise "capture not implemented for #{self.class}!"
26
+ end
27
+
28
+ def self.concat context, value
29
+ raise "concat not implemented for #{self.class}!"
30
+ end
31
+ end
32
+
33
+ class ERBTemplate
34
+ def self.get_output context
35
+ context.instance_variable_get "@output"
36
+ end
37
+
38
+ def self.capture context, &block
39
+ begin
40
+ old_output = context.instance_variable_get "@output"
41
+ old_output.must_be.defined
42
+ context.instance_variable_set "@output", ""
43
+ block.call
44
+ context.instance_variable_get "@output"
45
+ ensure
46
+ context.instance_variable_set "@output", old_output
47
+ end
48
+ end
49
+
50
+ def self.concat context, value
51
+ get_output(context) << value
52
+ end
53
+ end
54
+
55
+ class HamlTemplate
56
+ def self.get_output context
57
+ context.haml_buffer.buffer
58
+ end
59
+
60
+ def self.capture context, &block
61
+ context.capture_haml &block
62
+ end
63
+
64
+ def self.concat context, value
65
+ context.haml_concat value
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,17 @@
1
+ #
2
+ # Tilt::HamlTemplate.inspect causes error, fixin it.
3
+ #
4
+ class Tilt::HamlTemplate
5
+ def inspect
6
+ "#<Tilt::HamlTemplate:#{object_id} ...>"
7
+ end
8
+ end
9
+
10
+ #
11
+ # Tilt::HamlTemplate.inspect causes error, fixin it.
12
+ #
13
+ class Haml::Buffer
14
+ def inspect
15
+ "#<Tilt::Buffer:#{object_id} ...>"
16
+ end
17
+ end