rad_core 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (330) hide show
  1. data/Rakefile +4 -3
  2. data/lib/components/config.rb +6 -0
  3. data/lib/components/controller.rb +5 -0
  4. data/lib/components/controller.yml +3 -0
  5. data/lib/components/conveyors.rb +7 -0
  6. data/lib/components/environment.rb +5 -0
  7. data/lib/components/environment.yml +3 -0
  8. data/lib/components/flash.rb +5 -0
  9. data/lib/components/html.rb +4 -0
  10. data/lib/components/html.yml +3 -0
  11. data/lib/components/http.rb +6 -0
  12. data/lib/components/http.yml +13 -0
  13. data/lib/components/logger.rb +5 -0
  14. data/lib/components/mailer.rb +9 -0
  15. data/lib/components/remote.rb +4 -0
  16. data/lib/components/router.rb +13 -0
  17. data/lib/components/router.yml +2 -0
  18. data/lib/components/template.rb +8 -0
  19. data/lib/components/template.yml +1 -0
  20. data/lib/components/web.rb +8 -0
  21. data/lib/components/workspace.rb +1 -0
  22. data/lib/rad/{support → _support}/active_support/locales/en/actionpack.yml +0 -0
  23. data/lib/rad/{support → _support}/active_support/locales/en/activesupport.yml +0 -0
  24. data/lib/rad/_support/active_support/locales/ru/actionview.yml +162 -0
  25. data/lib/rad/_support/active_support/locales/ru/activesupport.yml +16 -0
  26. data/lib/rad/_support/active_support/locales/ru/datetime.yml +49 -0
  27. data/lib/rad/{support → _support}/active_support/micelaneous.rb +0 -0
  28. data/lib/rad/{support → _support}/active_support/time.rb +0 -0
  29. data/lib/rad/{support → _support}/active_support.rb +14 -2
  30. data/lib/rad/{support → _support}/addressable.rb +0 -0
  31. data/lib/rad/_support/callbacks.rb +166 -0
  32. data/lib/rad/_support/class_loader.rb +9 -0
  33. data/lib/rad/_support/encoding.rb +3 -0
  34. data/lib/rad/_support/exception.rb +45 -0
  35. data/lib/rad/_support/extensions.rb +20 -0
  36. data/lib/rad/_support/filters.rb +32 -0
  37. data/lib/rad/{support → _support}/hacks_and_fixes.rb +0 -0
  38. data/lib/rad/{support → _support}/mime.rb +6 -0
  39. data/lib/rad/{support → _support}/module.rb +7 -9
  40. data/lib/rad/_support/require.rb +62 -0
  41. data/lib/rad/{support → _support}/rson.rb +0 -0
  42. data/lib/rad/{support → _support}/ruby_ext_with_active_support.rb +0 -0
  43. data/lib/rad/{support → _support}/string.rb +9 -1
  44. data/lib/rad/controller/_abstract/micelaneous.rb +27 -0
  45. data/lib/rad/controller/_abstract/render.rb +159 -0
  46. data/lib/rad/controller/_abstract/responder.rb +13 -0
  47. data/lib/rad/controller/_abstract.rb +37 -0
  48. data/lib/rad/controller/_context.rb +15 -0
  49. data/lib/rad/controller/_http.rb +50 -0
  50. data/lib/rad/controller/_require.rb +19 -0
  51. data/lib/rad/controller/abstract.rb +1 -0
  52. data/lib/rad/controller/context.rb +1 -0
  53. data/lib/rad/controller/http.rb +1 -0
  54. data/lib/rad/controller/processors/controller_caller.rb +22 -24
  55. data/lib/rad/controller/processors/controller_error_handling.rb +46 -48
  56. data/lib/rad/controller/processors/controller_logger.rb +7 -9
  57. data/lib/rad/controller.rb +1 -28
  58. data/lib/rad/conveyors/_conveyor.rb +73 -0
  59. data/lib/rad/conveyors/_conveyors.rb +19 -0
  60. data/lib/rad/conveyors/_params.rb +10 -0
  61. data/lib/rad/conveyors/_processor.rb +13 -0
  62. data/lib/rad/conveyors/_require.rb +10 -0
  63. data/lib/rad/conveyors/_workspace.rb +34 -0
  64. data/lib/rad/conveyors/params.rb +1 -0
  65. data/lib/rad/conveyors/processor.rb +1 -0
  66. data/lib/rad/conveyors/processors/conveyor_logger.rb +23 -0
  67. data/lib/rad/conveyors/workspace.rb +1 -0
  68. data/lib/rad/conveyors.rb +1 -0
  69. data/lib/rad/core_web/_controller_micelaneous_helper.rb +17 -0
  70. data/lib/rad/core_web/_require.rb +25 -0
  71. data/lib/rad/core_web/_router/abstract_routing_helper.rb +20 -0
  72. data/lib/rad/core_web/_router/controller_routing_helper.rb +56 -0
  73. data/lib/rad/core_web/_router/view_routing_helper.rb +57 -0
  74. data/lib/rad/environment/_config.rb +27 -0
  75. data/lib/rad/environment/_environment.rb +17 -0
  76. data/lib/rad/environment/_files_helper.rb +55 -0
  77. data/lib/rad/environment/_logger.rb +53 -0
  78. data/lib/rad/environment/_require.rb +24 -0
  79. data/lib/rad/environment/config.rb +1 -111
  80. data/lib/rad/environment.rb +1 -55
  81. data/lib/{rad_core → rad}/gems.rb +2 -3
  82. data/lib/rad/html/_flash.rb +40 -0
  83. data/lib/rad/html/_helpers/basic_html_helper.rb +72 -0
  84. data/lib/rad/html/_helpers/flash_helper.rb +3 -0
  85. data/lib/rad/html/_helpers/form_helper.rb +114 -0
  86. data/lib/rad/html/_helpers/html_helper.rb +3 -0
  87. data/lib/rad/html/_helpers/javascript_helper.rb +27 -0
  88. data/lib/rad/html/_helpers/model_helper.rb +143 -0
  89. data/lib/rad/html/_require.rb +15 -0
  90. data/lib/rad/html/processors/prepare_flash.rb +22 -23
  91. data/lib/rad/html/processors/scoped_params.rb +18 -21
  92. data/lib/rad/html.rb +1 -26
  93. data/lib/rad/http/_http.rb +11 -0
  94. data/lib/rad/http/_http_adapter.rb +44 -0
  95. data/lib/rad/http/_request.rb +50 -0
  96. data/lib/rad/http/_require.rb +33 -0
  97. data/lib/rad/http/_response.rb +84 -0
  98. data/lib/rad/http/{support → _support}/rack/fixes.rb +0 -0
  99. data/lib/rad/http/_support/rack/rack_adapter.rb +57 -0
  100. data/lib/rad/http/processors/evaluate_format.rb +16 -19
  101. data/lib/rad/http/processors/http_logger.rb +10 -12
  102. data/lib/rad/http/processors/http_writer.rb +24 -26
  103. data/lib/rad/http/processors/prepare_params.rb +19 -18
  104. data/lib/rad/http/request.rb +1 -0
  105. data/lib/rad/http/response.rb +1 -0
  106. data/lib/rad/http.rb +1 -48
  107. data/lib/rad/mailer/_letter.rb +28 -0
  108. data/lib/rad/mailer/_mailer.rb +13 -0
  109. data/lib/rad/mailer/_mailer_controller.rb +38 -0
  110. data/lib/rad/mailer/_require.rb +7 -0
  111. data/lib/rad/mailer/mailer_controller.rb +1 -0
  112. data/lib/rad/mailer/processors/letter_builder.rb +34 -0
  113. data/lib/rad/mailer.rb +1 -0
  114. data/lib/rad/profiles/mailer.rb +5 -0
  115. data/lib/rad/profiles/web.rb +29 -52
  116. data/lib/rad/remote/_remote_controller.rb +9 -0
  117. data/lib/rad/remote/_require.rb +6 -0
  118. data/lib/rad/remote/processors/remote_caller.rb +44 -46
  119. data/lib/rad/remote/processors/remote_logger.rb +8 -10
  120. data/lib/rad/remote/remote_controller.rb +1 -0
  121. data/lib/rad/remote.rb +1 -9
  122. data/lib/rad/router/_abstract_router.rb +50 -0
  123. data/lib/rad/router/_alias_router.rb +124 -0
  124. data/lib/rad/router/_basic_router.rb +72 -0
  125. data/lib/rad/router/_configurator.rb +19 -0
  126. data/lib/rad/router/_core_routing_helper.rb +39 -0
  127. data/lib/rad/router/_default_format_processor.rb +10 -0
  128. data/lib/rad/router/_object_router.rb +184 -0
  129. data/lib/rad/router/_require.rb +31 -0
  130. data/lib/rad/router/_restful_router.rb +124 -0
  131. data/lib/rad/router/_router.rb +294 -0
  132. data/lib/rad/router/_simple_router.rb +21 -0
  133. data/lib/rad/router/abstract_router.rb +1 -0
  134. data/lib/rad/router/alias_router.rb +1 -0
  135. data/lib/rad/router/configurator.rb +1 -0
  136. data/lib/rad/router/micelaneous_router.rb +1 -0
  137. data/lib/rad/router/object_router.rb +1 -0
  138. data/lib/rad/router/processors/router.rb +23 -0
  139. data/lib/rad/router/restful_router.rb +1 -0
  140. data/lib/rad/{html/include_into_controller.rb → router/simple_router.rb} +0 -0
  141. data/lib/rad/router.rb +1 -29
  142. data/lib/rad/spec/controller.rb +20 -11
  143. data/lib/rad/spec/environment.rb +22 -38
  144. data/lib/rad/spec/http.rb +13 -86
  145. data/lib/rad/spec/http_controller.rb +105 -0
  146. data/lib/rad/spec/mailer.rb +27 -0
  147. data/lib/rad/spec/remote.rb +2 -2
  148. data/lib/rad/spec/router.rb +9 -11
  149. data/lib/rad/spec/template.rb +8 -2
  150. data/lib/rad/spec/xhtml.rb +0 -2
  151. data/lib/rad/spec.rb +4 -2
  152. data/lib/rad/template/_context.rb +92 -0
  153. data/lib/rad/template/_relative_path_resolver.rb +8 -0
  154. data/lib/rad/template/_require.rb +15 -0
  155. data/lib/rad/template/{support → _support}/tilt.rb +0 -0
  156. data/lib/rad/template/{support → _support}/tilt_fixes.rb +0 -0
  157. data/lib/rad/template/_template.rb +175 -0
  158. data/lib/rad/template/template_context.rb +1 -62
  159. data/lib/rad/template.rb +1 -25
  160. data/lib/rad.rb +8 -0
  161. data/readme.md +40 -12
  162. data/spec/controller/{abstract_controller_spec → abstract_spec}/views/OperationsOrderSpec/action.erb +0 -0
  163. data/spec/controller/{abstract_controller_spec → abstract_spec}/views/ViewVariablesSpec/action.erb +0 -0
  164. data/spec/controller/abstract_spec.rb +126 -0
  165. data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/NamespaceSpec/ClassSpec}/show.erb +0 -0
  166. data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/item_spec}/actions.erb +0 -0
  167. data/spec/controller/{controller_context_spec/views/NamespaceSpec/ClassSpec → context_spec/views/item_spec}/show.erb +0 -0
  168. data/spec/controller/{controller_context_spec/views/ItemSpec → context_spec/views/item_spec}/update.erb +0 -0
  169. data/spec/controller/{controller_context_spec → context_spec}/views/namespace_spec/class_spec/update.erb +0 -0
  170. data/spec/controller/{controller_context_spec/views/PageSpec → context_spec/views/page_spec}/actions.erb +0 -0
  171. data/spec/controller/{controller_context_spec/views/PageSpec → context_spec/views/page_spec}/show.erb +0 -0
  172. data/spec/controller/context_spec.rb +123 -0
  173. data/spec/controller/error_handling_spec.rb +21 -27
  174. data/spec/controller/{controller_helper_spec → helper_spec}/views/HelperMethodSpec/action.erb +0 -0
  175. data/spec/controller/{controller_helper_spec → helper_spec}/views/HelperSpec/action.erb +0 -0
  176. data/spec/controller/{controller_helper_spec.rb → helper_spec.rb} +7 -13
  177. data/spec/controller/{http_controller_spec.rb → http_spec.rb} +17 -23
  178. data/spec/controller/{controller_render_spec/views/AlreadyRenderedSpec → render_spec/views/already_rendered_spec}/action.erb +0 -0
  179. data/spec/controller/{controller_render_spec/views/AlreadyRenderedSpec → render_spec/views/already_rendered_spec}/custom_template.erb +0 -0
  180. data/spec/controller/{controller_render_spec/views/AnotherActionSpec → render_spec/views/another_action_spec}/another_action.erb +0 -0
  181. data/spec/controller/{controller_render_spec/views/AnotherLayout → render_spec/views/another_layout}/action.erb +0 -0
  182. data/spec/controller/{controller_render_spec/views/ForbidPartialAsActionSpec → render_spec/views/forbid_partial_as_action_spec}/_action.erb +0 -0
  183. data/spec/controller/{controller_render_spec/views/FormatSpec → render_spec/views/format_spec}/action.html.erb +0 -0
  184. data/spec/controller/{controller_render_spec/views/FormatSpec → render_spec/views/format_spec}/action.js.erb +0 -0
  185. data/spec/controller/{controller_render_spec/views/LayoutFiltersSpec → render_spec/views/layout_filters_spec}/action_with_layout.erb +0 -0
  186. data/spec/controller/{controller_render_spec/views/LayoutFiltersSpec → render_spec/views/layout_filters_spec}/action_without_layout.erb +0 -0
  187. data/spec/controller/{controller_render_spec/views/LayoutSpec → render_spec/views/layout_spec}/action.erb +0 -0
  188. data/spec/controller/{controller_render_spec → render_spec}/views/layouts/admin.erb +0 -0
  189. data/spec/controller/{controller_render_spec → render_spec}/views/layouts/app.html.erb +0 -0
  190. data/spec/controller/{controller_render_spec → render_spec}/views/layouts/app.js.erb +0 -0
  191. data/spec/controller/{controller_render_spec/views/MultipleActions → render_spec/views/multiple_actions}/actions.haml +0 -0
  192. data/spec/controller/render_spec/views/relative_spec/a/form.erb +1 -0
  193. data/spec/controller/render_spec/views/relative_spec/a/show.erb +1 -0
  194. data/spec/controller/render_spec/views/relative_spec/b/form.erb +1 -0
  195. data/spec/controller/{controller_render_spec → render_spec}/views/some_template.erb +0 -0
  196. data/spec/controller/{controller_render_spec → render_spec}/views/standalone.html.erb +0 -0
  197. data/spec/controller/{controller_render_spec.rb → render_spec.rb} +37 -27
  198. data/spec/{conveyor/conveyor_spec.rb → conveyors/conveyors_spec.rb} +36 -14
  199. data/spec/environment/config_spec.rb +13 -21
  200. data/spec/environment/environment_spec.rb +14 -41
  201. data/spec/environment/logger_spec.rb +4 -13
  202. data/spec/environment/minimal_app_spec/app.rb +1 -1
  203. data/spec/environment/minimal_app_spec.rb +12 -14
  204. data/spec/environment/standard_app_spec/app/lib/app/init.rb +1 -1
  205. data/spec/environment/standard_app_spec/plugin_a/lib/plugin_a/init.rb +1 -1
  206. data/spec/environment/standard_app_spec.rb +17 -25
  207. data/spec/html/basic_html_helper_spec.rb +7 -4
  208. data/spec/html/form_helper_spec.rb +5 -5
  209. data/spec/html/javascript_helper_spec.rb +9 -5
  210. data/spec/html/model_helper_spec.rb +9 -6
  211. data/spec/html/scoped_params_spec.rb +2 -2
  212. data/spec/html/spec_helper.rb +16 -24
  213. data/spec/http/http_spec.rb +14 -35
  214. data/spec/http/micelaneous_spec.rb +3 -3
  215. data/spec/{mail → mailer}/mail_controller_spec/views/body_template_spec/signup.erb +0 -0
  216. data/spec/{mail → mailer}/mail_controller_spec.rb +36 -12
  217. data/spec/mailer/spec_helper.rb +5 -0
  218. data/spec/remote/remote_spec.rb +23 -8
  219. data/spec/router/alias_router_spec.rb +29 -30
  220. data/spec/router/basic_router_spec.rb +44 -0
  221. data/spec/router/configurator_spec.rb +9 -6
  222. data/spec/router/integration_spec.rb +10 -7
  223. data/spec/router/object_router_spec.rb +186 -0
  224. data/spec/router/persistent_params_spec.rb +4 -4
  225. data/spec/router/restful_router_spec.rb +61 -53
  226. data/spec/router/{basic_spec.rb → router_spec.rb} +26 -23
  227. data/spec/router/routing_helper_spec.rb +5 -6
  228. data/spec/spec_helper.rb +4 -0
  229. data/spec/support/callbacks_spec.rb +1 -1
  230. data/spec/support/filters_spec.rb +2 -2
  231. data/spec/support/spec_helper.rb +1 -1
  232. data/spec/template/template_spec/views/format_for_partials/dialog.js.erb +1 -1
  233. data/spec/template/template_spec/views/nested/format/a.erb +1 -1
  234. data/spec/template/template_spec/views/nested/format/b.js.erb +1 -0
  235. data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -1
  236. data/spec/template/template_spec.rb +62 -48
  237. data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -1
  238. data/spec/template/tilt_spec/views/concat_and_capture.haml +1 -1
  239. data/spec/template/tilt_spec.rb +17 -19
  240. data/spec/{integration → web}/basic_spec/views/smoke_test_spec/action.erb +0 -0
  241. data/spec/{integration → web}/basic_spec.rb +31 -12
  242. data/spec/{integration → web}/controller_routing_helper_spec.rb +13 -11
  243. data/spec/{integration → web}/flash_spec.rb +57 -42
  244. data/spec/{integration → web}/spec_helper_spec.rb +11 -10
  245. data/spec/{integration → web}/view_routing_helper_spec.rb +44 -36
  246. metadata +338 -318
  247. data/lib/rad/controller/abstract_controller/micelaneous.rb +0 -31
  248. data/lib/rad/controller/abstract_controller/render.rb +0 -160
  249. data/lib/rad/controller/abstract_controller/responder.rb +0 -17
  250. data/lib/rad/controller/abstract_controller.rb +0 -64
  251. data/lib/rad/controller/controller_context.rb +0 -15
  252. data/lib/rad/controller/http_controller.rb +0 -48
  253. data/lib/rad/conveyor/conveyor.rb +0 -74
  254. data/lib/rad/conveyor/conveyors.rb +0 -20
  255. data/lib/rad/conveyor/params.rb +0 -14
  256. data/lib/rad/conveyor/processor.rb +0 -68
  257. data/lib/rad/conveyor/processors/conveyor_logger.rb +0 -25
  258. data/lib/rad/conveyor/workspace.rb +0 -36
  259. data/lib/rad/conveyor.rb +0 -29
  260. data/lib/rad/environment/dependency_resolver.rb +0 -107
  261. data/lib/rad/environment/environment.rb +0 -29
  262. data/lib/rad/environment/files_helper.rb +0 -55
  263. data/lib/rad/environment/logger.rb +0 -21
  264. data/lib/rad/html/flash.rb +0 -42
  265. data/lib/rad/html/helpers/basic_html_helper.rb +0 -83
  266. data/lib/rad/html/helpers/flash_helper.rb +0 -5
  267. data/lib/rad/html/helpers/form_helper.rb +0 -115
  268. data/lib/rad/html/helpers/html_helper.rb +0 -5
  269. data/lib/rad/html/helpers/javascript_helper.rb +0 -18
  270. data/lib/rad/html/helpers/model_helper.rb +0 -135
  271. data/lib/rad/http/http.rb +0 -21
  272. data/lib/rad/http/http_adapter.rb +0 -36
  273. data/lib/rad/http/middleware/static_files.rb +0 -21
  274. data/lib/rad/http/support/rack/rack_adapter.rb +0 -67
  275. data/lib/rad/http/support/rack/request.rb +0 -42
  276. data/lib/rad/http/support/rack/response.rb +0 -86
  277. data/lib/rad/integration/controller_micelaneous_helper.rb +0 -19
  278. data/lib/rad/integration/router/abstract_routing_helper.rb +0 -22
  279. data/lib/rad/integration/router/controller_routing_helper.rb +0 -58
  280. data/lib/rad/integration/router/view_routing_helper.rb +0 -104
  281. data/lib/rad/integration.rb +0 -30
  282. data/lib/rad/mail/letter.rb +0 -30
  283. data/lib/rad/mail/mail_controller.rb +0 -31
  284. data/lib/rad/mail/mailer.rb +0 -23
  285. data/lib/rad/mail/processors/letter_builder.rb +0 -36
  286. data/lib/rad/mail.rb +0 -15
  287. data/lib/rad/profiles/mail.rb +0 -16
  288. data/lib/rad/profiles/web_require.rb +0 -5
  289. data/lib/rad/remote/remote.rb +0 -15
  290. data/lib/rad/router/core/configurator.rb +0 -25
  291. data/lib/rad/router/core/core_routing_helper.rb +0 -41
  292. data/lib/rad/router/core/default_format_processor.rb +0 -12
  293. data/lib/rad/router/core/processors/router.rb +0 -29
  294. data/lib/rad/router/core/router.rb +0 -271
  295. data/lib/rad/router/core/simple_router.rb +0 -23
  296. data/lib/rad/router/routers/abstract_router.rb +0 -62
  297. data/lib/rad/router/routers/alias_router.rb +0 -113
  298. data/lib/rad/router/routers/restful_router.rb +0 -113
  299. data/lib/rad/spec/mail.rb +0 -31
  300. data/lib/rad/spec/view.rb +0 -10
  301. data/lib/rad/support/buffered_logger.rb +0 -44
  302. data/lib/rad/support/callbacks.rb +0 -168
  303. data/lib/rad/support/exception.rb +0 -31
  304. data/lib/rad/support/filters.rb +0 -34
  305. data/lib/rad/support/format.rb +0 -17
  306. data/lib/rad/support/micon.rb +0 -13
  307. data/lib/rad/support.rb +0 -63
  308. data/lib/rad/template/template.rb +0 -250
  309. data/spec/controller/abstract_controller_spec.rb +0 -132
  310. data/spec/controller/controller_context_spec.rb +0 -123
  311. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/action.erb +0 -1
  312. data/spec/controller/controller_render_spec/views/rem ExplicitRenderSpec/another_action.erb +0 -1
  313. data/spec/controller/spec_helper.rb +0 -19
  314. data/spec/conveyor/spec_helper.rb +0 -3
  315. data/spec/environment/config_spec/config.default.yml +0 -3
  316. data/spec/environment/config_spec/config.development.yml +0 -3
  317. data/spec/environment/config_spec/config.yml +0 -5
  318. data/spec/environment/spec_helper.rb +0 -1
  319. data/spec/http/http_spec/app/lib/app/init.rb +0 -10
  320. data/spec/http/http_spec/app/runtime/public/emptygit +0 -0
  321. data/spec/http/http_spec/plugin_a/lib/plugin_a/init.rb +0 -0
  322. data/spec/http/http_spec/plugin_b/lib/plugin_b/init.rb +0 -5
  323. data/spec/http/http_spec/plugin_b/static/emptygit +0 -0
  324. data/spec/http/spec_helper.rb +0 -5
  325. data/spec/integration/spec_helper.rb +0 -5
  326. data/spec/mail/spec_helper.rb +0 -7
  327. data/spec/remote/spec_helper.rb +0 -17
  328. data/spec/router/spec_helper.rb +0 -20
  329. data/spec/template/spec_helper.rb +0 -6
  330. data/spec/template/template_spec/views/nested/format/b.erb +0 -1
@@ -1,41 +0,0 @@
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
@@ -1,12 +0,0 @@
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
@@ -1,29 +0,0 @@
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
@@ -1,271 +0,0 @@
1
- module Rad
2
- class Router
3
- inject(
4
- config: :config,
5
- workspace: :workspace
6
- )
7
-
8
- attr_reader :routes, :format_processor
9
-
10
- def initialize class_variable, routes = {default_router: SimpleRouter.new}, format_processor = DefaultFormatProcessor.new
11
- @class_variable, @format_processor = class_variable, format_processor
12
- @routes = Dictionary.new
13
- routes.each do |k, v|
14
- k.must_be.present
15
- v.must_be.present
16
- v.must.respond_to(:decode)
17
- v.must.respond_to(:encode)
18
-
19
- @routes[k] = v
20
- end
21
- end
22
-
23
- def skip path_regexp=nil
24
- @skip ||= []
25
- if path_regexp
26
- path_regexp.must_be.a Regexp
27
- @skip << path_regexp unless @skip.include? path_regexp
28
- else
29
- @skip
30
- end
31
- end
32
-
33
- def url_for *args
34
- if args.first.is_a?(Class)
35
- args.size.must_be.in 2..3
36
- klass, method, options = args
37
- url_for_class(klass, method, (options || {}))
38
- else
39
- first = args.first.to_s
40
- if first !~ /^\//
41
- args.size.must_be.in 1..2
42
- method, options = args
43
- url_for_class(nil, method, (options || {}))
44
- else
45
- args.size.must_be.in 1..2
46
- path, options = args
47
- url_for_path(path, (options || {}))
48
- end
49
- end
50
- end
51
-
52
- def decode path, params
53
- path.first.must == '/'
54
- # params = params.to_openobject
55
-
56
- throw :skip, true if skip.any?{|path_regexp| path_regexp =~ path}
57
-
58
- path, format = format_processor.remove_format path if format_processor
59
-
60
- result = nil
61
- routes.each do |name, route|
62
- result = route.decode path, params
63
- break if result
64
- end
65
-
66
- raise "no route for '#{safe_workspace.path}' request!" unless result
67
-
68
- klass, method, params = result
69
- method ||= config.default_method
70
- params.must_be.defined
71
- method.must_be.a Symbol
72
-
73
- raise "Invalid route! No method '#{method}' for #{klass}!" unless klass.instance_methods.include? method
74
- raise "Invalid route! You try to call protected method '#{method}' for '#{path}'!" unless klass.public_instance_methods.include? method
75
-
76
- return klass, method, params
77
- end
78
-
79
- def encode klass, method, params = {}
80
- klass.must_be.defined
81
- method.must_be.a Symbol
82
- params = params.clone
83
- # method, params = method, params.to_openobject
84
-
85
- format = params.delete(:format)
86
-
87
- raise "Invalid route! No method '#{method}' for #{klass}!" unless klass.method_defined? method
88
- raise "Invalid route! You try to call protected method '#{method}' for '#{klass}'!" unless klass.method_defined? method
89
-
90
- inject_persistent_params! params
91
-
92
- result = nil
93
- routes.each do |name, route|
94
- result = route.encode klass, method, params
95
- break if result
96
- end
97
-
98
- raise "no route for '#{klass}.#{method}'!" unless result
99
-
100
- path, params = result
101
- path.must_be.defined
102
- params.must_be.defined
103
-
104
- path = format_processor.add_format path, format if format_processor and format
105
-
106
- return path, params
107
- end
108
-
109
- def encode_method route_method
110
- # method = method
111
- route_method.must_be.present
112
-
113
- result = nil
114
- routes.each do |name, route|
115
- result = route.respond_to :encode_method, route_method
116
- break if result
117
- end
118
-
119
- raise "no route for '#{route_method}' route method!" unless result
120
-
121
- klass, method = result
122
- klass.must_be.defined
123
- method.must_be.defined
124
- return klass, method
125
- end
126
- cache_method_with_params_in_production :encode_method
127
-
128
- def persist_params &block
129
- if block
130
- before = safe_workspace.persist_params?
131
- begin
132
- safe_workspace[:persist_params] = true
133
- block.call
134
- ensure
135
- safe_workspace.delete :persist_params unless before
136
- end
137
- else
138
- safe_workspace[:persist_params] = true
139
- end
140
- end
141
-
142
- def dont_persist_params &block
143
- if block
144
- before = safe_workspace.persist_params?
145
- begin
146
- safe_workspace.delete :persist_params
147
- block.call
148
- ensure
149
- safe_workspace[:persist_params] = true if before
150
- end
151
- else
152
- safe_workspace.delete :persist_params
153
- end
154
- end
155
-
156
- def persist_params?
157
- safe_workspace.persist_params?
158
- end
159
-
160
- def persistent_params; @persistent_params ||= [] end
161
-
162
- def url_for_path path, params
163
- # params = params.to_openobject
164
-
165
- # special params
166
- url = if params.include? :url_root
167
- (params.delete(:url_root) || "") + path
168
- else
169
- config.url_root! + path
170
- end
171
- host, port = params.delete(:host), params.delete(:port)
172
- format = params.delete(:format)
173
-
174
- # json
175
- params = {json: params.to_json} if params.delete :as_json #and !params.empty?
176
-
177
- # format
178
- if format
179
- params[:format] = format
180
- url.marks.format = format.to_s
181
- end
182
-
183
- # Delete 'nil' parameters
184
- to_delete = []
185
- params.each{|k, v| to_delete << k if v.nil?}
186
- to_delete.each{|k| params.delete k}
187
-
188
- # build url
189
- delimiter = path.include?('?') ? '&' : '?'
190
- url << "#{delimiter}#{params.to_query}" unless params.empty?
191
-
192
- if host.blank?
193
- url
194
- else
195
- %{http://#{host}#{":#{port}" unless port.blank?}#{url}}
196
- end
197
- end
198
-
199
- def url_for_class klass, method, params
200
- klass ||= current_class
201
- # params = params.to_openobject
202
-
203
- # special params
204
- format = params[:format]
205
-
206
- path, params = encode klass, method, params
207
- url = url_for_path path, params
208
-
209
- url.marks.format = format.to_s if format
210
-
211
- url
212
- end
213
-
214
- protected
215
- # sometimes we need access to routes outside of conveyor :cycle,
216
- # for example in spec routing helpers, in that case we just ignore workspace and it's variables
217
- def safe_workspace
218
- if Micon.active? :cycle
219
- workspace
220
- else
221
- Workspace.new
222
- end
223
- end
224
-
225
- def current_class; safe_workspace[@class_variable] end
226
-
227
- DONOT_PERSIST = [:_, :_method]
228
-
229
- def inject_persistent_params! params
230
- persist = params.delete(:persist)
231
-
232
- # global persistent params
233
- unless cached_global_persistend_params = safe_workspace.cached_global_persistend_params
234
- cached_global_persistend_params, workspace_params = {}, safe_workspace.params
235
- if workspace_params
236
- persistent_params.collect!{|k| k}
237
-
238
- workspace_params.each do |k, v|
239
- cached_global_persistend_params[k] = v if persistent_params.include?(k)
240
- end
241
-
242
- safe_workspace.cached_global_persistend_params = cached_global_persistend_params
243
- end
244
- end
245
-
246
- cached_global_persistend_params.each do |k, v|
247
- params[k] = v unless params.include? k
248
- end
249
-
250
- # underscored persistent params
251
- if persist_params?
252
- unless cached_persistend_params = safe_workspace.cached_persistend_params
253
- cached_persistend_params, workspace_params = {}, safe_workspace.params
254
-
255
- if workspace_params
256
- workspace_params.each do |k, v|
257
- cached_persistend_params[k] = v if (k =~ /^_/) and !DONOT_PERSIST.include?(k)
258
- end
259
-
260
- safe_workspace.cached_persistend_params = cached_persistend_params
261
- end
262
- end
263
-
264
- cached_persistend_params.each do |k, v|
265
- params[k] = v unless params.include? k
266
- end
267
- end
268
- end
269
-
270
- end
271
- end
@@ -1,23 +0,0 @@
1
- module Rad
2
- class SimpleRouter
3
- inject logger: :logger
4
-
5
- def encode klass, method, params
6
- path = "/#{klass.name.underscore}/#{method}"
7
- return path, params
8
- end
9
-
10
- def decode path, params
11
- parts = path[1..-1].split '/'
12
- if parts.size >= 2
13
- method = parts.pop.to_sym
14
-
15
- class_path = parts.join('/')
16
- class_name = class_path.camelize
17
- klass = class_name.constantize
18
-
19
- return klass, method, params
20
- end
21
- end
22
- end
23
- end
@@ -1,62 +0,0 @@
1
- module Rad
2
- module AbstractRouter
3
-
4
- protected
5
- def parse_url_root options
6
- url_root = options.delete(:url_root)
7
- url_root.must =~ /^\/.+/ if url_root
8
- url_root
9
- end
10
-
11
- def parse_prefix options
12
- prefix = options.delete(:prefix)
13
- if prefix
14
- prefix.must_not_be.empty
15
- prefix.must_be.a Array
16
- prefix = prefix.collect do |item|
17
- item = Array(item)
18
- item.size.must_be.in 1..2
19
- item << item.first.to_s if item.size < 2
20
- item.first.must_be.a Symbol
21
- item.last.must_be.a String
22
- item
23
- end
24
- end
25
- prefix
26
- end
27
-
28
- def encode_prefix_params! path, params, meta
29
- if prefix = meta[:prefix]
30
- parts = []
31
- prefix.each do |name, als|
32
- parts << als
33
- parts << (params.delete(name) || raise("not provided :#{name} prefix!")) # TODO 3 add url_escape
34
- end
35
- "/#{parts.join('/')}#{path}"
36
- else
37
- path
38
- end
39
- end
40
-
41
- def encode_url_root! path, meta
42
- if url_root = meta[:url_root]
43
- "#{url_root}#{path}"
44
- else
45
- path
46
- end
47
- end
48
-
49
- def decode_prefix_params! parts, params, meta
50
- if prefix = meta[:prefix]
51
- prefix.reverse.each do |name, als|
52
- params[name] = parts.pop || raise("not provided :#{name} prefix!")
53
- raise("incorrect url for :#{name} prefix!") unless parts.pop == als
54
- end
55
- end
56
- end
57
-
58
- def decode_url_root! parts, meta
59
- raise "invalid :url_root!" if meta[:url_root] and meta[:url_root] != "/#{parts.join('/')}"
60
- end
61
- end
62
- end
@@ -1,113 +0,0 @@
1
- module Rad
2
- class AliasRouter
3
- include AbstractRouter
4
-
5
- class TreeHash < Hash
6
- attr_accessor :meta
7
- end
8
-
9
- def initialize
10
- @route_methods, @paths, @classes = {}, TreeHash.new, {}
11
- end
12
-
13
- def add als, options = {}
14
- # parsing options
15
- # als, options = als.to_s, options.to_openobject
16
- als = als.to_s
17
- als.must =~ /^\//
18
- klass = options.delete(:class) || raise("no class!")
19
- method = options.delete(:method) || raise("no method!")
20
- method = method.must_be.a Symbol
21
- url_root = parse_url_root options
22
- prefix = parse_prefix options
23
- raise "unknown options :#{options.to_h.keys.join(': ')}!" unless options.empty?
24
- raise "you can't use '/' alias with :url_root!" if als == '/' and url_root
25
-
26
- # logic
27
- meta = {
28
- class: klass,
29
- method: method,
30
- path: als,
31
- url_root: url_root,
32
- prefix: prefix
33
- }
34
-
35
- route_methods["#{als[1..-1]}_path"] = meta
36
-
37
- (classes[klass] ||= {})[method] = meta
38
-
39
-
40
- parts = als[1..-1].split('/')
41
- parts << '' if parts.empty?
42
-
43
- tree_iterator = paths
44
- parts.reverse.each do |part|
45
- tree_iterator = (tree_iterator[part] ||= TreeHash.new)
46
- raise "alias '#{als}' conflicted with another alias!" if tree_iterator.meta
47
- end
48
- tree_iterator.meta = meta
49
- end
50
-
51
- def encode klass, method, params
52
- if meta = classes[klass].try(:[], method)
53
- path = meta[:path]
54
-
55
- path = encode_prefix_params! path, params, meta
56
- path = encode_url_root! path, meta
57
-
58
- return path, params
59
- else
60
- nil
61
- end
62
- end
63
-
64
- def decode path, params
65
- parts = path[1..-1].split('/')
66
- parts << '' if parts.empty?
67
-
68
- tree_iterator = paths
69
-
70
- # checking for first part
71
- part = parts.pop
72
- tree_iterator = tree_iterator[part]
73
- return nil unless tree_iterator
74
-
75
- # checking for exact match
76
- while part = parts.pop
77
- tmp = tree_iterator[part]
78
- unless tmp
79
- parts << part
80
- break
81
- end
82
- tree_iterator = tmp
83
- end
84
-
85
- meta = tree_iterator.meta
86
-
87
- decode_prefix_params! parts, params, meta
88
- decode_url_root! parts, meta
89
-
90
- return meta[:class], meta[:method], params
91
- end
92
-
93
- def encode_method route_method
94
- if meta = route_methods[route_method]
95
- return meta[:class], meta[:method]
96
- else
97
- nil
98
- end
99
- end
100
-
101
- protected
102
- attr_accessor :paths, :route_methods, :classes
103
- end
104
- end
105
-
106
-
107
- Rad::Routes::Configurator.class_eval do
108
- def alias *args, &block
109
- alias_router = @router.routes[:alias_router]
110
- raise "There's no AliasRouter (use config to add it)!" unless alias_router
111
- alias_router.add *args, &block
112
- end
113
- end
@@ -1,113 +0,0 @@
1
- module Rad
2
- class RestfulRouter
3
- include AbstractRouter
4
-
5
- def initialize
6
- @resources, @classes = {}, {}
7
- end
8
-
9
- def add resource, options = {}
10
- # parsing options
11
- resource = resource.to_s
12
- resource.must_not =~ /\//
13
- raise "resource should be in plural form!" unless resource.pluralize == resource
14
- klass = options.delete(:class) || raise("no class!")
15
- url_root = parse_url_root options
16
- prefix = parse_prefix options
17
- raise "unknown options :#{options.to_h.keys.join(': ')}!" unless options.empty?
18
-
19
- # logic
20
- meta = {
21
- class: klass,
22
- resource: resource,
23
- url_root: url_root,
24
- prefix: prefix
25
- }
26
-
27
- resources.must_not.include(resource.pluralize)
28
- classes.must_not.include(klass)
29
- resources[resource.pluralize] = meta
30
- resources[resource.singularize] = meta
31
- classes[klass] = meta
32
- end
33
-
34
- def encode klass, method, params
35
- meta = classes[klass]
36
- return nil unless meta
37
-
38
- path = if id = params.delete(:id)
39
- "/#{meta[:resource]}/#{id}/#{method}"
40
- else
41
- "/#{meta[:resource]}/#{method}"
42
- end
43
-
44
- path = encode_prefix_params! path, params, meta
45
- path = encode_url_root! path, meta
46
-
47
- [path, params]
48
- end
49
-
50
- def decode path, params
51
- decode_as_object_resource(path, params) || decode_as_static_resource(path, params)
52
- end
53
-
54
- def encode_method route_method
55
- token = route_method.sub(/_path$/, '')
56
-
57
- resources.each do |name, meta|
58
- if i = token.rindex(name)
59
- route_method.size == i + name.size and route_method[(i-1)..(i-1)] == '_'
60
- return meta[:class], route_method[0..(i-2)].to_sym
61
- end
62
- end
63
-
64
- return nil
65
- end
66
-
67
- protected
68
- attr_accessor :resources, :classes
69
-
70
- def decode_as_object_resource path, params
71
- parts = path[1..-1].split('/')
72
- return nil unless parts.size >= 3
73
-
74
- method, id, klass = parts.pop.to_sym, parts.pop, parts.pop
75
- meta = resources[klass]
76
- return nil unless meta
77
-
78
- return nil if parts.size != (meta[:url_root] ? 1 : 0) + (meta[:prefix] ? meta[:prefix].size * 2 : 0)
79
-
80
- decode_prefix_params! parts, params, meta
81
- decode_url_root! parts, meta
82
-
83
- params[:id] = id
84
-
85
- return meta[:class], method, params
86
- end
87
-
88
- def decode_as_static_resource path, params
89
- parts = path[1..-1].split('/')
90
- return nil unless parts.size >= 2
91
-
92
- method, klass = parts.pop.to_sym, parts.pop
93
- meta = resources[klass]
94
- return nil unless meta
95
-
96
- return nil if parts.size != (meta[:url_root] ? 1 : 0) + (meta[:prefix] ? meta[:prefix].size * 2 : 0)
97
-
98
- decode_prefix_params! parts, params, meta
99
- decode_url_root! parts, meta
100
-
101
- return meta[:class], method, params
102
- end
103
- end
104
- end
105
-
106
-
107
- Rad::Routes::Configurator.class_eval do
108
- def resource *args, &block
109
- restful_router = @router.routes[:restful_router]
110
- raise "There's no RestfulRouter (use config to add it)!" unless restful_router
111
- restful_router.add *args, &block
112
- end
113
- end
data/lib/rad/spec/mail.rb DELETED
@@ -1,31 +0,0 @@
1
- module Rad
2
- module RSpecHelper
3
- def sent_letters
4
- Rad::RSpecHelper.sent_letters
5
- end
6
-
7
- class << self
8
- attr_accessor :sent_letters
9
- end
10
- end
11
- end
12
-
13
- rspec do
14
- def self.with_mail
15
- Rad::Mailer.class_eval do
16
- def deliver letter
17
- Rad::RSpecHelper.sent_letters << letter
18
- end
19
- end
20
-
21
- Mail.defaults do
22
- delivery_method :test
23
- end
24
-
25
- rspec.include Rad::RSpecHelper
26
-
27
- before :each do
28
- Rad::RSpecHelper.sent_letters = []
29
- end
30
- end
31
- end