crystal 0.0.10 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (419) hide show
  1. data/Rakefile +25 -0
  2. data/lib/crystal/controller/abstract_controller/micelaneous.rb +31 -0
  3. data/lib/crystal/controller/abstract_controller/render.rb +133 -0
  4. data/lib/crystal/controller/abstract_controller/responder.rb +17 -0
  5. data/lib/crystal/controller/abstract_controller.rb +60 -0
  6. data/lib/crystal/controller/controller_context.rb +7 -0
  7. data/lib/crystal/controller/http_controller.rb +43 -0
  8. data/lib/crystal/controller/processors/controller_caller.rb +40 -0
  9. data/lib/crystal/controller/processors/controller_error_handling.rb +53 -0
  10. data/lib/crystal/controller/processors/controller_logger.rb +13 -0
  11. data/lib/crystal/controller.rb +28 -0
  12. data/lib/crystal/conveyor/conveyor.rb +74 -0
  13. data/lib/crystal/conveyor/conveyors.rb +20 -0
  14. data/lib/crystal/conveyor/params.rb +22 -0
  15. data/lib/crystal/conveyor/processor.rb +68 -0
  16. data/lib/crystal/conveyor/processors/conveyor_logger.rb +24 -0
  17. data/lib/crystal/conveyor/workspace.rb +36 -0
  18. data/lib/crystal/conveyor.rb +29 -0
  19. data/lib/crystal/environment/config.rb +118 -0
  20. data/lib/crystal/environment/dependency_resolver.rb +107 -0
  21. data/lib/crystal/environment/environment.rb +5 -0
  22. data/lib/crystal/environment/files_helper.rb +42 -0
  23. data/lib/crystal/environment/logger.rb +21 -0
  24. data/lib/crystal/environment.rb +52 -0
  25. data/lib/crystal/html/controller_helpers/controller_url_helper.rb +52 -0
  26. data/lib/crystal/html/controller_helpers/flash_helper.rb +5 -0
  27. data/lib/crystal/html/flash.rb +40 -0
  28. data/lib/crystal/html/include_into_controller.rb +24 -0
  29. data/lib/crystal/html/processors/prepare_flash.rb +26 -0
  30. data/lib/crystal/html/processors/scoped_params.rb +30 -0
  31. data/lib/crystal/html/view_helpers/basic_html_helper.rb +83 -0
  32. data/lib/crystal/html/view_helpers/form_helper.rb +104 -0
  33. data/lib/crystal/html/view_helpers/javascript_helper.rb +18 -0
  34. data/lib/crystal/html/view_helpers/model_helper.rb +119 -0
  35. data/lib/crystal/html/view_helpers/view_url_helper.rb +66 -0
  36. data/lib/crystal/html.rb +28 -0
  37. data/lib/crystal/http/http.rb +21 -0
  38. data/lib/crystal/http/http_adapter.rb +30 -0
  39. data/lib/crystal/http/middleware/static_files.rb +20 -0
  40. data/lib/crystal/http/processors/evaluate_format.rb +22 -0
  41. data/lib/crystal/http/processors/http_logger.rb +15 -0
  42. data/lib/crystal/http/processors/http_writer.rb +48 -0
  43. data/lib/crystal/http/processors/prepare_params.rb +24 -0
  44. data/lib/crystal/http/rack_config.rb +15 -0
  45. data/lib/crystal/http/support/rack/rack_adapter.rb +65 -0
  46. data/lib/crystal/http/support/rack/request.rb +12 -0
  47. data/lib/crystal/http/support/rack/response.rb +39 -0
  48. data/lib/crystal/http.rb +47 -0
  49. data/lib/crystal/mailer/mail.rb +7 -0
  50. data/lib/crystal/mailer.rb +13 -0
  51. data/lib/crystal/profiles/web.rb +69 -0
  52. data/lib/crystal/profiles/web_require.rb +5 -0
  53. data/lib/crystal/remote/processors/remote_caller.rb +54 -0
  54. data/lib/crystal/remote/processors/remote_logger.rb +13 -0
  55. data/lib/crystal/remote/remote.rb +15 -0
  56. data/lib/crystal/remote.rb +9 -0
  57. data/lib/crystal/router/configurator.rb +23 -0
  58. data/lib/crystal/router/default_format_processor.rb +12 -0
  59. data/lib/crystal/router/default_router.rb +23 -0
  60. data/lib/crystal/router/named_router.rb +63 -0
  61. data/lib/crystal/router/processors/router.rb +22 -0
  62. data/lib/crystal/router/router.rb +218 -0
  63. data/lib/crystal/router/routing_helper.rb +17 -0
  64. data/lib/crystal/router.rb +19 -0
  65. data/lib/crystal/spec/controller.rb +15 -0
  66. data/lib/crystal/spec/environment.rb +41 -0
  67. data/lib/crystal/spec/http.rb +67 -0
  68. data/lib/crystal/spec/mail.rb +20 -0
  69. data/lib/crystal/spec/remote.rb +9 -0
  70. data/lib/crystal/spec/view.rb +10 -0
  71. data/lib/crystal/spec/xhtml.rb +33 -0
  72. data/lib/crystal/spec.rb +8 -0
  73. data/lib/crystal/support/active_support/micelaneous.rb +2 -0
  74. data/lib/crystal/support/active_support.rb +37 -28
  75. data/lib/crystal/support/addressable.rb +45 -0
  76. data/lib/crystal/support/buffered_logger.rb +38 -0
  77. data/lib/crystal/support/callbacks.rb +155 -0
  78. data/lib/crystal/support/exception.rb +21 -0
  79. data/lib/crystal/support/filters.rb +34 -0
  80. data/lib/crystal/support/format.rb +9 -0
  81. data/lib/crystal/support/gems.rb +12 -0
  82. data/lib/crystal/support/micon.rb +16 -0
  83. data/lib/crystal/support/mime.rb +11 -0
  84. data/lib/crystal/support/module.rb +44 -0
  85. data/lib/crystal/support/rson.rb +53 -0
  86. data/lib/crystal/support/ruby_ext_with_active_support.rb +4 -0
  87. data/lib/crystal/support/safe_hash.rb +135 -0
  88. data/lib/crystal/support/string.rb +26 -0
  89. data/lib/crystal/support.rb +42 -0
  90. data/lib/crystal/template/support/tilt.rb +68 -0
  91. data/lib/crystal/template/template.rb +244 -0
  92. data/lib/crystal/template/template_context.rb +57 -0
  93. data/lib/crystal/template.rb +21 -0
  94. data/lib/views/crystal_default_templates/development/error.html.erb +11 -0
  95. data/lib/views/crystal_default_templates/development/error.js.erb +1 -0
  96. data/readme.md +9 -5
  97. data/spec/_mailer/basic_spec.rb +110 -0
  98. data/spec/_mailer/helper.rb +6 -0
  99. data/spec/controller/abstract_controller_spec/views/OperationsOrderSpec/action.erb +1 -0
  100. data/spec/controller/abstract_controller_spec/views/ViewVariablesSpec/action.erb +10 -0
  101. data/spec/controller/abstract_controller_spec.rb +138 -0
  102. data/spec/controller/controller_context_spec/views/ItemSpec/actions.erb +4 -0
  103. data/spec/controller/controller_context_spec/views/ItemSpec/show.erb +0 -0
  104. data/spec/controller/controller_context_spec/views/ItemSpec/update.erb +0 -0
  105. data/spec/controller/controller_context_spec/views/NamespaceSpec/ClassSpec/show.erb +0 -0
  106. data/spec/controller/controller_context_spec/views/PageSpec/actions.erb +3 -0
  107. data/spec/controller/controller_context_spec/views/PageSpec/show.erb +0 -0
  108. data/spec/controller/controller_context_spec/views/namespace_spec/class_spec/update.erb +0 -0
  109. data/spec/controller/controller_context_spec.rb +123 -0
  110. data/spec/controller/controller_helper_spec/views/HelperMethodSpec/action.erb +1 -0
  111. data/spec/controller/controller_helper_spec/views/HelperSpec/action.erb +1 -0
  112. data/spec/controller/controller_helper_spec.rb +58 -0
  113. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/action.erb +1 -0
  114. data/spec/controller/controller_render_spec/views/AlreadyRenderedSpec/custom_template.erb +1 -0
  115. data/spec/controller/controller_render_spec/views/AnotherActionSpec/another_action.erb +1 -0
  116. data/spec/controller/controller_render_spec/views/AnotherLayout/action.erb +1 -0
  117. data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/action.erb +1 -0
  118. data/spec/controller/controller_render_spec/views/ExplicitRenderSpec/another_action.erb +1 -0
  119. data/spec/controller/controller_render_spec/views/ForbidPartialAsActionSpec/_action.erb +1 -0
  120. data/spec/controller/controller_render_spec/views/FormatSpec/action.html.erb +1 -0
  121. data/spec/controller/controller_render_spec/views/FormatSpec/action.js.erb +1 -0
  122. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_with_layout.erb +1 -0
  123. data/spec/controller/controller_render_spec/views/LayoutFiltersSpec/action_without_layout.erb +1 -0
  124. data/spec/controller/controller_render_spec/views/LayoutSpec/action.erb +1 -0
  125. data/spec/controller/controller_render_spec/views/layouts/admin.erb +1 -0
  126. data/spec/controller/controller_render_spec/views/layouts/app.html.erb +1 -0
  127. data/spec/controller/controller_render_spec/views/layouts/app.js.erb +1 -0
  128. data/spec/controller/controller_render_spec/views/some_template.erb +1 -0
  129. data/spec/controller/controller_render_spec/views/standalone.html.erb +1 -0
  130. data/spec/controller/controller_render_spec.rb +192 -0
  131. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/a.erb +1 -0
  132. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/b.erb +1 -0
  133. data/spec/controller/error_handling_spec/views/diferrent_error_handling_spec/c.erb +1 -0
  134. data/spec/controller/error_handling_spec.rb +97 -0
  135. data/spec/controller/helper.rb +21 -0
  136. data/spec/controller/http_controller_spec.rb +90 -0
  137. data/spec/conveyor/conveyor_spec.rb +124 -0
  138. data/spec/conveyor/helper.rb +8 -0
  139. data/spec/environment/_dependency_resolver_spec.rb +50 -0
  140. data/spec/environment/environment_spec/app/app_plugin/config/ec_layout +1 -0
  141. data/spec/environment/environment_spec/app/app_plugin/ec_some_file +1 -0
  142. data/spec/environment/environment_spec/app/config/config.test.yml +1 -0
  143. data/spec/environment/environment_spec/app/config/config.yml +2 -0
  144. data/spec/environment/environment_spec/gem_plugin/config/ec_layout +1 -0
  145. data/spec/environment/environment_spec.rb +87 -0
  146. data/spec/environment/helper.rb +4 -0
  147. data/spec/environment/logger_spec.rb +20 -0
  148. data/spec/environment/minimal_app_spec/app.rb +3 -0
  149. data/spec/environment/minimal_app_spec.rb +29 -0
  150. data/spec/environment/standard_app_spec.rb +65 -0
  151. data/spec/environment/standard_app_spec_data/config/init.rb +18 -0
  152. data/spec/environment/standard_app_spec_data/plugin_a/plugin_a.rb +7 -0
  153. data/spec/html/basic_html_helper_spec.rb +30 -0
  154. data/spec/html/flash_spec.rb +185 -0
  155. data/spec/html/form_helper_spec.rb +57 -0
  156. data/spec/html/helper.rb +31 -0
  157. data/spec/html/javascript_helper_spec.rb +16 -0
  158. data/spec/html/model_helper_spec.rb +66 -0
  159. data/spec/html/scoped_params_spec.rb +18 -0
  160. data/spec/html/url_helper_spec.rb +152 -0
  161. data/spec/http/helper.rb +9 -0
  162. data/spec/http/http_spec.rb +57 -0
  163. data/spec/http/http_spec_data/config/init.rb +7 -0
  164. data/spec/http/http_spec_data/plugin_b/plugin_b.rb +6 -0
  165. data/spec/integration/basic_spec/views/smoke_test_spec/action.erb +1 -0
  166. data/spec/integration/basic_spec.rb +83 -0
  167. data/spec/integration/helper.rb +10 -0
  168. data/spec/remote/helper.rb +20 -0
  169. data/spec/remote/remote_spec.rb +76 -0
  170. data/spec/router/basic_spec.rb +131 -0
  171. data/spec/router/configurator_spec.rb +30 -0
  172. data/spec/router/helper.rb +23 -0
  173. data/spec/router/integration_spec.rb +43 -0
  174. data/spec/support/callbacks_spec.rb +155 -0
  175. data/spec/support/filters_spec.rb +61 -0
  176. data/spec/support/helper.rb +7 -0
  177. data/spec/support/safe_hash_spec.rb +84 -0
  178. data/spec/template/helper.rb +8 -0
  179. data/spec/template/template_spec/file.erb +1 -0
  180. data/spec/template/template_spec/views/basic/custom_context.erb +1 -0
  181. data/spec/template/template_spec/views/basic/extension.erb +1 -0
  182. data/spec/template/template_spec/views/basic/general.html.erb +5 -0
  183. data/spec/template/template_spec/views/basic/non_existing_format.html.erb +0 -0
  184. data/spec/template/template_spec/views/format/format.erb +1 -0
  185. data/spec/template/template_spec/views/format/format.html.erb +1 -0
  186. data/spec/template/template_spec/views/format/format.js.erb +1 -0
  187. data/spec/template/template_spec/views/layout/basic/content.erb +1 -0
  188. data/spec/template/template_spec/views/layout/basic/layout.erb +1 -0
  189. data/spec/template/template_spec/views/layout/content_for/content.erb +3 -0
  190. data/spec/template/template_spec/views/layout/content_for/layout.erb +3 -0
  191. data/spec/template/template_spec/views/layout/format/content.html.erb +1 -0
  192. data/spec/template/template_spec/views/layout/format/content.js.erb +1 -0
  193. data/spec/template/template_spec/views/layout/format/layout.html.erb +1 -0
  194. data/spec/template/template_spec/views/layout/format/layout.js.erb +1 -0
  195. data/spec/template/template_spec/views/layout/nested_yield/a.erb +1 -0
  196. data/spec/template/template_spec/views/layout/nested_yield/layout.erb +1 -0
  197. data/spec/template/template_spec/views/layout/nested_yield/layout_b.erb +1 -0
  198. data/spec/template/template_spec/views/layout/same_context/a.erb +1 -0
  199. data/spec/template/template_spec/views/layout/same_context/b.erb +1 -0
  200. data/spec/template/template_spec/views/layout/same_context/layout.erb +1 -0
  201. data/spec/template/template_spec/views/nested/format/a.erb +1 -0
  202. data/spec/template/template_spec/views/nested/format/b.erb +1 -0
  203. data/spec/template/template_spec/views/nested/relative/a.erb +1 -0
  204. data/spec/template/template_spec/views/nested/relative/b.erb +1 -0
  205. data/spec/template/template_spec/views/nested/relative/c.erb +1 -0
  206. data/spec/template/template_spec/views/nested/shared/c.erb +1 -0
  207. data/spec/template/template_spec/views/nesting_format/_dialog.html.erb +1 -0
  208. data/spec/template/template_spec/views/nesting_format/_form.html.erb +1 -0
  209. data/spec/template/template_spec/views/nesting_format/dialog.js.erb +1 -0
  210. data/spec/template/template_spec/views/other/template.erb +1 -0
  211. data/spec/template/template_spec/views/prefixes/_underscored.erb +1 -0
  212. data/spec/template/template_spec/views/prefixes/without_prefix.erb +1 -0
  213. data/spec/template/template_spec.rb +190 -0
  214. data/spec/template/tilt_spec/views/concat_and_capture.erb +1 -0
  215. data/spec/template/tilt_spec/views/concat_and_capture.haml +3 -0
  216. data/spec/template/tilt_spec/views/errors.erb +3 -0
  217. data/spec/template/tilt_spec/views/errors.haml +3 -0
  218. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_erb.erb +4 -0
  219. data/spec/template/tilt_spec/views/mixed_templates/broken_erb_concat_haml.haml +1 -0
  220. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_erb.erb +1 -0
  221. data/spec/template/tilt_spec/views/mixed_templates/broken_haml_concat_haml.haml +2 -0
  222. data/spec/template/tilt_spec/views/nested_capture_and_concat.haml +3 -0
  223. data/spec/template/tilt_spec/views/ugly.haml +3 -0
  224. data/spec/template/tilt_spec/views/yield.erb +1 -0
  225. data/spec/template/tilt_spec.rb +97 -0
  226. metadata +345 -205
  227. data/.git/COMMIT_EDITMSG +0 -1
  228. data/.git/FETCH_HEAD +0 -1
  229. data/.git/HEAD +0 -1
  230. data/.git/ORIG_HEAD +0 -1
  231. data/.git/config +0 -12
  232. data/.git/description +0 -1
  233. data/.git/hooks/applypatch-msg.sample +0 -15
  234. data/.git/hooks/commit-msg.sample +0 -24
  235. data/.git/hooks/post-commit.sample +0 -8
  236. data/.git/hooks/post-receive.sample +0 -15
  237. data/.git/hooks/post-update.sample +0 -8
  238. data/.git/hooks/pre-applypatch.sample +0 -14
  239. data/.git/hooks/pre-commit.sample +0 -46
  240. data/.git/hooks/pre-rebase.sample +0 -169
  241. data/.git/hooks/prepare-commit-msg.sample +0 -36
  242. data/.git/hooks/update.sample +0 -128
  243. data/.git/index +0 -0
  244. data/.git/info/exclude +0 -6
  245. data/.git/logs/HEAD +0 -21
  246. data/.git/logs/refs/heads/master +0 -21
  247. data/.git/logs/refs/remotes/origin/master +0 -19
  248. data/.git/objects/00/c26dc781c8997ed2bfa61f03b323466a3860d1 +0 -0
  249. data/.git/objects/04/03ee94b34a5760c46616cd13c317e69cb90d56 +0 -0
  250. data/.git/objects/04/6f30de5fd9fe81fd558c58091c38a57b6be727 +0 -0
  251. data/.git/objects/05/78d884154d5a74143844a4373121e8d9fa6abd +0 -0
  252. data/.git/objects/06/8c594d16214cbee3ad8e9f4eae9c78f6a9ddf1 +0 -3
  253. data/.git/objects/08/8b766b31125f7c4ae34a8fc50b23842cd3d329 +0 -0
  254. data/.git/objects/09/66c6b45bacaae9282463b9b4c0ce8488bbcee5 +0 -2
  255. data/.git/objects/09/a40c814899fcdadc2bd5665e892a7db26a3677 +0 -2
  256. data/.git/objects/0c/eac702c4548a2748f50793ea5108cfd4937568 +0 -0
  257. data/.git/objects/0d/03131f9fbc3e2fb1f8f9b616ac273d05f3a7f5 +0 -0
  258. data/.git/objects/0e/50f691a65b41ba9e7df9d6738ff9f333089b34 +0 -0
  259. data/.git/objects/11/72a42d5efc6cb442f877bef4427321a216990a +0 -1
  260. data/.git/objects/12/3a3f6e3c82bb8df88e242085deef1aa150039c +0 -0
  261. data/.git/objects/14/6253750089fd522535155630344c8ff2a60830 +0 -0
  262. data/.git/objects/15/3d7375df50713dd61152db972492405e5475e0 +0 -0
  263. data/.git/objects/15/f5669d470665c6bd28b5ab7b65431e199c36e9 +0 -0
  264. data/.git/objects/1b/d4b59edc03948d15434e9eb882c769ab779ba6 +0 -0
  265. data/.git/objects/1c/abe7402ff0ea8bbf7a63cee7a61dec7578dae9 +0 -0
  266. data/.git/objects/20/fb67fdc8a63361a3d317d3c873462fd5a338d0 +0 -0
  267. data/.git/objects/21/4bb3dd51d883243c744ee3d668e09a0c1cc293 +0 -0
  268. data/.git/objects/23/9d84cdccd97f779f60c08f88ab635f4c236e87 +0 -0
  269. data/.git/objects/27/510002446b0a1405c1e7f14634c28407dffa76 +0 -0
  270. data/.git/objects/28/4db1992e17d1d5fc9280dc4e79799958a9cbac +0 -0
  271. data/.git/objects/28/69649fc37831734b82493fe980f9dc65dfd935 +0 -0
  272. data/.git/objects/28/a3d1b3c79d0e59b8359ecd75e4ec0d62f60468 +0 -2
  273. data/.git/objects/29/53f684e47235f5b14b4beb0b0bb61c8e520dd8 +0 -0
  274. data/.git/objects/2c/b339709e1fb005a3e3006e76558d2e45333008 +0 -0
  275. data/.git/objects/2d/077a401db466ea0b1f062eac15293879293439 +0 -0
  276. data/.git/objects/2e/2f635a49a032cb37d69af4862181bb37bfa0fa +0 -0
  277. data/.git/objects/31/0f7c970910eced673e858c197f6ee418e97545 +0 -0
  278. data/.git/objects/34/7475671d8fbc0e870ce9ec1c6f275ddd90f1db +0 -0
  279. data/.git/objects/36/479605ef7fc62ec68841284083e171bcb3b2c2 +0 -2
  280. data/.git/objects/37/1221704ea1da5a27626855e82076565fb58cac +0 -0
  281. data/.git/objects/38/3af6cb155addf818eb9396229892743112dbc3 +0 -0
  282. data/.git/objects/3a/97679c02b93c246d359a6f663b513691e37991 +0 -0
  283. data/.git/objects/3b/101bd6fccf79321048448c8384029c8768ec01 +0 -0
  284. data/.git/objects/3d/4a702963039cf32ac2ca91c37669e78625f92b +0 -0
  285. data/.git/objects/40/55426e988e151ac26792ec17bf31d04c606377 +0 -0
  286. data/.git/objects/42/828defbc95389daf9bfa11c8b2341f98303ee7 +0 -0
  287. data/.git/objects/44/b6d8df4e1f924caeb7de56135c251ce24998fd +0 -0
  288. data/.git/objects/46/42a59703e31a105aa67c4511be5e41402d08af +0 -0
  289. data/.git/objects/49/22dc7ff543c31059ef3979c51ab36cdf74367e +0 -0
  290. data/.git/objects/49/3a5d4dfc291e68321e15120dd9ca15388817ff +0 -0
  291. data/.git/objects/4a/787ce4e048fe15df728e9b5e9170f087b0bcde +0 -4
  292. data/.git/objects/4b/f9324fefa911db32f9d75461842e3420254e7f +0 -0
  293. data/.git/objects/4d/ada0b46f7aedd3da02dbec0daef667b3903765 +0 -0
  294. data/.git/objects/50/dfa247b62156c4eb6371c8a68054c63aa1f075 +0 -2
  295. data/.git/objects/53/ae2a3872c30d9242b5ea4a609165c02da18392 +0 -0
  296. data/.git/objects/56/43b861a644b727a8b54ae003977151d975f360 +0 -0
  297. data/.git/objects/57/5fdffb0b6f624c9d2676964603788264ed7b28 +0 -0
  298. data/.git/objects/5a/53898e77d291396aeb2b7255d97d185b92cad2 +0 -0
  299. data/.git/objects/5c/bb5fbba6c1b72af9e412047c50e8629c681d72 +0 -1
  300. data/.git/objects/5e/11ba5e0794a914747bae95b942b2dbeb5c36c3 +0 -0
  301. data/.git/objects/5e/22424fba117a89e563604e2e55fca82ef7547a +0 -0
  302. data/.git/objects/5e/90e483ed4782b9a2a834280c6ad5e7711462fa +0 -0
  303. data/.git/objects/5e/f6eb87941331580ede445399654f199a9a6156 +0 -0
  304. data/.git/objects/5f/2b8b8c9f16877c91fda9a177e235698103c4c9 +0 -0
  305. data/.git/objects/61/8d3d8348db1739ba171f7db3effb3c7244bf3b +0 -2
  306. data/.git/objects/62/b4bbd793a5a9ad8b0f24ef657b973afbfcf3cf +0 -0
  307. data/.git/objects/62/fa8ffcffcedc680a953c2e01ca9312e60807b0 +0 -0
  308. data/.git/objects/63/82b66d637e3d04e78a6272e25d3e212de90a10 +0 -0
  309. data/.git/objects/65/b8ba705a4a439a8b26df539f10b97d6ca4988d +0 -1
  310. data/.git/objects/66/aa791f24ea2ed8717abe3d1c74da4ad544723d +0 -0
  311. data/.git/objects/68/02f5c496f00787242a9fa1a81eb9847071e076 +0 -0
  312. data/.git/objects/69/b1b39f438eb902f68ddd438119d2e74633d16f +0 -0
  313. data/.git/objects/6c/a1abc3f9fe344fddcedb7163848fe6111717ae +0 -0
  314. data/.git/objects/6d/003cf32b629086b5714d3ba0cb6b3ae296ff4e +0 -0
  315. data/.git/objects/6e/4e5c95547a5e088db2d6a9d3b52c446cfec1fb +0 -0
  316. data/.git/objects/6f/2b5882b4cb9c2ef42902433076b58ef5ce44b9 +0 -0
  317. data/.git/objects/71/d7d7da97da36d9899873715ccd080c2793cbe9 +0 -0
  318. data/.git/objects/7a/64ac4146eb137a2667085fbddfea97cc727bb7 +0 -2
  319. data/.git/objects/7b/47a3e0c3fb6407567185df38e031cb54179c6e +0 -0
  320. data/.git/objects/7c/34481a926b48e49767828aa8a3bbeeeb26643e +0 -0
  321. data/.git/objects/7c/4fb1fb0dfa094010b07e489dd6feaa0b15c316 +0 -0
  322. data/.git/objects/7d/97e0e697055b4fbf915cc3d662d4599b3b1477 +0 -0
  323. data/.git/objects/7f/0673a63b426d7025b0a11de29083490264b350 +0 -0
  324. data/.git/objects/81/031da1db90c4cd43fe27336054d76564dbe64c +0 -3
  325. data/.git/objects/81/1ad37e54ba756ff8d3acbbad733e43631c2de8 +0 -3
  326. data/.git/objects/81/f505f109391e66ba3de39165c66c41b8e5e0bb +0 -0
  327. data/.git/objects/82/1912a397a9029beb4d74f407a6ad4b8e36f2f2 +0 -0
  328. data/.git/objects/85/8d7587d219e75ac4eda5bc7b6d28e74d545146 +0 -0
  329. data/.git/objects/86/738c97b0d7ac8443a25cbcd0c4e147bcdb152e +0 -0
  330. data/.git/objects/86/edc0909929d735fe5e1cf8f8b46ad7fa2c1d60 +0 -0
  331. data/.git/objects/8b/722287d6667e73e07eab685f7bd7b32dbecb04 +0 -0
  332. data/.git/objects/8b/ef303f65e1da2f9054b8912cb952718ef99bba +0 -0
  333. data/.git/objects/8c/572af4f04bcafb3c226a669fbc4dc508aed651 +0 -0
  334. data/.git/objects/8d/a995e65577a82011df060b13a498f0a738d017 +0 -0
  335. data/.git/objects/8e/1980f27fbc85de9d530e3946ad9f4e78b96107 +0 -0
  336. data/.git/objects/8e/5b69ea615859da8ee6d7848ca754d8cca5ffc5 +0 -0
  337. data/.git/objects/90/cfb8df76866f20a0c9c4adfb6d5d1faebad9d3 +0 -0
  338. data/.git/objects/9f/e781c5e0fe8f889aefb163da0b52f9cf25ec1f +0 -2
  339. data/.git/objects/a4/fd740f28646783c68d1db592fa65a983d73e7b +0 -0
  340. data/.git/objects/a7/618ca140c7c16536cdbd864c8264d4e738d508 +0 -0
  341. data/.git/objects/a9/38b272a1a743d7e30caa05b5513760195ec0a8 +0 -4
  342. data/.git/objects/a9/4c0880d370e61595adda4af6e91209437265aa +0 -0
  343. data/.git/objects/aa/2420e96b6dcb848de2a8ea393c28a0314eda6e +0 -2
  344. data/.git/objects/aa/ddfc59430a3fb268bd5c97a088ea4bfdb2db07 +0 -0
  345. data/.git/objects/ac/3226f3722e8ea60a4ddcbc5b4a30d305fbdf50 +0 -0
  346. data/.git/objects/ad/8ddf80de972b932bc955c672c29e21f948367f +0 -0
  347. data/.git/objects/ad/994f9b41e5bc6fd188de9aa8adefe6b5515ed6 +0 -3
  348. data/.git/objects/af/606f60f63c31341fd75ec557e073435327cf82 +0 -0
  349. data/.git/objects/b1/244bb3652d56ebe4b465468e214d1a1fa87ebb +0 -1
  350. data/.git/objects/b2/1be06405e5a7e2db12e03d6a781c759b305a72 +0 -0
  351. data/.git/objects/b2/a45e92c20d09897c984186472f616c0af6b5d3 +0 -2
  352. data/.git/objects/b3/39ab5d14998e1bb098eb0b807fb9b53ecc790b +0 -0
  353. data/.git/objects/b3/838491c1c451ff8680fe25a7288d79e22c5ee9 +0 -1
  354. data/.git/objects/b4/e715329ba853104d19112487b1188571bca659 +0 -0
  355. data/.git/objects/b5/010cc435a10af9518f125b67851576c1e74835 +0 -0
  356. data/.git/objects/b5/9d6a5f9325cbd5a7ce3b351b51db1f1b6d58f9 +0 -0
  357. data/.git/objects/b6/e185313a1e82513d52144e80d97c4e7217a6b0 +0 -0
  358. data/.git/objects/b8/bd01ebc6defac18710776615168beb4e251e87 +0 -2
  359. data/.git/objects/b8/ca44e136c1392f27f617801a9ea908eaf45d0b +0 -0
  360. data/.git/objects/ba/c39f505b90f6e64cff088337293912161a4ca5 +0 -0
  361. data/.git/objects/bb/c21a34b3d2ddd51f3e39ddef3c6811aaa26305 +0 -0
  362. data/.git/objects/bf/1e07cd3085bed5be7f3ca1860ec8c14d0fdebb +0 -0
  363. data/.git/objects/bf/4d123f34ecf86a041a5d8df32beb6e1b24dfed +0 -0
  364. data/.git/objects/c0/aa97f36a0fdf80be4ca530ecf0ff7ec23fc313 +0 -0
  365. data/.git/objects/c2/759026a46887f199c46ee60ef9764fed87c7af +0 -0
  366. data/.git/objects/c3/6838a35e7acdbe40a8e762aa92e143d6be8376 +0 -0
  367. data/.git/objects/c5/73778609d449286e4eb5177d34e3c77b0cf520 +0 -0
  368. data/.git/objects/c5/945ab6909de8dd7f9e192a67fe72db2a7f5740 +0 -0
  369. data/.git/objects/c5/ef2f6ac4ee5779fa79f7afb54a458191352e86 +0 -0
  370. data/.git/objects/c6/c08bf8bd35fcf7fc9127a482badd7a9ff48ba2 +0 -0
  371. data/.git/objects/c6/c8485326187c9c872dedc68d71a2fe3ad15446 +0 -0
  372. data/.git/objects/cc/0b74e32ae045d3208839aa91d0dc94f5ea4c09 +0 -0
  373. data/.git/objects/cc/dd62a9a3a9e16e487495294c19ac64da9516d0 +0 -3
  374. data/.git/objects/cf/8ccc732db70ccfb4e185f78dc03512b04fb4f6 +0 -0
  375. data/.git/objects/d2/6b6bac449e70757e718bf023bd3c327b3f231c +0 -0
  376. data/.git/objects/d3/b4580aaa3c069e320b941dd23f56a474cd6caa +0 -3
  377. data/.git/objects/d4/5dffe5792c4d873de1cc233ec8992e9a9f8df5 +0 -0
  378. data/.git/objects/d7/ea5d3d4b7fdcc93771304fee8d5261f6469f28 +0 -0
  379. data/.git/objects/d8/53eba81fc4b75fbc90cf8c39f4b1344deddc9f +0 -0
  380. data/.git/objects/d8/de40b222d79af7bdb2b1ae59944fc3b0dd0f05 +0 -0
  381. data/.git/objects/df/39c68e0de1bee1b87beeb44170f52db5da2317 +0 -0
  382. data/.git/objects/df/e23416f16c0bb6c98ca2a0b1d02d803ff53831 +0 -0
  383. data/.git/objects/df/ee793cf3fd89820e5a9a4481d35000d75040d9 +0 -0
  384. data/.git/objects/e0/f7b971a634e34d7976676a4d575c654746a5f8 +0 -0
  385. data/.git/objects/e2/6ee4ee0aae4b71ab0fae46952e858050eb6380 +0 -0
  386. data/.git/objects/e5/134d62f67ad64eb79b139bb86ed8af711704d4 +0 -0
  387. data/.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  388. data/.git/objects/e8/2061e7bc928cd8df2a4ac34848bd670d7cb29c +0 -0
  389. data/.git/objects/e8/2e9ddde8094f4d6f4871abe19f82acce46cafe +0 -0
  390. data/.git/objects/e9/0b6867602c5754080219c30aee275f3aa10b49 +0 -0
  391. data/.git/objects/e9/8264a4555c2b9436f7c8633575eb5cea338e35 +0 -0
  392. data/.git/objects/eb/86cc8e7187bdb75267a4e5ba1c5d4d4b200c98 +0 -0
  393. data/.git/objects/ee/282c9448793de0bd2df8348e0f4fd6cb1b8f2f +0 -0
  394. data/.git/objects/f0/2d1b4f22ec5df7fc658d4616cac5e5250e033b +0 -0
  395. data/.git/objects/f3/8245046bfe9c478a502c58b1c1434f382800d3 +0 -0
  396. data/.git/objects/f3/e1d5f3bc635974bf9410cb87d21bb3ad29da6b +0 -0
  397. data/.git/objects/f6/3c2e6d83a07cf107ff63a6b92a72a0ac5e9e3f +0 -0
  398. data/.git/objects/f8/a51fe3b4da3e5616ee4606fc71ef1915162853 +0 -0
  399. data/.git/objects/fb/0a0717fd1a64bfe6de89e84ce2f320e9bca527 +0 -0
  400. data/.git/objects/fc/794047fc246572581a7fdce016e1be6b8ab61a +0 -0
  401. data/.git/objects/fe/d4da51927e4d0b97d071611a3cb0c7c484938d +0 -0
  402. data/.git/objects/ff/db1bde1735cee2b62d80bf8151ae98515069b4 +0 -0
  403. data/.git/refs/heads/master +0 -1
  404. data/.git/refs/remotes/origin/master +0 -1
  405. data/.gitignore +0 -3
  406. data/bin/crystal_console +0 -45
  407. data/bin/crystal_new +0 -3
  408. data/bin/crystal_server +0 -6
  409. data/lib/crystal/core/config.rb +0 -52
  410. data/lib/crystal/core/crystal.rb +0 -40
  411. data/lib/crystal/core/remote.rb +0 -8
  412. data/lib/crystal/core/router.rb +0 -39
  413. data/lib/crystal/core/scopes.rb +0 -4
  414. data/lib/crystal/rack/adapter.rb +0 -57
  415. data/lib/crystal/rack/middleware/static_files.rb +0 -27
  416. data/lib/crystal/rack/rack_app.rb +0 -96
  417. data/lib/crystal/rack/support.rb +0 -55
  418. data/lib/crystal.rb +0 -37
  419. data/rakefile +0 -70
@@ -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,135 @@
1
+ require 'singleton'
2
+
3
+ class SafeHash < BasicObject
4
+ attr_reader :hash
5
+
6
+ def initialize hash = {}
7
+ reinitialize hash
8
+ end
9
+
10
+ def []= key, value
11
+ value = SafeHash.new value if value.is_a? Hash
12
+ @hash[key.to_s] = value
13
+ end
14
+
15
+ def include? key
16
+ @hash.include? key.to_s
17
+ end
18
+
19
+ def [] key, *args
20
+ key = key.to_s
21
+ if key.last == '!'
22
+ key = key[0..-2]
23
+ if @hash.include? key
24
+ @hash[key]
25
+ else
26
+ raise "No key #{key}"
27
+ end
28
+ elsif key.last == '?'
29
+ key = key[0..-2]
30
+ @hash.include? key
31
+ else
32
+ if @hash.include? key
33
+ @hash[key]
34
+ elsif args.empty?
35
+ SafeNil.instance
36
+ else
37
+ return *args
38
+ end
39
+ end
40
+ end
41
+
42
+ def reinitialize hash
43
+ @hash = {}
44
+ hash.each do |k, v|
45
+ v = SafeHash.new v if v.is_a? Hash
46
+ @hash[k.to_s] = v
47
+ end
48
+ # @hash.freeze
49
+ end
50
+
51
+ def method_missing m, *args
52
+ m = m.to_s
53
+ if m.last == '='
54
+ self[m[0..-2]] = *args
55
+ else
56
+ self[m, *args]
57
+ end
58
+ end
59
+
60
+ def to_yaml *args
61
+ @hash.to_yaml *args
62
+ end
63
+
64
+ def inspect
65
+ @hash.inspect
66
+ end
67
+
68
+ def delete key
69
+ @hash.delete key.to_s
70
+ end
71
+
72
+ # deep conversion, check and converts nested SafeHashes to Hashes
73
+ def to_hash
74
+ r = {}
75
+ @hash.each do |k, v|
76
+ r[k] = if v.respond_to :is_a_safe_hash?
77
+ v.to_hash
78
+ else
79
+ v
80
+ end
81
+ end
82
+ r
83
+ end
84
+ alias_method :to_h, :to_hash
85
+
86
+ def is_a_safe_hash?
87
+ true
88
+ end
89
+
90
+ class SafeNil < BasicObject
91
+ include Singleton
92
+
93
+ def [] key, *args
94
+ key = key.to_s
95
+ if key.last == '!'
96
+ raise "No key #{key}"
97
+ elsif key.last == '?'
98
+ false
99
+ elsif args.empty?
100
+ SafeNil.instance
101
+ else
102
+ return *args
103
+ end
104
+ end
105
+
106
+ def method_missing m, *args
107
+ m = m.to_s
108
+ if m.last == '='
109
+ raise "No such key!"
110
+ else
111
+ self[m, *args]
112
+ end
113
+ end
114
+
115
+ def include? key
116
+ false
117
+ end
118
+
119
+ def to_b
120
+ false
121
+ end
122
+
123
+ def to_yaml *args
124
+ nil.to_yaml *args
125
+ end
126
+
127
+ def to_h
128
+ {}
129
+ end
130
+
131
+ def inspect
132
+ nil.inspect
133
+ end
134
+ end
135
+ 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,42 @@
1
+ require 'crystal/support/gems'
2
+
3
+
4
+ require 'crystal/support/active_support'
5
+
6
+
7
+ require 'ruby_ext'
8
+
9
+ require 'ruby_ext/open_constructor'
10
+ require 'crystal/support/ruby_ext_with_active_support'
11
+
12
+ require 'class_loader'
13
+
14
+ require 'micon'
15
+ require 'crystal/support/micon'
16
+
17
+ require 'dictionary'
18
+
19
+ require 'thread'
20
+ require 'time'
21
+ require 'uri'
22
+ require 'json'
23
+
24
+
25
+ require 'addressable/uri'
26
+ require 'crystal/support/addressable'
27
+ ::Uri = Addressable::URI
28
+
29
+ autoload :Nokogiri, 'nokogiri'
30
+
31
+ [
32
+ 'module',
33
+ 'buffered_logger',
34
+ 'callbacks',
35
+ 'filters',
36
+ 'format',
37
+ 'mime',
38
+ 'string',
39
+ 'rson',
40
+ 'exception',
41
+ 'safe_hash'
42
+ ].each{|f| require "crystal/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,244 @@
1
+ module Crystal
2
+ module Template
3
+ DIRECTORY_NAME = "views"
4
+
5
+ class << self
6
+ inject(
7
+ :logger => :logger,
8
+ :config => :config,
9
+ :environment => :environment
10
+ )
11
+
12
+ def render *args, &block
13
+ result, context = basic_render(parse_arguments(*args), &block)
14
+ result
15
+ end
16
+
17
+ # def render_and_return_context *args, &block
18
+ # basic_render(*parse_arguments(*args), &block)
19
+ # end
20
+
21
+ def render_layout *args
22
+ options = parse_arguments(*args)
23
+ options = options.stringify_keys!
24
+ options.must.include :content
25
+ options.must.include :context
26
+
27
+ result, context = basic_render options do |*args|
28
+ if args.empty?
29
+ options.content
30
+ else
31
+ args.size.must_be == 1
32
+ variable_name = args.first.to_s
33
+ self.context.content_variables[variable_name]
34
+ end
35
+ end
36
+
37
+ result
38
+ end
39
+
40
+ def exist? tname, options = {}
41
+ options = options.to_openobject
42
+ !!find_template(tname, calculate_prefixes(options), options.format, options.current_dir)
43
+ end
44
+
45
+ def read tname, options = {}
46
+ options = options.to_openobject
47
+ file = find_template tname, calculate_prefixes(options), options.format, options.current_dir
48
+ raise "No template '#{tname}'!" unless file
49
+ File.read file
50
+ end
51
+
52
+ def template_name_with_prefix tname, prefix
53
+ index = tname.rindex('/')
54
+ index = index ? index + 1 : 0
55
+ tname = tname.clone
56
+ tname.insert index, prefix
57
+ end
58
+
59
+ def parse_arguments *args
60
+ options = args.extract_options!.to_openobject
61
+ if args.size == 1
62
+ options.template = args.first
63
+ else
64
+ raise "Invalid input" if args.size != 0
65
+ end
66
+
67
+ options
68
+ end
69
+
70
+ def basic_render options, &block
71
+ options = options.clone.to_openobject
72
+
73
+ with_context options do |context|
74
+ context.content_block ||= block
75
+
76
+ with_scope options, context do |scope|
77
+ unless file = options.file
78
+ file = find_template options.template!, calculate_prefixes(options), scope.format, scope.current_dir
79
+ # p [tname, calculate_prefixes(options), scope.format, scope.current_dir]
80
+ raise "No template '#{options.template!}'!" unless file
81
+ end
82
+
83
+ scope.current_dir = dirname(file)
84
+
85
+ template = create_tilt_template file
86
+
87
+ result = with_template context, template do
88
+ render_template template, options, &context.content_block
89
+ end
90
+
91
+ return result, context
92
+ end
93
+ end
94
+ end
95
+
96
+ protected
97
+ def context
98
+ Thread.current[:render_context]
99
+ end
100
+
101
+ def calculate_prefixes options
102
+ options.action ? [''] : options.prefixes
103
+ end
104
+
105
+ def with_context options, &block
106
+ context = Thread.current[:render_context] || options.context || create_context(options)
107
+
108
+ old = Thread.current[:render_context]
109
+ begin
110
+ Thread.current[:render_context] = context
111
+ block.call context
112
+ ensure
113
+ Thread.current[:render_context] = old
114
+ end
115
+ end
116
+
117
+ def with_scope options, context, &block
118
+ initial = context.scope_variables
119
+
120
+ old = context.scope_variables || OpenObject.new
121
+ begin
122
+ context.scope_variables = {
123
+ :current_dir => options.current_dir || old.current_dir,
124
+ :format => options.format || old.format
125
+ # :prefixes => options.prefixes || old.prefixes
126
+ }.to_openobject
127
+
128
+ block.call context.scope_variables
129
+ ensure
130
+ context.scope_variables = old if initial
131
+ end
132
+ end
133
+
134
+ def with_template context, template, &block
135
+ old = context._tilt_template
136
+ begin
137
+ context._tilt_template = template
138
+ block.call context
139
+ ensure
140
+ context._tilt_template = old
141
+ end
142
+ end
143
+
144
+ def create_context options
145
+ context_class = options.context_class || TemplateContext
146
+ raise "#{context_class} must inherit from TemplateContext!" unless context_class.is? TemplateContext
147
+ context = context_class.new
148
+
149
+ context.options = options
150
+
151
+ if ivs = options.instance_variables
152
+ (ivs.is_a?(Array) ? ivs : [ivs]).each do |container|
153
+ if container.is_a? Hash
154
+ container.each do |name, value|
155
+ context.instance_variable_set("@#{name}", value)
156
+ end
157
+ else
158
+ container.instance_variables.each do |ivname|
159
+ iv = container.instance_variable_get(ivname)
160
+ context.instance_variable_set(ivname, iv)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ context
167
+ end
168
+
169
+ def dirname_without_cache path;
170
+ File.dirname path
171
+ end
172
+ cache_method_with_params_in_production :dirname
173
+
174
+ def find_template tname, prefixes, format, current_dir
175
+ # splitted into two to optimize cache
176
+ if tname =~ /^\//
177
+ find_absolute_template tname, prefixes, format
178
+ else
179
+ find_relative_template tname, prefixes, format, current_dir
180
+ end
181
+ end
182
+
183
+ def find_absolute_template_without_cache tname, prefixes, format
184
+ prefixes = prefixes || config.default_template_prefixes!
185
+ prefixes.each do |prefix|
186
+ tname_with_prefix = template_name_with_prefix("/#{DIRECTORY_NAME}#{tname}", prefix)
187
+ file = find_file(tname_with_prefix, format, environment.directories)
188
+ return file if file
189
+ end
190
+ return nil
191
+ end
192
+ cache_method_with_params_in_production :find_absolute_template
193
+
194
+ def find_relative_template_without_cache tname, prefixes, format, current_dir
195
+ raise "You can't use relative template path '#{tname}' without :current_dir!" unless current_dir
196
+ prefixes = prefixes || config.default_template_prefixes!
197
+ prefixes.each do |prefix|
198
+ tname_with_prefix = template_name_with_prefix("/#{tname}", prefix)
199
+ file = find_file(tname_with_prefix, format, current_dir)
200
+ return file if file
201
+ end
202
+ return nil
203
+ end
204
+ cache_method_with_params_in_production :find_relative_template
205
+
206
+ def find_file tname, format, directories
207
+ if tname.include? '.'
208
+ _find_file(tname, directories) || _find_file("#{tname}.*", directories)
209
+ else
210
+ if format
211
+ _find_file("#{tname}.#{format}.*", directories) or
212
+ _find_file("#{tname}.*", directories, true)
213
+ else
214
+ _find_file("#{tname}.*", directories)
215
+ end
216
+ end
217
+ end
218
+
219
+ # with_one_extension - 'tname.*' matches not only 'tname.erb' but also 'tname.html.erb',
220
+ # with this option enabled it will not match 'tname.html.erb', only 'tname.erb'
221
+ def _find_file pattern, directories, with_one_extension = false
222
+ files = environment.find_files_by_pattern_without_cache pattern, directories
223
+ files = files.select{|f| f !~ /\.[^\.\/]+\.[^\.\/]+$/} if with_one_extension
224
+ logger.warn "Multiple templates for '#{pattern}'!" if files.size > 1
225
+ files.first
226
+ end
227
+
228
+ def create_tilt_template path
229
+ template_options = {
230
+ :ugly => true,
231
+ :outvar => "@output"
232
+ }
233
+ template = Tilt.new(path, nil, template_options)
234
+ end
235
+
236
+ def render_template template, options, &block
237
+ locals = options.locals || {}
238
+ locals[:object] = options.object if options.object?
239
+
240
+ template.render context, locals, &block
241
+ end
242
+ end
243
+ end
244
+ end
@@ -0,0 +1,57 @@
1
+ module Crystal
2
+ class TemplateContext
3
+ include Tilt::CompileSite, Tilt::ContextExt
4
+
5
+ #
6
+ # System
7
+ #
8
+ attr_accessor :options, :_tilt_template
9
+
10
+ # for saving :format, :current_dir and others
11
+ # def scope_variables; @scope_variables ||= OpenObject.new end
12
+ attr_accessor :scope_variables
13
+
14
+
15
+ #
16
+ # Helpers
17
+ #
18
+ inject(
19
+ :workspace => :workspace,
20
+ :router => :router,
21
+ :config => :config
22
+ )
23
+
24
+ delegate :render, :to => ::Crystal::Template
25
+ delegate :url_for, :to => :router
26
+
27
+
28
+ #
29
+ # Content Variables
30
+ #
31
+ attr_accessor :content_block
32
+ def content_variables; @content_variables ||= {} end
33
+ def content_for name, content = nil, &block
34
+ content ||= capture(&block)
35
+ (content_variables[name.to_s] ||= "") << content
36
+ nil
37
+ end
38
+ def prepend_to name, content = nil, &block
39
+ content ||= capture(&block)
40
+ (content_variables[name.to_s] ||= "").insert 0, content
41
+ nil
42
+ end
43
+ def wrap_content_for name, &block
44
+ block.must_be.defined
45
+ content = capture((content_variables[name.to_s] || ""), &block)
46
+ content_variables[name.to_s] ||= content
47
+ nil
48
+ end
49
+ def has_content_for? name
50
+ content_variables.include? name.to_s
51
+ end
52
+
53
+ def params
54
+ workspace.params
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,21 @@
1
+ gem "haml"
2
+
3
+ require 'crystal/environment'
4
+
5
+ require 'erb'
6
+ require 'haml'
7
+ require 'tilt'
8
+ require 'crystal/template/support/tilt'
9
+
10
+ [
11
+ 'template',
12
+ 'template_context'
13
+ ].each{|f| require "crystal/template/#{f}"}
14
+
15
+
16
+ #
17
+ # Initialization
18
+ #
19
+ Crystal::Config::DEFAULTS.merge!({
20
+ :default_template_prefixes => ['', '_']
21
+ }.stringify_keys)
@@ -0,0 +1,11 @@
1
+ <html>
2
+ <body>
3
+ <p>
4
+ <b><font color='red'>ERROR:</font></b>
5
+ <%= error.message.html_escape %>
6
+ </p>
7
+ <pre>
8
+ <%= error.backtrace && error.backtrace.sfilter(Exception.common_filters).join("\n ").html_escape %>
9
+ </pre>
10
+ </body>
11
+ </html>
@@ -0,0 +1 @@
1
+ console.log("<%= error.message.js_escape %>");
data/readme.md CHANGED
@@ -1,7 +1,11 @@
1
- # Crystal - Ruby Web Framework.
1
+ # Crystal - Ruby Web Framework inspired by Rails and Spring.
2
2
 
3
- It's a code extracted from my [http://bom4.com](http://bom4.com) application.
4
- It's under heavy development now and not ready for use.
3
+ It kinda does the same thing as Rails but in different way. The idea is to provide you with an application framework as opened and extensible as the Ruby itself.
5
4
 
6
- # TODO
7
- - Use Rack::Utils for escape
5
+ It's the constructor, built from set of low coupled components. You can start quickly using one of predefined 'opinionated' profiles, or tune and extend it as you wish.
6
+ The same apply for the architecture of your application - instead of to be a monolith it consists of cooperating plugins/gems.
7
+
8
+ Web tier looks almost like Rails and overall architecture is slightly borrowed from Java Spring framework.
9
+ Yes, I know that IoC aren't much popular in Ruby community, but it's not quite ordinary IoC, and it's really handy.
10
+
11
+ *It's under heavy development, and not ready to use.*