thorero 0.9.4.4 → 0.9.4.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. data/LICENSE +1 -1
  2. data/README +21 -0
  3. data/Rakefile +275 -108
  4. data/TODO +0 -0
  5. data/bin/merb +12 -0
  6. data/bin/merb-specs +5 -0
  7. data/docs/bootloading.dox +58 -0
  8. data/docs/documentation_standards +40 -0
  9. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  10. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  11. data/docs/merb-core-call-stack-diagram.png +0 -0
  12. data/docs/new_render_api +51 -0
  13. data/lib/merb-core.rb +603 -0
  14. data/lib/merb-core/autoload.rb +32 -0
  15. data/lib/merb-core/bootloader.rb +708 -0
  16. data/lib/merb-core/config.rb +303 -0
  17. data/lib/merb-core/constants.rb +43 -0
  18. data/lib/merb-core/controller/abstract_controller.rb +578 -0
  19. data/lib/merb-core/controller/exceptions.rb +302 -0
  20. data/lib/merb-core/controller/merb_controller.rb +256 -0
  21. data/lib/merb-core/controller/mime.rb +106 -0
  22. data/lib/merb-core/controller/mixins/authentication.rb +87 -0
  23. data/lib/merb-core/controller/mixins/controller.rb +290 -0
  24. data/lib/merb-core/controller/mixins/render.rb +481 -0
  25. data/lib/merb-core/controller/mixins/responder.rb +472 -0
  26. data/lib/merb-core/controller/template.rb +254 -0
  27. data/lib/merb-core/core_ext.rb +8 -0
  28. data/lib/merb-core/core_ext/kernel.rb +319 -0
  29. data/lib/merb-core/dispatch/cookies.rb +91 -0
  30. data/lib/merb-core/dispatch/dispatcher.rb +278 -0
  31. data/lib/merb-core/dispatch/exceptions.html.erb +303 -0
  32. data/lib/merb-core/dispatch/request.rb +603 -0
  33. data/lib/merb-core/dispatch/router.rb +179 -0
  34. data/lib/merb-core/dispatch/router/behavior.rb +867 -0
  35. data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
  36. data/lib/merb-core/dispatch/router/route.rb +321 -0
  37. data/lib/merb-core/dispatch/session.rb +78 -0
  38. data/lib/merb-core/dispatch/session/cookie.rb +168 -0
  39. data/lib/merb-core/dispatch/session/memcached.rb +184 -0
  40. data/lib/merb-core/dispatch/session/memory.rb +241 -0
  41. data/lib/merb-core/dispatch/worker.rb +28 -0
  42. data/lib/merb-core/gem_ext/erubis.rb +77 -0
  43. data/lib/{extlib → merb-core}/logger.rb +2 -2
  44. data/lib/merb-core/plugins.rb +59 -0
  45. data/lib/merb-core/rack.rb +21 -0
  46. data/lib/merb-core/rack/adapter.rb +44 -0
  47. data/lib/merb-core/rack/adapter/ebb.rb +25 -0
  48. data/lib/merb-core/rack/adapter/evented_mongrel.rb +26 -0
  49. data/lib/merb-core/rack/adapter/fcgi.rb +17 -0
  50. data/lib/merb-core/rack/adapter/irb.rb +118 -0
  51. data/lib/merb-core/rack/adapter/mongrel.rb +26 -0
  52. data/lib/merb-core/rack/adapter/runner.rb +28 -0
  53. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
  54. data/lib/merb-core/rack/adapter/thin.rb +39 -0
  55. data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
  56. data/lib/merb-core/rack/adapter/webrick.rb +36 -0
  57. data/lib/merb-core/rack/application.rb +18 -0
  58. data/lib/merb-core/rack/handler/mongrel.rb +97 -0
  59. data/lib/merb-core/rack/middleware.rb +26 -0
  60. data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
  61. data/lib/merb-core/rack/middleware/profiler.rb +19 -0
  62. data/lib/merb-core/rack/middleware/static.rb +45 -0
  63. data/lib/merb-core/server.rb +252 -0
  64. data/lib/merb-core/tasks/audit.rake +68 -0
  65. data/lib/merb-core/tasks/merb.rb +1 -0
  66. data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
  67. data/lib/merb-core/test.rb +11 -0
  68. data/lib/merb-core/test/helpers.rb +9 -0
  69. data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
  70. data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
  71. data/lib/merb-core/test/helpers/request_helper.rb +344 -0
  72. data/lib/merb-core/test/helpers/route_helper.rb +33 -0
  73. data/lib/merb-core/test/helpers/view_helper.rb +121 -0
  74. data/lib/merb-core/test/matchers.rb +9 -0
  75. data/lib/merb-core/test/matchers/controller_matchers.rb +319 -0
  76. data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
  77. data/lib/merb-core/test/matchers/view_matchers.rb +335 -0
  78. data/lib/merb-core/test/run_specs.rb +47 -0
  79. data/lib/merb-core/test/tasks/spectasks.rb +68 -0
  80. data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
  81. data/lib/merb-core/test/test_ext/object.rb +14 -0
  82. data/lib/merb-core/test/test_ext/string.rb +14 -0
  83. data/lib/merb-core/vendor/facets.rb +2 -0
  84. data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
  85. data/lib/merb-core/vendor/facets/inflect.rb +345 -0
  86. data/lib/merb-core/version.rb +11 -0
  87. data/spec/private/config/adapter_spec.rb +32 -0
  88. data/spec/private/config/config_spec.rb +202 -0
  89. data/spec/private/config/environment_spec.rb +13 -0
  90. data/spec/private/config/spec_helper.rb +1 -0
  91. data/spec/private/core_ext/kernel_spec.rb +169 -0
  92. data/spec/private/dispatch/bootloader_spec.rb +24 -0
  93. data/spec/private/dispatch/cookies_spec.rb +107 -0
  94. data/spec/private/dispatch/dispatch_spec.rb +35 -0
  95. data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
  96. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
  97. data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
  98. data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
  99. data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
  100. data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
  101. data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
  102. data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
  103. data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
  104. data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
  105. data/spec/private/dispatch/fixture/config/black_hole.rb +12 -0
  106. data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
  107. data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
  108. data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
  109. data/spec/private/dispatch/fixture/config/init.rb +45 -0
  110. data/spec/private/dispatch/fixture/config/rack.rb +11 -0
  111. data/spec/private/dispatch/fixture/config/router.rb +35 -0
  112. data/spec/private/dispatch/fixture/log/merb_test.log +1874 -0
  113. data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
  114. data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
  115. data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
  116. data/spec/private/dispatch/route_params_spec.rb +24 -0
  117. data/spec/private/dispatch/session_mixin_spec.rb +47 -0
  118. data/spec/private/dispatch/spec_helper.rb +1 -0
  119. data/spec/private/plugins/plugin_spec.rb +166 -0
  120. data/spec/private/rack/application_spec.rb +49 -0
  121. data/spec/private/router/behavior_spec.rb +60 -0
  122. data/spec/private/router/fixture/log/merb_test.log +139 -0
  123. data/spec/private/router/route_spec.rb +414 -0
  124. data/spec/private/router/router_spec.rb +175 -0
  125. data/spec/private/vendor/facets/plural_spec.rb +564 -0
  126. data/spec/private/vendor/facets/singular_spec.rb +489 -0
  127. data/spec/public/DEFINITIONS +11 -0
  128. data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
  129. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
  130. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
  131. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
  132. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
  133. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
  134. data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
  135. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
  136. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
  137. data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
  138. data/spec/public/abstract_controller/controllers/display.rb +54 -0
  139. data/spec/public/abstract_controller/controllers/filters.rb +193 -0
  140. data/spec/public/abstract_controller/controllers/helpers.rb +41 -0
  141. data/spec/public/abstract_controller/controllers/partial.rb +121 -0
  142. data/spec/public/abstract_controller/controllers/render.rb +113 -0
  143. data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
  144. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
  145. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
  146. data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
  147. data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
  148. data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
  149. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
  150. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
  151. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
  152. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
  153. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
  154. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
  155. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
  156. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
  157. data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
  158. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
  159. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
  160. data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
  161. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
  162. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
  163. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
  164. data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
  165. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
  166. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
  167. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
  168. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
  169. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
  170. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
  171. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
  172. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
  173. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
  174. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
  175. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
  176. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
  177. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
  178. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
  179. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
  180. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
  181. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
  182. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
  183. data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
  184. data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
  185. data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
  186. data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
  187. data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
  188. data/spec/public/abstract_controller/display_spec.rb +33 -0
  189. data/spec/public/abstract_controller/filter_spec.rb +106 -0
  190. data/spec/public/abstract_controller/helper_spec.rb +21 -0
  191. data/spec/public/abstract_controller/partial_spec.rb +61 -0
  192. data/spec/public/abstract_controller/render_spec.rb +90 -0
  193. data/spec/public/abstract_controller/spec_helper.rb +31 -0
  194. data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
  195. data/spec/public/boot_loader/spec_helper.rb +1 -0
  196. data/spec/public/controller/authentication_spec.rb +103 -0
  197. data/spec/public/controller/base_spec.rb +36 -0
  198. data/spec/public/controller/controllers/authentication.rb +45 -0
  199. data/spec/public/controller/controllers/base.rb +36 -0
  200. data/spec/public/controller/controllers/display.rb +118 -0
  201. data/spec/public/controller/controllers/redirect.rb +30 -0
  202. data/spec/public/controller/controllers/responder.rb +93 -0
  203. data/spec/public/controller/controllers/url.rb +7 -0
  204. data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
  205. data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +1 -0
  206. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
  207. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
  208. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
  209. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
  210. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
  211. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
  212. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
  213. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +1 -0
  214. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
  215. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
  216. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
  217. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
  218. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
  219. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
  220. data/spec/public/controller/display_spec.rb +84 -0
  221. data/spec/public/controller/redirect_spec.rb +27 -0
  222. data/spec/public/controller/responder_spec.rb +163 -0
  223. data/spec/public/controller/spec_helper.rb +11 -0
  224. data/spec/public/controller/url_spec.rb +180 -0
  225. data/spec/public/core/merb_core_spec.rb +45 -0
  226. data/spec/public/core_ext/class_spec.rb +91 -0
  227. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
  228. data/spec/public/core_ext/kernel_spec.rb +9 -0
  229. data/spec/public/core_ext/spec_helper.rb +1 -0
  230. data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
  231. data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
  232. data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
  233. data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
  234. data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
  235. data/spec/public/directory_structure/directory/config/router.rb +3 -0
  236. data/spec/public/directory_structure/directory/log/merb_test.log +562 -0
  237. data/spec/public/directory_structure/directory_spec.rb +44 -0
  238. data/spec/public/logger/logger_spec.rb +181 -0
  239. data/spec/public/logger/spec_helper.rb +1 -0
  240. data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
  241. data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
  242. data/spec/public/reloading/directory/config/init.rb +2 -0
  243. data/spec/public/reloading/directory/log/merb_test.log +138 -0
  244. data/spec/public/reloading/reload_spec.rb +103 -0
  245. data/spec/public/request/multipart_spec.rb +41 -0
  246. data/spec/public/request/request_spec.rb +228 -0
  247. data/spec/public/router/default_spec.rb +21 -0
  248. data/spec/public/router/deferred_spec.rb +22 -0
  249. data/spec/public/router/fixation_spec.rb +27 -0
  250. data/spec/public/router/fixture/log/merb_test.log +1556 -0
  251. data/spec/public/router/namespace_spec.rb +113 -0
  252. data/spec/public/router/nested_matches_spec.rb +97 -0
  253. data/spec/public/router/nested_resources_spec.rb +41 -0
  254. data/spec/public/router/resource_spec.rb +37 -0
  255. data/spec/public/router/resources_spec.rb +82 -0
  256. data/spec/public/router/spec_helper.rb +90 -0
  257. data/spec/public/router/special_spec.rb +61 -0
  258. data/spec/public/router/string_spec.rb +61 -0
  259. data/spec/public/template/template_spec.rb +104 -0
  260. data/spec/public/template/templates/error.html.erb +2 -0
  261. data/spec/public/template/templates/template.html.erb +1 -0
  262. data/spec/public/template/templates/template.html.myt +1 -0
  263. data/spec/public/test/controller_matchers_spec.rb +402 -0
  264. data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
  265. data/spec/public/test/controllers/dispatch_controller.rb +11 -0
  266. data/spec/public/test/controllers/spec_helper_controller.rb +38 -0
  267. data/spec/public/test/multipart_request_helper_spec.rb +159 -0
  268. data/spec/public/test/multipart_upload_text_file.txt +1 -0
  269. data/spec/public/test/request_helper_spec.rb +221 -0
  270. data/spec/public/test/route_helper_spec.rb +71 -0
  271. data/spec/public/test/route_matchers_spec.rb +162 -0
  272. data/spec/public/test/view_helper_spec.rb +96 -0
  273. data/spec/public/test/view_matchers_spec.rb +183 -0
  274. data/spec/spec_helper.rb +68 -0
  275. metadata +493 -41
  276. data/README.txt +0 -3
  277. data/lib/extlib.rb +0 -32
  278. data/lib/extlib/assertions.rb +0 -8
  279. data/lib/extlib/blank.rb +0 -42
  280. data/lib/extlib/class.rb +0 -175
  281. data/lib/extlib/hash.rb +0 -410
  282. data/lib/extlib/hook.rb +0 -366
  283. data/lib/extlib/inflection.rb +0 -141
  284. data/lib/extlib/lazy_array.rb +0 -106
  285. data/lib/extlib/mash.rb +0 -143
  286. data/lib/extlib/module.rb +0 -37
  287. data/lib/extlib/object.rb +0 -165
  288. data/lib/extlib/object_space.rb +0 -13
  289. data/lib/extlib/pathname.rb +0 -5
  290. data/lib/extlib/pooling.rb +0 -233
  291. data/lib/extlib/rubygems.rb +0 -38
  292. data/lib/extlib/simple_set.rb +0 -39
  293. data/lib/extlib/string.rb +0 -132
  294. data/lib/extlib/struct.rb +0 -8
  295. data/lib/extlib/tasks/release.rb +0 -9
  296. data/lib/extlib/time.rb +0 -12
  297. data/lib/extlib/version.rb +0 -3
  298. data/lib/extlib/virtual_file.rb +0 -10
@@ -0,0 +1,254 @@
1
+ module Merb::InlineTemplates
2
+ end
3
+
4
+ module Merb::Template
5
+
6
+ EXTENSIONS = {} unless defined?(EXTENSIONS)
7
+ METHOD_LIST = {} unless defined?(METHOD_LIST)
8
+ MTIMES = {} unless defined?(MTIMES)
9
+
10
+ class << self
11
+ # Get the template's method name from a full path. This replaces
12
+ # non-alphanumeric characters with __ and "." with "_"
13
+ #
14
+ # Collisions are potentially possible with something like:
15
+ # ~foo.bar and __foo.bar or !foo.bar.
16
+ #
17
+ # ==== Parameters
18
+ # path<String>:: A full path to convert to a valid Ruby method name
19
+ #
20
+ # ==== Returns
21
+ # String:: The template name.
22
+ #
23
+ #---
24
+ # We might want to replace this with something that varies the
25
+ # character replaced based on the non-alphanumeric character
26
+ # to avoid edge-case collisions.
27
+ def template_name(path)
28
+ path = File.expand_path(path)
29
+ path.gsub(/[^\.a-zA-Z0-9]/, "__").gsub(/\./, "_")
30
+ end
31
+
32
+ # For a given path, get an IO object that responds to #path.
33
+ #
34
+ # This is so that plugins can override this if they provide
35
+ # mechanisms for specifying templates that are not just simple
36
+ # files. The plugin is responsible for ensuring that the fake
37
+ # path provided will work with #template_for, and thus the
38
+ # RenderMixin in general.
39
+ #
40
+ # ==== Parameters
41
+ # path<String>:: A full path to find a template for. This is the
42
+ # path that the RenderMixin assumes it should find the template
43
+ # in.
44
+ #
45
+ # ==== Returns
46
+ # IO#path:: An IO object that responds to path (File or VirtualFile).
47
+ #---
48
+ # @semipublic
49
+ def load_template_io(path)
50
+ File.open(path, "r")
51
+ end
52
+
53
+ # Get the name of the template method for a particular path.
54
+ #
55
+ # ==== Parameters
56
+ # path<String>:: A full path to find a template method for.
57
+ # template_stack<Array>:: The template stack. Not used.
58
+ #
59
+ # ==== Returns
60
+ # DOC
61
+ #---
62
+ # @semipublic
63
+ def template_for(path, template_stack = [])
64
+ path = File.expand_path(path)
65
+
66
+ ret =
67
+ if Merb::Config[:reload_templates]
68
+ file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
69
+ METHOD_LIST[path] = file ? inline_template(load_template_io(file)) : nil
70
+ else
71
+ METHOD_LIST[path] ||= begin
72
+ file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
73
+ file ? inline_template(load_template_io(file)) : nil
74
+ end
75
+ end
76
+
77
+ ret
78
+ end
79
+
80
+ # Get all known template extensions
81
+ #
82
+ # ==== Returns
83
+ # Array:: Extension strings.
84
+ #---
85
+ # @semipublic
86
+ def template_extensions
87
+ EXTENSIONS.keys
88
+ end
89
+
90
+ # Takes a template at a particular path and inlines it into a module and
91
+ # adds it to the METHOD_LIST table to speed lookup later.
92
+ #
93
+ # ==== Parameters
94
+ # io<#path>::
95
+ # An IO that responds to #path (File or VirtualFile)
96
+ # mod<Module>::
97
+ # The module to put the compiled method into. Defaults to
98
+ # Merb::InlineTemplates
99
+ #
100
+ # ==== Notes
101
+ # Even though this method supports inlining into any module, the method
102
+ # must be available to instances of AbstractController that will use it.
103
+ #---
104
+ # @public
105
+ def inline_template(io, mod = Merb::InlineTemplates)
106
+ path = File.expand_path(io.path)
107
+ ret = METHOD_LIST[path.gsub(/\.[^\.]*$/, "")] =
108
+ engine_for(path).compile_template(io, template_name(path), mod)
109
+ io.close
110
+ ret
111
+ end
112
+
113
+ # Finds the engine for a particular path.
114
+ #
115
+ # ==== Parameters
116
+ # path<String>:: The path of the file to find an engine for.
117
+ #
118
+ # ==== Returns
119
+ # Class:: The engine.
120
+ #---
121
+ # @semipublic
122
+ def engine_for(path)
123
+ path = File.expand_path(path)
124
+ EXTENSIONS[path.match(/\.([^\.]*)$/)[1]]
125
+ end
126
+
127
+ # Registers the extensions that will trigger a particular templating
128
+ # engine.
129
+ #
130
+ # ==== Parameters
131
+ # engine<Class>:: The class of the engine that is being registered
132
+ # extensions<Array[String]>::
133
+ # The list of extensions that will be registered with this templating
134
+ # language
135
+ #
136
+ # ==== Raises
137
+ # ArgumentError:: engine does not have a compile_template method.
138
+ #
139
+ # ==== Example
140
+ # Merb::Template.register_extensions(Merb::Template::Erubis, ["erb"])
141
+ #---
142
+ # @public
143
+ def register_extensions(engine, extensions)
144
+ raise ArgumentError, "The class you are registering does not have a compile_template method" unless
145
+ engine.respond_to?(:compile_template)
146
+ extensions.each{|ext| EXTENSIONS[ext] = engine }
147
+ Merb::AbstractController.class_eval <<-HERE
148
+ include #{engine}::Mixin
149
+ HERE
150
+ end
151
+ end
152
+
153
+ require 'erubis'
154
+
155
+ class Erubis
156
+ # ==== Parameters
157
+ # io<#path>:: An IO containing the full path of the template.
158
+ # name<String>:: The name of the method that will be created.
159
+ # mod<Module>:: The module that the compiled method will be placed into.
160
+ def self.compile_template(io, name, mod)
161
+ template = ::Erubis::BlockAwareEruby.new(io.read)
162
+
163
+ _old_verbose, $VERBOSE = $VERBOSE, nil
164
+ template.def_method(mod, name, File.expand_path(io.path))
165
+ $VERBOSE = _old_verbose
166
+
167
+ name
168
+ end
169
+
170
+ module Mixin
171
+
172
+ # ==== Parameters
173
+ # *args:: Arguments to pass to the block.
174
+ # &block:: The template block to call.
175
+ #
176
+ # ==== Returns
177
+ # String:: The output of the block.
178
+ #
179
+ # ==== Examples
180
+ # Capture being used in a .html.erb page:
181
+ #
182
+ # <% @foo = capture do %>
183
+ # <p>Some Foo content!</p>
184
+ # <% end %>
185
+ def capture_erb(*args, &block)
186
+ _old_buf, @_erb_buf = @_erb_buf, ""
187
+ block.call(*args)
188
+ ret = @_erb_buf
189
+ @_erb_buf = _old_buf
190
+ ret
191
+ end
192
+
193
+ # DOC
194
+ def concat_erb(string, binding)
195
+ @_erb_buf << string
196
+ end
197
+
198
+ end
199
+
200
+ Merb::Template.register_extensions(self, %w[erb])
201
+ end
202
+
203
+ end
204
+
205
+ module Erubis
206
+ module BlockAwareEnhancer
207
+ def add_preamble(src)
208
+ src << "_old_buf, @_erb_buf = @_erb_buf, ''; "
209
+ src << "@_engine = 'erb'; "
210
+ end
211
+
212
+ def add_postamble(src)
213
+ src << "\n" unless src[-1] == ?\n
214
+ src << "_ret = @_erb_buf; @_erb_buf = _old_buf; _ret.to_s;\n"
215
+ end
216
+
217
+ def add_text(src, text)
218
+ src << " @_erb_buf.concat('" << escape_text(text) << "'); "
219
+ end
220
+
221
+ def add_expr_escaped(src, code)
222
+ src << ' @_erb_buf.concat(' << escaped_expr(code) << ');'
223
+ end
224
+
225
+ def add_stmt2(src, code, tailch)
226
+ src << code
227
+ src << " ).to_s; " if tailch == "="
228
+ src << ';' unless code[-1] == ?\n
229
+ end
230
+
231
+ def add_expr_literal(src, code)
232
+ if code =~ /(do|\{)(\s*\|[^|]*\|)?\s*\Z/
233
+ src << ' @_erb_buf.concat( ' << code << "; "
234
+ else
235
+ src << ' @_erb_buf.concat((' << code << ').to_s);'
236
+ end
237
+ end
238
+ end
239
+
240
+ class BlockAwareEruby < Eruby
241
+ include BlockAwareEnhancer
242
+ end
243
+
244
+ # module RubyEvaluator
245
+ #
246
+ # # DOC
247
+ # def def_method(object, method_name, filename=nil)
248
+ # m = object.is_a?(Module) ? :module_eval : :instance_eval
249
+ # setup = "@_engine = 'erb'"
250
+ # object.__send__(m, "def #{method_name}(locals={}); #{setup}; #{@src}; end", filename || @filename || '(erubis)')
251
+ # end
252
+ #
253
+ # end
254
+ end
@@ -0,0 +1,8 @@
1
+ begin
2
+ require "extlib"
3
+ rescue LoadError => e
4
+ puts "Merb-core 0.9.4 and later uses extlib for Ruby core class extensions. Install it from github.com/sam/extlib."
5
+ exit
6
+ end
7
+
8
+ require File.dirname(__FILE__) / "core_ext" / "kernel"
@@ -0,0 +1,319 @@
1
+ module Kernel
2
+ # Loads the given string as a gem. Execution is deferred until
3
+ # after the logger has been instantiated and the framework directory
4
+ # structure is defined.
5
+ #
6
+ # If that has already happened, the gem will be activated
7
+ # immediately.
8
+ #
9
+ # ==== Parameters
10
+ # @param name<String> The name of the gem to load.
11
+ # @param *ver<Gem::Requirement, Gem::Version, Array, #to_str>
12
+ # Version requirements to be passed to Gem.activate.
13
+ #
14
+ # ==== Returns
15
+ # Array[String, Array[Gem::Requirement, Gem::Version, Array, #to_str]]::
16
+ # The name and version information that was passed in.
17
+ def dependency(name, *ver)
18
+ if Merb::BootLoader.finished?(Merb::BootLoader::Dependencies)
19
+ load_dependency(name, *ver)
20
+ else
21
+ Merb::BootLoader::Dependencies.dependencies << [name, ver]
22
+ end
23
+ [name, ver]
24
+ end
25
+
26
+ # Loads the given string as a gem.
27
+ #
28
+ # This new version tries to load the file via ROOT/gems first before moving
29
+ # off to the system gems (so if you have a lower version of a gem in
30
+ # ROOT/gems, it'll still get loaded).
31
+ #
32
+ # @param name<String> The name of the gem to load.
33
+ # @param *ver<Gem::Requirement, Gem::Version, Array, #to_str>
34
+ # Version requirements to be passed to Gem.activate.
35
+ #
36
+ # @note
37
+ # If the gem cannot be found, the method will attempt to require the string
38
+ # as a library.
39
+ def load_dependency(name, *ver)
40
+ try_framework = Merb.frozen?
41
+ begin
42
+ # If this is a piece of merb, and we're frozen, try to require
43
+ # first, so we can pick it up from framework/,
44
+ # otherwise try activating the gem
45
+ if name =~ /^merb/ && try_framework
46
+ require name
47
+ else
48
+ gem(name, *ver) if ver
49
+ require name
50
+ Merb.logger.info!("loading gem '#{name}' ...")
51
+ end
52
+ rescue LoadError
53
+ if try_framework
54
+ try_framework = false
55
+ retry
56
+ else
57
+ Merb.logger.info!("loading gem '#{name}' ...")
58
+ # Failed requiring as a gem, let's try loading with a normal require.
59
+ require name
60
+ end
61
+ end
62
+ end
63
+
64
+ # Loads both gem and library dependencies that are passed in as arguments.
65
+ # Execution is deferred to the Merb::BootLoader::Dependencies.run during bootup.
66
+ #
67
+ # @param *args<String, Hash, Array> The dependencies to load.
68
+ def dependencies(*args)
69
+ args.each do |arg|
70
+ case arg
71
+ when String then dependency(arg)
72
+ when Hash then arg.each { |r,v| dependency(r, v) }
73
+ when Array then arg.each { |r| dependency(r) }
74
+ end
75
+ end
76
+ end
77
+
78
+ # Loads both gem and library dependencies that are passed in as arguments.
79
+ #
80
+ # @param *args<String, Hash, Array> The dependencies to load.
81
+ #
82
+ # @note
83
+ # Each argument can be:
84
+ # String:: Single dependency.
85
+ # Hash::
86
+ # Multiple dependencies where the keys are names and the values versions.
87
+ # Array:: Multiple string dependencies.
88
+ #
89
+ # @example dependencies "RedCloth" # Loads the the RedCloth gem
90
+ # @example dependencies "RedCloth", "merb_helpers" # Loads RedCloth and merb_helpers
91
+ # @example dependencies "RedCloth" => "3.0" # Loads RedCloth 3.0
92
+ def load_dependencies(*args)
93
+ args.each do |arg|
94
+ case arg
95
+ when String then load_dependency(arg)
96
+ when Hash then arg.each { |r,v| load_dependency(r, v) }
97
+ when Array then arg.each { |r| load_dependency(r) }
98
+ end
99
+ end
100
+ end
101
+
102
+ # Does a basic require, and prints a message if an error occurs.
103
+ #
104
+ # @param library<to_s> The library to attempt to include.
105
+ # @param message<String> The error to add to the log upon failure. Defaults to nil.
106
+ def rescue_require(library, message = nil)
107
+ require library
108
+ rescue LoadError, RuntimeError
109
+ Merb.logger.error!(message) if message
110
+ end
111
+
112
+ # Used in Merb.root/config/init.rb to tell Merb which ORM (Object Relational
113
+ # Mapper) you wish to use. Currently Merb has plugins to support
114
+ # ActiveRecord, DataMapper, and Sequel.
115
+ #
116
+ # @param orm<#to_s> The ORM to use.
117
+ #
118
+ # @example
119
+ # use_orm :datamapper
120
+ #
121
+ # # This will use the DataMapper generator for your ORM
122
+ # $ merb-gen model ActivityEvent
123
+ #
124
+ # @note
125
+ # If for some reason this is called more than once, latter
126
+ # call takes over other.
127
+ def use_orm(orm)
128
+ begin
129
+ register_orm(orm)
130
+ orm_plugin = "merb_#{orm}"
131
+ Kernel.dependency(orm_plugin)
132
+ rescue LoadError => e
133
+ Merb.logger.warn!("The #{orm_plugin} gem was not found. You may need to install it.")
134
+ raise e
135
+ end
136
+ end
137
+
138
+
139
+ # Registers ORM at generator scope.
140
+ #
141
+ # @param orm<#to_sym>
142
+ # ORM alias, like :activerecord, :datamapper or :sequel.
143
+ #
144
+ # @api private
145
+ def register_orm(orm)
146
+ Merb.orm_generator_scope = orm
147
+ end
148
+
149
+ # Used in Merb.root/config/init.rb to tell Merb which testing framework to
150
+ # use. Currently Merb has plugins to support RSpec and Test::Unit.
151
+ #
152
+ # @param test_framework<Symbol>
153
+ # The test framework to use. Currently only supports :rspec and :test_unit.
154
+ #
155
+ # @example
156
+ # use_test :rspec
157
+ #
158
+ # # This will now use the RSpec generator for tests
159
+ # $ merb-gen model ActivityEvent
160
+ def use_test(test_framework, *test_dependencies)
161
+ raise "use_test only supports :rspec and :test_unit currently" unless supported_test_framework?(test_framework)
162
+ register_test_framework(test_framework)
163
+
164
+ dependencies test_dependencies if Merb.env == "test" || Merb.env.nil?
165
+ end
166
+
167
+ # Check whether Merb supports test framework. Currently Merb has plugins to support RSpec and Test::Unit.
168
+ #
169
+ # @param test_framework<Symbol>
170
+ # The test framework to check. Currently only supports :rspec and :test_unit.
171
+ #
172
+ # @api plugin
173
+ def supported_test_framework?(test_framework)
174
+ [:rspec, :test_unit].include?(test_framework.to_sym)
175
+ end
176
+
177
+ # Register test framework at generator scope. Currently Merb has plugins to support RSpec and Test::Unit.
178
+ #
179
+ # @param test_framework<Symbol>
180
+ # The test framework to check. Currently only supports :rspec and :test_unit but the
181
+ # check is performed before registration if you use API.
182
+ #
183
+ # @api private
184
+ def register_test_framework(test_framework)
185
+ Merb.test_framework_generator_scope = test_framework
186
+ end
187
+
188
+ # @param i<Fixnum> The caller number. Defaults to 1.
189
+ #
190
+ # @return <Array[Array]> The file, line and method of the caller.
191
+ #
192
+ # @example
193
+ # __caller_info__(1)
194
+ # # => ['/usr/lib/ruby/1.8/irb/workspace.rb', '52', 'irb_binding']
195
+ def __caller_info__(i = 1)
196
+ file, line, meth = caller[i].scan(/(.*?):(\d+):in `(.*?)'/).first
197
+ end
198
+
199
+ # @param file<String> The file to read.
200
+ # @param line<Fixnum> The line number to look for.
201
+ # @param size<Fixnum>
202
+ # Number of lines to include above and below the the line to look for.
203
+ # Defaults to 4.
204
+ #
205
+ # @return <Array[Array]>
206
+ # Triplets containing the line number, the line and whether this was the
207
+ # searched line.
208
+ #
209
+ # @example
210
+ # __caller_lines__('/usr/lib/ruby/1.8/debug.rb', 122, 2) # =>
211
+ # [
212
+ # [ 120, " def check_suspend", false ],
213
+ # [ 121, " return if Thread.critical", false ],
214
+ # [ 122, " while (Thread.critical = true; @suspend_next)", true ],
215
+ # [ 123, " DEBUGGER__.waiting.push Thread.current", false ],
216
+ # [ 124, " @suspend_next = false", false ]
217
+ # ]
218
+ def __caller_lines__(file, line, size = 4)
219
+ return [['Template Error!', "problem while rendering", false]] if file =~ /\(erubis\)/
220
+ lines = File.readlines(file)
221
+ current = line.to_i - 1
222
+
223
+ first = current - size
224
+ first = first < 0 ? 0 : first
225
+
226
+ last = current + size
227
+ last = last > lines.size ? lines.size : last
228
+
229
+ log = lines[first..last]
230
+
231
+ area = []
232
+
233
+ log.each_with_index do |line, index|
234
+ index = index + first + 1
235
+ area << [index, line.chomp, index == current + 1]
236
+ end
237
+
238
+ area
239
+ end
240
+
241
+ # Takes a block, profiles the results of running the block
242
+ # specified number of times and generates HTML report.
243
+ #
244
+ # @param name<#to_s>
245
+ # The file name. The result will be written out to
246
+ # Merb.root/"log/#{name}.html".
247
+ # @param min<Fixnum>
248
+ # Minimum percentage of the total time a method must take for it to be
249
+ # included in the result. Defaults to 1.
250
+ #
251
+ # @return <String>
252
+ # The result of the profiling.
253
+ #
254
+ # @note
255
+ # Requires ruby-prof (<tt>sudo gem install ruby-prof</tt>)
256
+ #
257
+ # @example
258
+ # __profile__("MyProfile", 5, 30) do
259
+ # rand(10)**rand(10)
260
+ # puts "Profile run"
261
+ # end
262
+ #
263
+ # Assuming that the total time taken for #puts calls was less than 5% of the
264
+ # total time to run, #puts won't appear in the profile report.
265
+ # The code block will be run 30 times in the example above.
266
+ def __profile__(name, min=1, iter=100)
267
+ require 'ruby-prof' unless defined?(RubyProf)
268
+ return_result = ''
269
+ result = RubyProf.profile do
270
+ iter.times{return_result = yield}
271
+ end
272
+ printer = RubyProf::GraphHtmlPrinter.new(result)
273
+ path = File.join(Merb.root, 'log', "#{name}.html")
274
+ File.open(path, 'w') do |file|
275
+ printer.print(file, {:min_percent => min,
276
+ :print_file => true})
277
+ end
278
+ return_result
279
+ end
280
+
281
+ # Extracts an options hash if it is the last item in the args array. Used
282
+ # internally in methods that take *args.
283
+ #
284
+ # @param args<Array> The arguments to extract the hash from.
285
+ #
286
+ # @example
287
+ # def render(*args,&blk)
288
+ # opts = extract_options_from_args!(args) || {}
289
+ # # [...]
290
+ # end
291
+ def extract_options_from_args!(args)
292
+ args.pop if Hash === args.last
293
+ end
294
+
295
+ # Checks that the given objects quack like the given conditions.
296
+ #
297
+ # @param opts<Hash>
298
+ # Conditions to enforce. Each key will receive a quacks_like? call with the
299
+ # value (see Object#quacks_like? for details).
300
+ #
301
+ # @raise <ArgumentError>
302
+ # An object failed to quack like a condition.
303
+ def enforce!(opts = {})
304
+ opts.each do |k,v|
305
+ raise ArgumentError, "#{k.inspect} doesn't quack like #{v.inspect}" unless k.quacks_like?(v)
306
+ end
307
+ end
308
+
309
+ unless Kernel.respond_to?(:debugger)
310
+
311
+ # Define debugger method so that code even works if debugger was not
312
+ # requested. Drops a note to the logs that Debugger was not available.
313
+ def debugger
314
+ Merb.logger.info! "\n***** Debugger requested, but was not " +
315
+ "available: Start server with --debugger " +
316
+ "to enable *****\n"
317
+ end
318
+ end
319
+ end