merb 0.5.3 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. data/LICENSE +0 -20
  2. data/README +0 -277
  3. data/Rakefile +80 -199
  4. data/TODO +0 -3
  5. metadata +19 -438
  6. data/SVN_REVISION +0 -1
  7. data/app_generators/merb/USAGE +0 -5
  8. data/app_generators/merb/merb_generator.rb +0 -108
  9. data/app_generators/merb/templates/Rakefile +0 -124
  10. data/app_generators/merb/templates/app/controllers/application.rb +0 -3
  11. data/app_generators/merb/templates/app/controllers/exceptions.rb +0 -13
  12. data/app_generators/merb/templates/app/helpers/global_helper.rb +0 -5
  13. data/app_generators/merb/templates/app/mailers/views/layout/application.html.erb +0 -1
  14. data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +0 -1
  15. data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +0 -1
  16. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +0 -216
  17. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +0 -38
  18. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +0 -40
  19. data/app_generators/merb/templates/app/views/layout/application.html.erb +0 -11
  20. data/app_generators/merb/templates/config/boot.rb +0 -11
  21. data/app_generators/merb/templates/config/dependencies.rb +0 -41
  22. data/app_generators/merb/templates/config/environments/development.rb +0 -1
  23. data/app_generators/merb/templates/config/environments/production.rb +0 -1
  24. data/app_generators/merb/templates/config/environments/test.rb +0 -1
  25. data/app_generators/merb/templates/config/merb.yml +0 -82
  26. data/app_generators/merb/templates/config/merb_init.rb +0 -17
  27. data/app_generators/merb/templates/config/plugins.yml +0 -1
  28. data/app_generators/merb/templates/config/router.rb +0 -35
  29. data/app_generators/merb/templates/config/upload.conf +0 -0
  30. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  31. data/app_generators/merb/templates/public/merb.fcgi +0 -6
  32. data/app_generators/merb/templates/public/stylesheets/master.css +0 -119
  33. data/app_generators/merb/templates/script/destroy +0 -32
  34. data/app_generators/merb/templates/script/generate +0 -32
  35. data/app_generators/merb/templates/script/stop_merb +0 -13
  36. data/app_generators/merb/templates/script/win_script.cmd +0 -1
  37. data/app_generators/merb/templates/spec/spec.opts +0 -6
  38. data/app_generators/merb/templates/spec/spec_helper.rb +0 -15
  39. data/app_generators/merb/templates/test/test_helper.rb +0 -14
  40. data/app_generators/merb_plugin/USAGE +0 -5
  41. data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -68
  42. data/app_generators/merb_plugin/templates/LICENSE +0 -20
  43. data/app_generators/merb_plugin/templates/README +0 -4
  44. data/app_generators/merb_plugin/templates/Rakefile +0 -35
  45. data/app_generators/merb_plugin/templates/TODO +0 -5
  46. data/app_generators/merb_plugin/templates/merbtasks.rb +0 -6
  47. data/app_generators/merb_plugin/templates/sampleplugin.rb +0 -10
  48. data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +0 -7
  49. data/app_generators/merb_plugin/templates/spec_helper.rb +0 -2
  50. data/bin/merb +0 -4
  51. data/lib/autotest/discover.rb +0 -3
  52. data/lib/autotest/merb_rspec.rb +0 -80
  53. data/lib/merb.rb +0 -188
  54. data/lib/merb/abstract_controller.rb +0 -399
  55. data/lib/merb/assets.rb +0 -160
  56. data/lib/merb/assets.rb.orig +0 -119
  57. data/lib/merb/boot_loader.rb +0 -286
  58. data/lib/merb/boot_loader.rb.orig +0 -235
  59. data/lib/merb/caching.rb +0 -5
  60. data/lib/merb/caching/action_cache.rb +0 -92
  61. data/lib/merb/caching/fragment_cache.rb +0 -39
  62. data/lib/merb/caching/store/file_cache.rb +0 -90
  63. data/lib/merb/caching/store/memory_cache.rb +0 -85
  64. data/lib/merb/config.rb +0 -290
  65. data/lib/merb/constants.rb +0 -50
  66. data/lib/merb/controller.rb +0 -220
  67. data/lib/merb/cookies.rb +0 -95
  68. data/lib/merb/core_ext.rb +0 -15
  69. data/lib/merb/core_ext/array.rb +0 -0
  70. data/lib/merb/core_ext/class.rb +0 -180
  71. data/lib/merb/core_ext/enumerable.rb +0 -49
  72. data/lib/merb/core_ext/get_args.rb +0 -76
  73. data/lib/merb/core_ext/hash.rb +0 -306
  74. data/lib/merb/core_ext/inflections.rb +0 -112
  75. data/lib/merb/core_ext/inflector.rb +0 -275
  76. data/lib/merb/core_ext/kernel.rb +0 -242
  77. data/lib/merb/core_ext/mash.rb +0 -88
  78. data/lib/merb/core_ext/module.rb +0 -67
  79. data/lib/merb/core_ext/numeric.rb +0 -72
  80. data/lib/merb/core_ext/object.rb +0 -183
  81. data/lib/merb/core_ext/string.rb +0 -53
  82. data/lib/merb/core_ext/symbol.rb +0 -6
  83. data/lib/merb/dispatcher.rb +0 -109
  84. data/lib/merb/drb_server.rb +0 -19
  85. data/lib/merb/erubis_ext.rb +0 -10
  86. data/lib/merb/exceptions.rb +0 -192
  87. data/lib/merb/generators/merb_app/merb_app.rb +0 -22
  88. data/lib/merb/generators/merb_generator_helpers.rb +0 -318
  89. data/lib/merb/generators/merb_plugin.rb +0 -22
  90. data/lib/merb/logger.rb +0 -78
  91. data/lib/merb/mail_controller.rb +0 -268
  92. data/lib/merb/mailer.rb +0 -87
  93. data/lib/merb/mixins/basic_authentication.rb +0 -35
  94. data/lib/merb/mixins/controller.rb +0 -160
  95. data/lib/merb/mixins/erubis_capture.rb +0 -68
  96. data/lib/merb/mixins/general_controller.rb +0 -253
  97. data/lib/merb/mixins/inline_partial.rb +0 -32
  98. data/lib/merb/mixins/render.rb +0 -465
  99. data/lib/merb/mixins/responder.rb +0 -449
  100. data/lib/merb/mixins/view_context.rb +0 -558
  101. data/lib/merb/mixins/web_controller.rb +0 -36
  102. data/lib/merb/mongrel_handler.rb +0 -168
  103. data/lib/merb/part_controller.rb +0 -29
  104. data/lib/merb/plugins.rb +0 -16
  105. data/lib/merb/rack_adapter.rb +0 -37
  106. data/lib/merb/request.rb +0 -465
  107. data/lib/merb/router.rb +0 -646
  108. data/lib/merb/server.rb +0 -169
  109. data/lib/merb/session.rb +0 -23
  110. data/lib/merb/session/cookie_store.rb +0 -118
  111. data/lib/merb/session/mem_cache_session.rb +0 -131
  112. data/lib/merb/session/memory_session.rb +0 -176
  113. data/lib/merb/template.rb +0 -37
  114. data/lib/merb/template/erubis.rb +0 -68
  115. data/lib/merb/template/haml.rb +0 -87
  116. data/lib/merb/template/markaby.rb +0 -59
  117. data/lib/merb/template/xml_builder.rb +0 -50
  118. data/lib/merb/test/fake_request.rb +0 -74
  119. data/lib/merb/test/helper.rb +0 -260
  120. data/lib/merb/test/hpricot.rb +0 -136
  121. data/lib/merb/test/multipart.rb +0 -66
  122. data/lib/merb/test/rspec.rb +0 -18
  123. data/lib/merb/test/rspec_matchers/controller_matchers.rb +0 -117
  124. data/lib/merb/test/rspec_matchers/markup_matchers.rb +0 -98
  125. data/lib/merb/upload_handler.rb +0 -80
  126. data/lib/merb/upload_progress.rb +0 -48
  127. data/lib/merb/version.rb +0 -49
  128. data/lib/merb/view_context.rb +0 -79
  129. data/lib/tasks.rb +0 -7
  130. data/lib/tasks/merb.rake +0 -54
  131. data/merb_default_generators/model/USAGE +0 -0
  132. data/merb_default_generators/model/model_generator.rb +0 -16
  133. data/merb_default_generators/model/templates/new_model_template.erb +0 -5
  134. data/merb_default_generators/resource_controller/USAGE +0 -0
  135. data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -26
  136. data/merb_default_generators/resource_controller/templates/controller.rb +0 -30
  137. data/merb_default_generators/resource_controller/templates/edit.html.erb +0 -1
  138. data/merb_default_generators/resource_controller/templates/helper.rb +0 -5
  139. data/merb_default_generators/resource_controller/templates/index.html.erb +0 -1
  140. data/merb_default_generators/resource_controller/templates/new.html.erb +0 -1
  141. data/merb_default_generators/resource_controller/templates/show.html.erb +0 -1
  142. data/merb_generators/controller/USAGE +0 -5
  143. data/merb_generators/controller/controller_generator.rb +0 -16
  144. data/merb_generators/controller/templates/controller.rb +0 -8
  145. data/merb_generators/controller/templates/helper.rb +0 -5
  146. data/merb_generators/controller/templates/index.html.erb +0 -3
  147. data/merb_generators/part_controller/USAGE +0 -5
  148. data/merb_generators/part_controller/part_controller_generator.rb +0 -27
  149. data/merb_generators/part_controller/templates/controller.rb +0 -8
  150. data/merb_generators/part_controller/templates/helper.rb +0 -5
  151. data/merb_generators/part_controller/templates/index.html.erb +0 -3
  152. data/merb_generators/resource/USAGE +0 -0
  153. data/merb_generators/resource/resource_generator.rb +0 -67
  154. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -67
  155. data/rspec_generators/merb_controller_test/templates/controller_spec.rb +0 -8
  156. data/rspec_generators/merb_controller_test/templates/edit_spec.rb +0 -12
  157. data/rspec_generators/merb_controller_test/templates/helper_spec.rb +0 -5
  158. data/rspec_generators/merb_controller_test/templates/index_spec.rb +0 -12
  159. data/rspec_generators/merb_controller_test/templates/new_spec.rb +0 -12
  160. data/rspec_generators/merb_controller_test/templates/show_spec.rb +0 -5
  161. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -26
  162. data/rspec_generators/merb_model_test/templates/model_spec_template.erb +0 -7
  163. data/script/destroy +0 -14
  164. data/script/generate +0 -14
  165. data/spec/fixtures/config/environments/environment_config_test.yml +0 -1
  166. data/spec/fixtures/config/merb.yml +0 -18
  167. data/spec/fixtures/controllers/dispatch_spec_controllers.rb +0 -235
  168. data/spec/fixtures/controllers/render_spec_controllers.rb +0 -184
  169. data/spec/fixtures/foo.rb +0 -3
  170. data/spec/fixtures/mailers/views/layout/application.html.erb +0 -3
  171. data/spec/fixtures/mailers/views/layout/application.text.erb +0 -3
  172. data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +0 -1
  173. data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +0 -1
  174. data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +0 -1
  175. data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +0 -1
  176. data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +0 -1
  177. data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +0 -1
  178. data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +0 -1
  179. data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +0 -1
  180. data/spec/fixtures/models/router_spec_models.rb +0 -30
  181. data/spec/fixtures/parts/views/layout/todo_part.html.erb +0 -3
  182. data/spec/fixtures/parts/views/layout/todo_part.xml.erb +0 -3
  183. data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +0 -1
  184. data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +0 -1
  185. data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +0 -1
  186. data/spec/fixtures/parts/views/todo_part/list.html.erb +0 -3
  187. data/spec/fixtures/sample.txt +0 -1
  188. data/spec/fixtures/views/erubis.html.erb +0 -1
  189. data/spec/fixtures/views/examples/_erubis.html.erb +0 -1
  190. data/spec/fixtures/views/examples/_haml.html.haml +0 -1
  191. data/spec/fixtures/views/examples/_markaby.html.mab +0 -1
  192. data/spec/fixtures/views/examples/_throw_content.html.erb +0 -6
  193. data/spec/fixtures/views/examples/hello.xml.builder +0 -1
  194. data/spec/fixtures/views/examples/js.js.erb +0 -1
  195. data/spec/fixtures/views/examples/template_catch_content.html.erb +0 -15
  196. data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +0 -6
  197. data/spec/fixtures/views/examples/template_throw_content.html.erb +0 -10
  198. data/spec/fixtures/views/examples/template_throw_content_without_block.html.erb +0 -3
  199. data/spec/fixtures/views/exceptions/admin_access_required.html.erb +0 -1
  200. data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +0 -1
  201. data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +0 -1
  202. data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +0 -1
  203. data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +0 -1
  204. data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +0 -1
  205. data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +0 -1
  206. data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +0 -1
  207. data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
  208. data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +0 -1
  209. data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +0 -1
  210. data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +0 -1
  211. data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
  212. data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
  213. data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +0 -1
  214. data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +0 -1
  215. data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +0 -1
  216. data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +0 -4
  217. data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +0 -1
  218. data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +0 -1
  219. data/spec/fixtures/views/haml.html.haml +0 -1
  220. data/spec/fixtures/views/haml.xml.haml +0 -2
  221. data/spec/fixtures/views/layout/application.html.erb +0 -1
  222. data/spec/fixtures/views/layout/application.xml.erb +0 -1
  223. data/spec/fixtures/views/layout/nested/example.html.erb +0 -1
  224. data/spec/fixtures/views/markaby.html.mab +0 -1
  225. data/spec/fixtures/views/nested/example/test.html.erb +0 -1
  226. data/spec/fixtures/views/partials/_erubis.html.erb +0 -1
  227. data/spec/fixtures/views/partials/_erubis_collection.html.erb +0 -1
  228. data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +0 -1
  229. data/spec/fixtures/views/partials/_erubis_new.html.erb +0 -1
  230. data/spec/fixtures/views/partials/_haml.html.haml +0 -1
  231. data/spec/fixtures/views/partials/_haml_collection.html.haml +0 -1
  232. data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +0 -1
  233. data/spec/fixtures/views/partials/_haml_new.html.haml +0 -1
  234. data/spec/fixtures/views/partials/_markaby.html.mab +0 -1
  235. data/spec/fixtures/views/partials/_markaby_collection.html.mab +0 -1
  236. data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +0 -1
  237. data/spec/fixtures/views/partials/_markaby_new.html.mab +0 -1
  238. data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +0 -1
  239. data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +0 -1
  240. data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +0 -1
  241. data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +0 -4
  242. data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +0 -7
  243. data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +0 -7
  244. data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +0 -15
  245. data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +0 -15
  246. data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +0 -4
  247. data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +0 -12
  248. data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +0 -11
  249. data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +0 -14
  250. data/spec/fixtures/views/test.dir/the_template.html.erb +0 -1
  251. data/spec/merb/abstract_controller_spec.rb +0 -38
  252. data/spec/merb/assets_spec.rb +0 -207
  253. data/spec/merb/caching_spec.rb +0 -102
  254. data/spec/merb/config_spec.rb +0 -29
  255. data/spec/merb/controller_filters_spec.rb +0 -253
  256. data/spec/merb/controller_spec.rb +0 -126
  257. data/spec/merb/cookie_store_spec.rb +0 -72
  258. data/spec/merb/cookies_spec.rb +0 -96
  259. data/spec/merb/core_ext/class_spec.rb +0 -97
  260. data/spec/merb/core_ext/enumerable_spec.rb +0 -27
  261. data/spec/merb/core_ext/hash_spec.rb +0 -251
  262. data/spec/merb/core_ext/inflector_spec.rb +0 -34
  263. data/spec/merb/core_ext/kernel_spec.rb +0 -25
  264. data/spec/merb/core_ext/numeric_spec.rb +0 -26
  265. data/spec/merb/core_ext/object_spec.rb +0 -47
  266. data/spec/merb/core_ext/string_spec.rb +0 -22
  267. data/spec/merb/core_ext/symbol_spec.rb +0 -7
  268. data/spec/merb/dependency_spec.rb +0 -22
  269. data/spec/merb/dispatch_spec.rb +0 -528
  270. data/spec/merb/fake_request_spec.rb +0 -80
  271. data/spec/merb/generator_spec.rb +0 -248
  272. data/spec/merb/handler_spec.rb +0 -169
  273. data/spec/merb/mail_controller_spec.rb +0 -177
  274. data/spec/merb/mailer_spec.rb +0 -87
  275. data/spec/merb/multipart_spec.rb +0 -50
  276. data/spec/merb/part_controller_spec.rb +0 -124
  277. data/spec/merb/plugins_spec.rb +0 -80
  278. data/spec/merb/render_spec.rb +0 -469
  279. data/spec/merb/request_spec.rb +0 -287
  280. data/spec/merb/responder_spec.rb +0 -562
  281. data/spec/merb/router_spec.rb +0 -900
  282. data/spec/merb/server_spec.rb +0 -19
  283. data/spec/merb/template_spec.rb +0 -41
  284. data/spec/merb/upload_handler_spec.rb +0 -108
  285. data/spec/merb/version_spec.rb +0 -33
  286. data/spec/merb/view_context_spec.rb +0 -366
  287. data/spec/spec_generator_helper.rb +0 -34
  288. data/spec/spec_helper.rb +0 -101
  289. data/spec/spec_helpers/url_shared_behaviour.rb +0 -112
  290. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -53
  291. data/test_unit_generators/merb_controller_test/templates/functional_test.rb +0 -17
  292. data/test_unit_generators/merb_controller_test/templates/helper_test.rb +0 -9
  293. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -29
  294. data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +0 -9
@@ -1,399 +0,0 @@
1
- module Merb
2
-
3
- class AbstractController
4
- include Merb::RenderMixin
5
- include Merb::GeneralControllerMixin
6
-
7
- class_inheritable_accessor :before_filters
8
- class_inheritable_accessor :after_filters
9
- class_inheritable_accessor :action_argument_list
10
- self.action_argument_list = Hash.new([])
11
-
12
- cattr_accessor :_abstract_subclasses
13
- cattr_accessor :_template_path_cache
14
- self._abstract_subclasses = []
15
- self._template_path_cache
16
-
17
- class << self
18
- def inherited(klass)
19
- _abstract_subclasses << klass.to_s unless _abstract_subclasses.include?(klass.to_s)
20
- super
21
- end
22
- end
23
-
24
- # Holds internal execution times. Prefaced with an underscore to not
25
- # conflict with user-defined controller instance variables.
26
- attr_accessor :_benchmarks, :thrown_content
27
-
28
- def initialize(*args)
29
- @_benchmarks = {}
30
- @thrown_content = AbstractController.default_thrown_content
31
- end
32
-
33
- def dispatch(action=:to_s)
34
- caught = catch(:halt) do
35
- start = Time.now
36
- result = call_filters(before_filters)
37
- @_benchmarks[:before_filters_time] = Time.now - start if before_filters
38
- result
39
- end
40
-
41
- @_body = case caught
42
- when :filter_chain_completed
43
- call_action(action)
44
- when String
45
- caught
46
- when nil
47
- filters_halted
48
- when Symbol
49
- send(caught)
50
- when Proc
51
- caught.call(self)
52
- else
53
- raise MerbControllerError, "The before filter chain is broken dude. wtf?"
54
- end
55
- start = Time.now
56
- call_filters(after_filters)
57
- @_benchmarks[:after_filters_time] = Time.now - start if after_filters
58
- end
59
-
60
-
61
- # Adds the a template path to the template path cache. This is required for
62
- # any view templates or layouts to be found during renering.
63
- #
64
- # ==== Parameters
65
- # template_path<String>:: Full path to the template file.
66
- #
67
- # ==== Returns
68
- # Boolean:: true unless the template path is less than three levels deep.
69
- #
70
- # ==== Examples
71
- # Merb::AbstractController.add_path_to_template_cache('/full/path/to/template.html.erb')
72
- #
73
- def self.add_path_to_template_cache(template_path)
74
- arry = template_path.split("/").last.split(".")
75
- return false if template_path == "" || arry.size != 3
76
- key = template_path.split(".")[0..-2].join(".")
77
- self._template_path_cache[key] = template_path
78
- end
79
-
80
- # Resets the template_path_cache to an empty hash
81
- #
82
- def self.reset_template_path_cache!
83
- self._template_path_cache = {}
84
- end
85
-
86
- protected
87
-
88
- def call_action(action)
89
- # [[:id], [:foo, 7]]
90
- args = self.class.action_argument_list[action.to_sym].map do |arg_default|
91
- arg = arg_default[0]
92
- raise BadRequest unless params.key?(arg.to_sym) || (arg_default.size == 2)
93
- params.key?(arg.to_sym) ? params[arg.to_sym] : arg_default[1]
94
- end rescue []
95
- send(action, *args)
96
- end
97
-
98
- # Calls a filter chain according to rules.
99
- #
100
- # ==== Parameters
101
- # filter_set<Array>:: Array of filter-rule pairs as two piece arrays.
102
- #
103
- # ==== Returns
104
- # Symbol:: :filter_chain_completed to signify execution is completed.
105
- #
106
- def call_filters(filter_set)
107
- (filter_set || []).each do |(filter, rule)|
108
- ok = false
109
- if rule.has_key?(:only)
110
- if rule[:only].include?(params[:action].intern)
111
- ok = true
112
- end
113
- elsif rule.has_key?(:exclude)
114
- if !rule[:exclude].include?(params[:action].intern)
115
- ok = true
116
- end
117
- else
118
- ok = true
119
- end
120
- if ok
121
- case filter
122
- when Symbol, String
123
- send(filter)
124
- when Proc
125
- filter.call(self)
126
- end
127
- end
128
- end
129
- return :filter_chain_completed
130
- end
131
-
132
- # +finalize_session+ is called at the end of a request to finalize/store
133
- # any data placed in the session. Mixins/Classes wishing to define a new
134
- # session store must implement this method. See merb/lib/sessions/*
135
- # for examples of built in session stores.
136
- def finalize_session #:nodoc:
137
- # noop
138
- end
139
-
140
- # +setup_session+ is called at the beginning of a request to load the
141
- # current session data. Mixins/Classes wishing to define a new session
142
- # store must implement this method. See merb/lib/sessions/* for examples
143
- # of built in session stores.
144
- def setup_session #:nodoc:
145
- # noop
146
- end
147
-
148
- # Override this method on your controller classes to specialize
149
- # the output when the filter chain is halted.
150
- #
151
- # ==== Returns
152
- # String:: A message explaining what happened.
153
- #
154
- def filters_halted
155
- "<html><body><h1>Filter Chain Halted!</h1></body></html>"
156
- end
157
-
158
-
159
- # Specify before filters in your controllers. If a method name is given
160
- # that method will be called and if a proc is given it will be called
161
- # with an argument of self where self is the current controller object.
162
- # When you use a proc as a filter it needs to take one parameter.
163
- #
164
- # Merb's before filter chain is very flexible. To halt the filter chain you
165
- # use throw :halt. If throw is called with only one argument of :halt the
166
- # return of the method filters_halted will be what is rendered to the view.
167
- # You can overide filters_halted in your own controllers to control what it
168
- # outputs. But the throw construct is much more powerful then just that.
169
- # throw :halt can also take a second argument. Here is what that second arg
170
- # can be and the behavior each type can have:
171
- #
172
- # * String:
173
- # when the second arg is a string then that string will be what
174
- # is rendered to the browser. Since merb's render method returns
175
- # a string you can render a template or just use a plain string:
176
- #
177
- # throw :halt, "You don't have permissions to do that!"
178
- # throw :halt, render(:action => :access_denied)
179
- #
180
- # * Symbol:
181
- # If the second arg is a symbol then the method named after that
182
- # symbol will be called
183
- #
184
- # throw :halt, :must_click_disclaimer
185
- #
186
- # * Proc:
187
- #
188
- # If the second arg is a Proc, it will be called and its return
189
- # value will be what is rendered to the browser:
190
- #
191
- # throw :halt, Proc.new {|c| c.access_denied }
192
- # throw :halt, Proc.new {|c| Tidy.new(c.index) }
193
- #
194
- # ==== Parameters
195
- # filter<Symbol, String, Proc>:: The filter to be added.
196
- # opts<Hash>::
197
- # The options for the filter to be added (see below). Defaults to an
198
- # empty Hash.
199
- #
200
- # ==== Options (opts)
201
- # :only<Array, Symbol>:: The actions that the filter should be applied to.
202
- # :exclude<Array, Symbol>:: The actions that should ignore this filter.
203
- #
204
- # Note: :only and :exluce cannot be used simultaneously.
205
- #
206
- # ==== Examples
207
- # before :some_filter
208
- # before :authenticate, :exclude => [:login, :signup]
209
- # before Proc.new {|c| c.some_method }, :only => :foo
210
- #
211
- def self.before(filter, opts={})
212
- add_filter((self.before_filters ||= []), filter, opts)
213
- end
214
-
215
- # Specify after filters in your controllers. If a method name is given
216
- # that method will be called and if a proc is given it will be called
217
- # with an argument of self where self is the current controller object.
218
- # When you use a proc as a filter it needs to take one parameter.
219
- #
220
- # ==== Parameters
221
- # filter<Symbol, String, Proc>:: The filter to be added.
222
- # opts<Hash>::
223
- # The options for the filter to be added (see below). Defaults to an
224
- # empty Hash.
225
- #
226
- # ==== Options (opts)
227
- # :only<Array, Symbol>:: The actions that the filter should be applied to.
228
- # :exclude<Array, Symbol>:: The actions that should ignore this filter.
229
- #
230
- # Note: :only and :exluce cannot be used simultaneously.
231
- #
232
- # ==== Examples
233
- # after :some_filter
234
- # after :tidy, :exclude => [:stats]
235
- # before Proc.new {|c| c.some_method }, :only => :foo
236
- #
237
- def self.after(filter, opts={})
238
- add_filter((self.after_filters ||= []), filter, opts)
239
- end
240
-
241
- # Remove an already declared before filter from your controller.
242
- #
243
- # ==== Parameters
244
- # filter<String, Symbol>:: The filter to be removed.
245
- #
246
- # ==== Examples
247
- # class Application < Merb::Controller
248
- # before :require_login
249
- # end
250
- #
251
- # class Login < Application
252
- # skip_before :require_login # Login should be accessible by everyone
253
- # end
254
- #
255
- def self.skip_before(filter)
256
- skip_filter((self.before_filters || []), filter)
257
- end
258
-
259
- # Remove an already declared after filter from your controller.
260
- #
261
- # ==== Parameters
262
- # filter<String, Symbol>:: The filter to be removed.
263
- #
264
- # ==== Examples
265
- # class Application < Merb::Controller
266
- # after :log_activitiy
267
- # end
268
- #
269
- # class Stats < Application
270
- # skip_after :log_activitiy
271
- # end
272
- #
273
- def self.skip_after(filter)
274
- skip_filter((self.after_filters || []), filter)
275
- end
276
-
277
- def self.default_thrown_content
278
- Hash.new{ |hash, key| hash[key] = "" }
279
- end
280
-
281
- # Set here to respond when rendering to cover the provides syntax of
282
- # setting the content_type
283
- #
284
- # ==== Returns
285
- # Boolean:: True if the content type was set.
286
- #
287
- def content_type_set?
288
- false
289
- end
290
-
291
- # Returns the content type.
292
- #
293
- # ==== Returns
294
- # Symbol:: The content type.
295
- #
296
- def content_type
297
- params[:format] || :html
298
- end
299
-
300
- private
301
-
302
- # Adds a filter to a list of filters.
303
- #
304
- # ==== Parameters
305
- # filters<Array>::
306
- # The array of filters to which the filter should be added.
307
- # filter<Symbol, String, Proc>:: The filter to be added.
308
- # opts<Hash>::
309
- # The options for the filter to be added (see below). Defaults to an
310
- # empty Hash.
311
- #
312
- # ==== Options (opts)
313
- # :only<Array, Symbol>:: The actions that the filter should be applied to.
314
- # :exclude<Array, Symbol>:: The actions that should ignore this filter.
315
- #
316
- # ==== Raises
317
- # ArgumentError::
318
- # The options include both the :only and the :exclude key or the filter
319
- # is not a Symbol, String or Proc.
320
- #
321
- # ==== Examples
322
- # add_filter([ :log_activity ], :login_required)
323
- #
324
- # add_filter([ :log_activity ], :login_required, { :exclude => :login })
325
- #
326
- def self.add_filter(filters, filter, opts={})
327
- raise(ArgumentError,
328
- "You can specify either :only or :exclude but
329
- not both at the same time for the same filter."
330
- ) if opts.has_key?(:only) && opts.has_key?(:exclude)
331
-
332
- opts = shuffle_filters!(opts)
333
-
334
- case filter
335
- when Symbol, Proc, String
336
- if existing_filter = filters.find {|f| f.first.to_s[filter.to_s]}
337
- existing_filter.last.replace(opts)
338
- else
339
- filters << [filter, opts]
340
- end
341
- else
342
- raise(ArgumentError,
343
- 'Filters need to be either a Symbol, String or a Proc'
344
- )
345
- end
346
- end
347
-
348
- # Removes a filter from a list of filters.
349
- #
350
- # ==== Parameters
351
- # filters<Array>::
352
- # The array of filters from which the filter should be removed.
353
- # filter<Symbol, String>:: The filter to be removed.
354
- #
355
- # ==== Raises
356
- # ArgumentError:: The filter argument is not a String or a Symbol.
357
- #
358
- # ==== Examples
359
- # skip_filter([ :login_required, :log_activity ], :login_required)
360
- #
361
- def self.skip_filter(filters, filter)
362
- raise(ArgumentError,
363
- 'You can only skip filters that have a String or Symbol name.'
364
- ) unless [Symbol, String].include? filter.class
365
-
366
- Merb.logger.warn("Filter #{filter} was not found in your filter chain."
367
- ) unless filters.reject! {|f| f.first.to_s[filter.to_s] }
368
- end
369
-
370
- # Changes filter options hash values for the only and exclude keys to
371
- # arrays, if they are not arrays already.
372
- #
373
- # ==== Parameters
374
- # opts<Hash>:: The filter options hash. Will default to an empty Hash.
375
- #
376
- # ==== Options (opts)
377
- # :only<Array, Symbol>:: The actions that the filter should be applied to.
378
- # :exclude<Array, Symbol>:: The actions that should ignore this filter.
379
- #
380
- # ==== Returns
381
- # Hash:: The original options with the only and exclude values as arrays.
382
- #
383
- # ==== Examples
384
- # shuffle_filters!(:only => :new)
385
- # # => { :only => [:new] }
386
- #
387
- def self.shuffle_filters!(opts={})
388
- if opts[:only] && opts[:only].is_a?(Symbol)
389
- opts[:only] = [opts[:only]]
390
- end
391
- if opts[:exclude] && opts[:exclude].is_a?(Symbol)
392
- opts[:exclude] = [opts[:exclude]]
393
- end
394
- return opts
395
- end
396
-
397
- end
398
-
399
- end
data/lib/merb/assets.rb DELETED
@@ -1,160 +0,0 @@
1
- module Merb
2
- module Assets
3
-
4
- # Check whether the assets should be bundled.
5
- #
6
- # ==== Returns
7
- # Boolean::
8
- # True if the assets should be bundled (e.g., production mode or
9
- # :bundle_assets is explicitly enabled).
10
- #
11
- def self.bundle?
12
- (Merb::Config[:environment].to_s == 'production') ||
13
- (!!Merb::Config[:bundle_assets])
14
- end
15
-
16
- # Helpers for handling asset files.
17
- module AssetHelpers
18
- # :nodoc:
19
- ASSET_FILE_EXTENSIONS = {
20
- :javascript => ".js",
21
- :stylesheet => ".css"
22
- }
23
-
24
- # Returns the URI path to a particular asset file. If +local_path+ is
25
- # true, returns the path relative to the Merb.root, not the public
26
- # directory. Uses the path_prefix, if any is configured.
27
- #
28
- # ==== Parameters
29
- # asset_type<Symbol>:: Type of the asset (e.g. :javascript).
30
- # filename<~to_s>:: The path to the file.
31
- #
32
- # local_path<Boolean>::
33
- # If true, the returned path will be relative to the Merb.root,
34
- # otherwise it will be the public URI path. Defaults to false.
35
- #
36
- # ==== Returns
37
- # String:: The path to the asset.
38
- #
39
- # ==== Examples
40
- # asset_path(:javascript, :dingo)
41
- # # => "/javascripts/dingo.js"
42
- #
43
- # asset_path(:javascript, :dingo, true)
44
- # # => "public/javascripts/dingo.js"
45
- #
46
- def asset_path(asset_type, filename, local_path = false)
47
- filename = filename.to_s
48
- if filename !~ /#{'\\' + ASSET_FILE_EXTENSIONS[asset_type]}\Z/
49
- filename << ASSET_FILE_EXTENSIONS[asset_type]
50
- end
51
- filename = "/#{asset_type}s/#{filename}"
52
- if local_path
53
- return "public#{filename}"
54
- else
55
- return "#{Merb::Config[:path_prefix]}#{filename}"
56
- end
57
- end
58
- end
59
-
60
- # An abstract class for bundling text assets into single files.
61
- class AbstractAssetBundler
62
- class << self
63
-
64
- # Add a post-bundle callback.
65
- #
66
- # ==== Examples
67
- # add_callback { |filename| `yuicompressor #{filename}` }
68
- #
69
- def add_callback(&block)
70
- callbacks << block
71
- end
72
- alias_method :after_bundling, :add_callback
73
-
74
- # Retrieve existing callbacks.
75
- #
76
- # ==== Returns
77
- # Array:: An array of existing callbacks.
78
- #
79
- def callbacks
80
- @callbacks ||= []
81
- return @callbacks
82
- end
83
-
84
- # The type of asset for which the bundler is responsible. Override
85
- # this method in your bundler code.
86
- #
87
- # ==== Raises
88
- # NotImplementedError::
89
- # If this method has not been implemented by the bundler.
90
- #
91
- # ==== Returns
92
- # Symbol:: The type of the asset
93
- #
94
- def asset_type
95
- raise NotImplementedError, "should return a symbol for the first argument to be passed to asset_path"
96
- end
97
- end
98
-
99
- # Create a new asset bundler, which will produce a bundled file containing
100
- # the contents of +files+. If +name+ is +true+ (as in, is an instance of
101
- # +TrueClass+), the filename is written out as "all", otherwise +name+
102
- # is coerced into a string.
103
- def initialize(name, *files)
104
- @bundle_name = name == true ? :all : name
105
- @bundle_filename = asset_path(self.class.asset_type, @bundle_name, true)
106
- @files = files.map { |f| asset_path(self.class.asset_type, f, true) }
107
- end
108
-
109
- # Creates the new bundled file, executing all the callbacks.
110
- #
111
- # ==== Returns
112
- # Symbol:: Name of the bundle.
113
- #
114
- def bundle!
115
- # TODO: Move this file check out into an in-memory cache. Also, push it out to the helper level so we don't have to create the helper object.
116
- unless File.exist?(@bundle_filename)
117
- bundle_files(@bundle_filename, *@files)
118
- self.class.callbacks.each { |c| c.call(@bundle_filename) }
119
- end
120
- return @bundle_name
121
- end
122
-
123
- protected
124
-
125
- include Merb::Assets::AssetHelpers # for asset_path
126
-
127
- # Bundle all the files into one.
128
- #
129
- # ==== Parameters
130
- # filename<String>:: Name of the bundle file.
131
- # files<Array>:: An array of filenames to be bundled.
132
- #
133
- def bundle_files(filename, *files)
134
- File.open(filename, "w") do |f|
135
- files.each { |file| f.puts(File.read(file)) }
136
- end
137
- end
138
-
139
- end
140
-
141
- # Bundles javascripts into a single file:
142
- #
143
- # javascripts/#{name}.js
144
- class JavascriptAssetBundler < AbstractAssetBundler
145
- def self.asset_type
146
- :javascript
147
- end
148
- end
149
-
150
- # Bundles stylesheets into a single file:
151
- #
152
- # stylesheets/#{name}.css
153
- class StylesheetAssetBundler < AbstractAssetBundler
154
- def self.asset_type
155
- :stylesheet
156
- end
157
- end
158
-
159
- end
160
- end