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,19 @@
1
+ module Rad
2
+ module ControllerMicelaneousHelper
3
+ def reload_page
4
+ params = workspace.params
5
+ params.format.must_be.in 'html', 'js'
6
+
7
+ keep_flash!
8
+ if params.format == 'js'
9
+ workspace.response.set!(
10
+ status: :ok,
11
+ content_type: Mime[params.format]
12
+ )
13
+ throw :halt_render, "window.location.reload();"
14
+ else
15
+ redirect_to workspace.request.env["HTTP_REFERER"]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ module Rad
2
+ module AbstractRoutingHelper
3
+ protected
4
+ def special_url key
5
+ return nil unless (key.is_a?(Symbol) or key.is_a?(String))
6
+
7
+ if key == :back
8
+ workspace.request.env["HTTP_REFERER"] || 'javascript:history.back()'
9
+ elsif key == '#'
10
+ '#'
11
+ elsif key !~ /^[\/0-9_a-z]+$/i
12
+ key
13
+ else
14
+ nil
15
+ end
16
+ end
17
+
18
+ def keep_flash!
19
+ rad[:flash].keep! if rad.include? :flash
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ module Rad
2
+ module ControllerRoutingHelper
3
+ inherit AbstractRoutingHelper
4
+
5
+ module ClassMethods
6
+
7
+ #
8
+ # persist_params controller filters
9
+ #
10
+ def persist_params *args
11
+ if args.empty?
12
+ before :persist_params
13
+ elsif args.first.is_a? Hash
14
+ before :persist_params, args.first
15
+ else
16
+ before :persist_params, only: args.first
17
+ end
18
+ end
19
+ end
20
+
21
+ #
22
+ # redirect_to
23
+ #
24
+ def redirect_to *args
25
+ params, response = workspace.params, workspace.response
26
+ params.format.must_be.in 'html', 'js'
27
+
28
+ if url = special_url(args.first)
29
+ args.size.must_be <= 1
30
+ else
31
+ url = url_for(*args)
32
+ end
33
+ content_type = Mime[params.format]
34
+
35
+ content = if params.format == 'js'
36
+ response.set!(
37
+ status: :ok,
38
+ content_type: content_type
39
+ )
40
+
41
+ "window.location = '#{url}';"
42
+ else
43
+ response.set!(
44
+ status: :redirect,
45
+ content_type: content_type
46
+ )
47
+ response.headers['Location'] = url
48
+
49
+ %(<html><body>You are being <a href="#{url.html_escape if url}">redirected</a>.</body></html>)
50
+ end
51
+
52
+ # Flash need to know if we using redirect
53
+ keep_flash!
54
+
55
+ throw :halt_render, content
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,104 @@
1
+ module Rad
2
+ module ViewRoutingHelper
3
+ inherit AbstractRoutingHelper
4
+
5
+ #
6
+ # links
7
+ #
8
+ # def link_to *args, &block
9
+ # # parse args
10
+ # content = if block
11
+ # capture(&block)
12
+ # else
13
+ # args.shift
14
+ # end
15
+ #
16
+ # special = nil
17
+ # html_options = if args.last.is_a?(Hash)
18
+ # if args[-2].is_a?(Hash)
19
+ # args.pop
20
+ # else
21
+ # {}
22
+ # end
23
+ # else
24
+ # args << {}
25
+ # {}
26
+ # end
27
+ #
28
+ # # build url
29
+ # url = special_url(*args) || url_for(*args)
30
+ #
31
+ # # add javascript
32
+ # add_js_link_options! url, html_options
33
+ #
34
+ # tag :a, content, html_options.merge(href: url)
35
+ # end
36
+
37
+ def link_to *args, &block
38
+ # content
39
+ content = if block
40
+ capture(&block)
41
+ else
42
+ args.shift
43
+ end
44
+
45
+ # url, html_options
46
+ if args.first.is_a? String
47
+ args.size.must_be.in 1..2
48
+ url, html_options = args
49
+ html_options ||= {}
50
+ else
51
+ if url = special_url(args.first)
52
+ args.size.must_be <= 2
53
+ html_options = args[1] || {}
54
+ else
55
+ html_options = if args[-1].is_a?(Hash) and args[-1].is_a?(Hash)
56
+ args.pop
57
+ else
58
+ {}
59
+ end
60
+
61
+ args << {} unless args[-1].is_a?(Hash)
62
+ url = url_for(*args)
63
+ end
64
+ end
65
+
66
+ # add javascript
67
+ add_js_link_options! url, html_options
68
+
69
+ tag :a, content, html_options.merge(href: url)
70
+ end
71
+
72
+ protected
73
+ # TODO3 refactor to use data-remote, data-method, data-confirm
74
+ def add_js_link_options! url, html_options
75
+ confirm, remote, method = html_options.delete(:confirm), html_options.delete(:remote),
76
+ html_options.delete(:method)
77
+
78
+ remote ||= config.remote_link_formats!.include? url.marks.format
79
+
80
+ onclick = if remote
81
+ method ||= :get
82
+ %{$(this).link_to({method: '#{method}', ajax: true}); return false;}
83
+ elsif method
84
+ %{$(this).link_to({method: '#{method}'}); return false;}
85
+ else
86
+ nil
87
+ end
88
+
89
+ # if onclick and ActionController::Base.defer_static_scripts?
90
+ # html_options['class'] ||= ""
91
+ # end
92
+
93
+ if confirm
94
+ onclick = if onclick
95
+ %(if(confirm('#{confirm.js_escape}')){#{onclick}}; return false;)
96
+ else
97
+ %(return confirm('#{confirm.js_escape}');)
98
+ end
99
+ end
100
+
101
+ html_options[:onclick] = onclick if onclick
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,30 @@
1
+ require 'rad/html'
2
+ require 'rad/router'
3
+
4
+ %w(
5
+ controller_micelaneous_helper
6
+
7
+ router/abstract_routing_helper
8
+ router/view_routing_helper
9
+ router/controller_routing_helper
10
+ ).each{|f| require "rad/integration/#{f}"}
11
+
12
+
13
+ module Rad
14
+ # View helpers
15
+ [
16
+ HtmlHelper,
17
+ CoreRoutingHelper, ViewRoutingHelper
18
+ ].each do |helper|
19
+ ControllerContext.inherit helper
20
+ end
21
+
22
+ # Controller helpers
23
+ [
24
+ FlashHelper,
25
+ CoreRoutingHelper, ControllerRoutingHelper,
26
+ ControllerMicelaneousHelper
27
+ ].each do |helper|
28
+ AbstractController.inherit helper
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Rad
2
+ class Letter
3
+ inject mailer: :mailer
4
+
5
+ attr_accessor :from, :to, :subject, :body
6
+
7
+ def initialize properties
8
+ properties.each do |k, v|
9
+ send "#{k}=", v
10
+ end
11
+ end
12
+
13
+ def validate!
14
+ from || raise("letter :from not specified!")
15
+ to || raise("letter :to not specified!")
16
+ subject || raise("letter :subject not specified!")
17
+ body || raise("letter :body not specified!")
18
+ end
19
+
20
+ def deliver
21
+ validate!
22
+ mailer.deliver self
23
+ end
24
+
25
+ def to_hash
26
+ {from: from, to: to, subject: subject, body: body}
27
+ end
28
+ alias_method :to_h, :to_hash
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ module Rad
2
+ module MailController
3
+ inherit AbstractController
4
+
5
+ attr_accessor :from, :to, :subject, :body
6
+
7
+ module ClassMethods
8
+ protected
9
+ inject conveyors: :conveyors
10
+
11
+ def method_missing m, *args, &block
12
+ mail_controller = self.new
13
+ if mail_controller.respond_to? m
14
+ build_letter mail_controller, m, *args
15
+ else
16
+ super
17
+ end
18
+ end
19
+
20
+ def build_letter mail_controller, m, *args
21
+ conveyors.mail.must_be.present
22
+ workspace = conveyors.mail.call(
23
+ controller: mail_controller,
24
+ method_name: m,
25
+ arguments: args
26
+ )
27
+ workspace.letter.must_be.present
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ module Rad
2
+ class Mailer
3
+ inject logger: :logger, config: :config
4
+
5
+ def deliver letter
6
+ mail = Mail.new letter.to_h
7
+ if config.development?
8
+ logger.info " Delivering mail #{letter.to_h.inspect}"
9
+ else
10
+ logger.info " Delivering mail '#{letter.subject}'"
11
+ end
12
+ mail.deliver!
13
+ end
14
+ end
15
+ end
16
+
17
+ rad.after :environment do
18
+ if rad.config.development?
19
+ Mail.defaults do
20
+ delivery_method :test
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ module Rad
2
+ module Processors
3
+ class LetterBuilder < Processor
4
+ def call
5
+ # prepare
6
+ controller = workspace.controller.must_be.present
7
+ raise "The controller #{controller} must be a Rad::MailController!" unless controller.is_a? Rad::MailController
8
+ action = workspace.action = workspace.method_name
9
+
10
+ # call
11
+ content = catch :halt_render do
12
+ controller.run_callbacks :action, method: action do
13
+ # call controller
14
+ controller.send action, *workspace.arguments
15
+ # render view
16
+ controller.render action: action
17
+ end
18
+ end
19
+
20
+ controller.body = content unless content.blank?
21
+
22
+ # letter
23
+ workspace.letter = ::Rad::Letter.new(
24
+ from: controller.from,
25
+ to: controller.to,
26
+ subject: controller.subject,
27
+ body: controller.body
28
+ )
29
+ workspace.letter.validate!
30
+
31
+ next_processor.call if next_processor
32
+ end
33
+
34
+ end
35
+ end
36
+ end
data/lib/rad/mail.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'mail'
2
+
3
+ require 'rad/controller'
4
+ require 'rad/template'
5
+
6
+ %w(
7
+ mailer
8
+ letter
9
+ mail_controller
10
+ processors/letter_builder
11
+ ).each{|f| require "rad/mail/#{f}"}
12
+
13
+ rad.register :mailer, depends_on: :environment do
14
+ Rad::Mailer.new
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'rad/router'
2
+ require 'rad/mail'
3
+
4
+ #
5
+ # Conveyors
6
+ #
7
+ module Rad::Processors
8
+ rad.after :environment do
9
+ rad.conveyors.mail do |mail|
10
+ # mail
11
+ mail.use LetterBuilder
12
+
13
+ mail.build!
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,68 @@
1
+ require 'rad/profiles/web_require'
2
+
3
+ #
4
+ # Routes
5
+ #
6
+ rad.after :environment do
7
+ rad.register :router, depends_on: :environment do
8
+ Rad::Router.new(:class, [
9
+ [:alias_router, Rad::AliasRouter.new],
10
+ [:restful_router, Rad::RestfulRouter.new],
11
+ [:simple_router, Rad::SimpleRouter.new]
12
+ ])
13
+ end
14
+ end
15
+
16
+
17
+ #
18
+ # Conveyors
19
+ #
20
+ module Rad::Processors
21
+ rad.after :environment do
22
+ rad.conveyors.web do |web|
23
+ # conveyor
24
+ web.use ConveyorLogger
25
+
26
+ # http
27
+ web.use HttpWriter
28
+ web.use PrepareParams
29
+ web.use EvaluateFormat
30
+ web.use HTTPLogger
31
+
32
+ # html
33
+ # web.use ScopedParams
34
+ web.use PrepareFlash
35
+
36
+ # controller
37
+ web.use ControllerErrorHandling
38
+
39
+ # router
40
+ web.use Router, :class, :method_name
41
+
42
+ # controller
43
+ web.use ControllerLogger
44
+ web.use ControllerCaller
45
+
46
+ web.build!
47
+ end
48
+ end
49
+ end
50
+
51
+
52
+ #
53
+ # Rack
54
+ #
55
+ Rad.initialize_rack do |builder|
56
+ config = rad.config
57
+
58
+ # CommonLogger, ShowExceptions, Lint
59
+ builder.use Rack::Lint if config.development?
60
+ builder.use Rad::StaticFiles, config.public_dir! if config.static? and config.public_dir? and config.development?
61
+
62
+ # use Rack::Session::Cookie, key: 'rack.session', domain: 'foo.com', path: '/', expire_after: 2592000, secret: 'change_me'
63
+ builder.use Rack::Session::Cookie, config.session.to_hash if config.session?
64
+
65
+ # builder.use Rack::CommonLogger
66
+ builder.use Rack::MethodOverride
67
+ # builder.use ShowExceptions if config.show_exceptions?
68
+ end
@@ -0,0 +1,5 @@
1
+ require 'rad/router'
2
+ require 'rad/http'
3
+ require 'rad/controller'
4
+ require 'rad/html'
5
+ require 'rad/integration'
@@ -0,0 +1,54 @@
1
+ module Rad
2
+ module Processors
3
+ class RemoteCaller < Processor
4
+ # TODO2 :remote isn't registered with rad[
5
+ inject remote: :remote
6
+
7
+ def initialize next_processor, result_variable = 'content'
8
+ super(next_processor)
9
+ @result_variable = result_variable
10
+ end
11
+
12
+ def call
13
+ return next_processor.call unless workspace.class?
14
+
15
+ # prepare
16
+ klass = workspace.class
17
+ raise "The remote class #{klass} must be a Rad::Remote!" unless klass.is? Rad::Remote
18
+ workspace.remote_object = klass.new
19
+ method = workspace.method_name
20
+
21
+ # call
22
+ begin
23
+ result = workspace.remote_object.run_callbacks :action, method: method do
24
+ workspace.remote_object.send method
25
+ end
26
+
27
+ ensure_correct_result! result
28
+ workspace.remote_result = result
29
+
30
+ next_processor.call
31
+
32
+ # write JSON as a result if format is JSON and no one else filled it
33
+ if workspace[@result_variable].blank?
34
+ workspace[@result_variable] = workspace.remote_result.to_json
35
+ end
36
+ rescue StandardError => e
37
+ raise e if !workspace.params.format == 'json' or config.test?
38
+
39
+ workspace[@result_variable] = {error: e.message}.to_json
40
+
41
+ logger.error e
42
+ logger.info "\n"
43
+ end
44
+ end
45
+
46
+ private
47
+ def ensure_correct_result! result
48
+ unless result.rson?
49
+ raise "You can't use object of type '#{result.class}' as Remote's return value!"
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ module Rad
2
+ module Processors
3
+ class RemoteLogger < Processor
4
+ def call
5
+ next_processor.call
6
+
7
+ if (klass = workspace.class) and (method = workspace.method_name)
8
+ logger.info " Processing #{klass.name}.#{method} with #{workspace.params.inspect}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Rad
2
+ module Remote
3
+ inherit Filters
4
+
5
+ inject(
6
+ workspace: :workspace,
7
+ logger: :logger,
8
+ config: :config
9
+ )
10
+
11
+ def params
12
+ workspace.params
13
+ end
14
+ end
15
+ end
data/lib/rad/remote.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'rad/conveyor'
2
+
3
+ [
4
+ 'remote',
5
+ 'processors/remote_logger',
6
+ 'processors/remote_caller',
7
+ ].each{|f| require "rad/remote/#{f}"}
8
+
9
+ Rad::Config::DEFAULTS['default_method'] ||= 'call'
@@ -0,0 +1,25 @@
1
+ module Rad
2
+ module Routes
3
+ class Configurator
4
+ inject router: :router
5
+
6
+ def initialize router
7
+ @router = router
8
+ end
9
+
10
+ def persistent_params *args
11
+ args.each{|v| router.persistent_params << v}
12
+ end
13
+
14
+ delegate :skip, to: :router
15
+
16
+ class << self
17
+ inject router: :router
18
+
19
+ def routes &block
20
+ block.call Configurator.new(router)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,41 @@
1
+ module Rad
2
+ module CoreRoutingHelper
3
+ inject router: :router
4
+
5
+ delegate :url_for, :url_for_path, :persist_params, :persist_params?, :dont_persist_params, to: :router
6
+
7
+ def default_path options = {}
8
+ url_for_path config.default_path!, options.merge(url_root: false)
9
+ end
10
+
11
+ def return_to_path options = {}
12
+ dont_persist_params do
13
+ path = params[:_return_to] || workspace.request.session['return_to'] || config.default_path!
14
+ url_for_path path, options.merge(url_root: false)
15
+ end
16
+ end
17
+
18
+ def parse_routing_arguments *args
19
+ params = args.extract_options!
20
+ raise "invalid usage!" unless args.size <= 1
21
+ if args.size == 1
22
+ raise "duplicate :id pameter!" if params.include?(:id) or params.include?('id')
23
+ params[:id] = args.first.to_param
24
+ end
25
+ params
26
+ end
27
+
28
+ protected
29
+ def method_missing m, *args, &block
30
+ m = m.to_s
31
+ if m =~ /_path$/
32
+ params = parse_routing_arguments(*args)
33
+ klass, method = router.encode_method m
34
+
35
+ url_for klass, method, params
36
+ else
37
+ super m.to_sym, *args, &block
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,12 @@
1
+ module Rad
2
+ class DefaultFormatProcessor
3
+ def add_format path, format
4
+ path << ".#{format}"
5
+ path
6
+ end
7
+
8
+ def remove_format path
9
+ path.sub(/\.[^\.]+$/, '')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ module Rad
2
+ module Processors
3
+ class Router < Processor
4
+ inject router: :router
5
+
6
+ def initialize next_processor, class_variable = :class, method_variable = :method
7
+ super(next_processor)
8
+ @class_variable, @method_variable = class_variable, method_variable
9
+ end
10
+
11
+ def call
12
+ skip = catch :skip do
13
+ if workspace[@class_variable].blank? or workspace[@method_variable].blank?
14
+ klass, method, params = router.decode workspace.path, workspace.params
15
+ workspace[@class_variable], workspace[@method_variable], workspace.params = klass, method, params
16
+ end
17
+
18
+ nil
19
+ end
20
+
21
+ if skip
22
+ logger.info " Skipping '#{workspace.path}'"
23
+ else
24
+ next_processor.call
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end