merb 0.5.3 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
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,50 +0,0 @@
1
- module Merb
2
- module Const
3
-
4
- ESCAPE_TABLE = {
5
- '&' => '&',
6
- '<' => '&lt;',
7
- '>' => '&gt;',
8
- '"' => '&quot;',
9
- "'" => '&#039;',
10
- }.freeze
11
-
12
- DEFAULT_SEND_FILE_OPTIONS = {
13
- :type => 'application/octet-stream'.freeze,
14
- :disposition => 'attachment'.freeze
15
- }.freeze
16
-
17
- SET_COOKIE = " %s=%s; path=/; expires=%s".freeze
18
- COOKIE_EXPIRATION_FORMAT = "%a, %d-%b-%Y %H:%M:%S GMT".freeze
19
- COOKIE_SPLIT = /[;,] */n.freeze
20
- COOKIE_REGEXP = /\s*(.+)=(.*)\s*/.freeze
21
- COOKIE_EXPIRED_TIME = Time.at(0).freeze
22
- HOUR = 60*60
23
- DAY = HOUR*24
24
- WEEK = DAY*7
25
- MULTIPART_REGEXP = /\Amultipart\/form-data.*boundary=\"?([^\";,]+)/n.freeze
26
- HTTP_COOKIE = 'HTTP_COOKIE'.freeze
27
- QUERY_STRING = 'QUERY_STRING'.freeze
28
- JSON_MIME_TYPE_REGEXP = %r{^application/json|^text/x-json}.freeze
29
- XML_MIME_TYPE_REGEXP = %r{^application/xml|^text/xml}.freeze
30
- FORM_URL_ENCODED_REGEXP = %r{^application/x-www-form-urlencoded}.freeze
31
- UPCASE_CONTENT_TYPE = 'CONTENT_TYPE'.freeze
32
- CONTENT_TYPE = "Content-Type".freeze
33
- LAST_MODIFIED = "Last-Modified".freeze
34
- SLASH = "/".freeze
35
- REQUEST_METHOD = "REQUEST_METHOD".freeze
36
- GET = "GET".freeze
37
- POST = "POST".freeze
38
- HEAD = "HEAD".freeze
39
- CONTENT_LENGTH = "CONTENT_LENGTH".freeze
40
- HTTP_X_FORWARDED_FOR = "HTTP_X_FORWARDED_FOR".freeze
41
- HTTP_IF_MODIFIED_SINCE = "HTTP_IF_MODIFIED_SINCE".freeze
42
- HTTP_IF_NONE_MATCH = "HTTP_IF_NONE_MATCH".freeze
43
- UPLOAD_ID = "upload_id".freeze
44
- PATH_INFO = "PATH_INFO".freeze
45
- SCRIPT_NAME = "SCRIPT_NAME".freeze
46
- REQUEST_URI = "REQUEST_URI".freeze
47
- REQUEST_PATH = "REQUEST_PATH".freeze
48
- REMOTE_ADDR = "REMOTE_ADDR".freeze
49
- end
50
- end
@@ -1,220 +0,0 @@
1
- module Merb
2
-
3
- # All of your web controllers will inherit from Merb::Controller. This
4
- # superclass takes care of parsing the incoming headers and body into
5
- # params and cookies and headers. If the request is a file upload it will
6
- # stream it into a tempfile and pass in the filename and tempfile object
7
- # to your controller via params. It also parses the ?query=string and
8
- # puts that into params as well.
9
- #
10
- # == Sessions
11
- #
12
- # Session data can be accessed through the +session+ hash:
13
- #
14
- # session[:user_id] = @user.id
15
- #
16
- # Session data is available until the user's cookie gets deleted/expires,
17
- # or until your specific session store expires the data.
18
- #
19
- # === Session Store
20
- #
21
- # The session store is set in Merb.root/config/merb.yml :
22
- #
23
- # :session_store: your_store
24
- #
25
- # Out of the box merb supports three session stores
26
- #
27
- # cookie:: All data (max 4kb) stored directly in cookie. Data integrity is checked on each request to prevent tampering. (Merb::CookieStore)
28
- # memory:: Data stored in a class in memory. (Merb::MemorySession)
29
- # mem_cache:: Data stored in mem_cache. (Merb::MemCacheSession)
30
- #
31
- # See the documentation on each session store for more information.
32
- #
33
- # You can also use a session store provided by a plugin. For instance, if you have DataMapper you can set
34
- #
35
- # :session_store: datamapper
36
- #
37
- # In this case session data will be stored in the database, as defined by the merb_datamapper plugin.
38
- # Similar functionality exists for +activerecord+ and +sequel+ currently.
39
-
40
- class Controller < AbstractController
41
- class_inheritable_accessor :_session_id_key, :_session_expiry
42
- cattr_accessor :_subclasses, :session_secret_key
43
- self._subclasses = []
44
- self.session_secret_key = nil
45
- self._session_id_key = '_session_id'
46
- self._session_expiry = Time.now + Merb::Const::WEEK * 2
47
-
48
- include Merb::ControllerMixin
49
- include Merb::ResponderMixin
50
- include Merb::ControllerExceptions
51
- include Merb::Caching::Actions
52
-
53
- class << self
54
- def inherited(klass)
55
- _subclasses << klass.to_s unless _subclasses.include?(klass.to_s)
56
- super
57
- end
58
-
59
- def callable_actions
60
- @callable_actions ||= begin
61
- hsh = {}
62
- (public_instance_methods - hidden_actions).each {|action| hsh[action.to_s] = true}
63
- hsh
64
- end
65
- end
66
-
67
- def hidden_actions
68
- write_inheritable_attribute(:hidden_actions, Merb::Controller.public_instance_methods) unless read_inheritable_attribute(:hidden_actions)
69
- read_inheritable_attribute(:hidden_actions)
70
- end
71
-
72
- # Hide each of the given methods from being callable as actions.
73
- def hide_action(*names)
74
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect { |n| n.to_s })
75
- end
76
-
77
- def build(request, response = StringIO.new, status=200, headers={'Content-Type' => 'text/html; charset=utf-8'})
78
- cont = new
79
- cont.set_dispatch_variables(request, response, status, headers)
80
- cont
81
- end
82
- end
83
-
84
- def set_dispatch_variables(request, response, status, headers)
85
- if request.params.key?(_session_id_key)
86
- if Merb::Config[:session_id_cookie_only]
87
- # This condition allows for certain controller/action paths to allow
88
- # a session ID to be passed in a query string. This is needed for
89
- # Flash Uploads to work since flash will not pass a Session Cookie
90
- # Recommend running session.regenerate after any controller taking
91
- # advantage of this in case someone is attempting a session fixation
92
- # attack
93
- if Merb::Config[:query_string_whitelist].include?("#{request.controller_name}/#{request.action}")
94
- # FIXME to use routes not controller and action names -----^
95
- request.cookies[_session_id_key] = request.params[_session_id_key]
96
- end
97
- else
98
- request.cookies[_session_id_key] = request.params[_session_id_key]
99
- end
100
- end
101
- @_request = request
102
- @_response = response
103
- @_status = status
104
- @_headers = headers
105
- end
106
-
107
- def dispatch(action=:index)
108
- start = Time.now
109
- if self.class.callable_actions[action.to_s]
110
- params[:action] ||= action
111
- setup_session
112
- super(action)
113
- finalize_session
114
- else
115
- raise ActionNotFound, "Action '#{action}' was not found in #{self.class}"
116
- end
117
- @_benchmarks[:action_time] = Time.now - start
118
- Merb.logger.info("Time spent in #{self.class}##{action} action: #{@_benchmarks[:action_time]} seconds")
119
- end
120
-
121
- # Accessor for @_body. Please use body and never @body directly.
122
- def body
123
- @_body
124
- end
125
-
126
- # Accessor for @_status. Please use status and never @_status directly.
127
- def status
128
- @_status
129
- end
130
-
131
- # Accessor for @_request. Please use request and never @_request directly.
132
- def request
133
- @_request
134
- end
135
-
136
- def params
137
- request.params
138
- end
139
-
140
- def cookies
141
- @_cookies ||= Cookies.new(request.cookies, @_headers)
142
- end
143
-
144
- # Accessor for @_headers. Please use headers and never @_headers directly.
145
- def headers
146
- @_headers
147
- end
148
-
149
- # Accessor for @_session. Please use session and never @_session directly.
150
- def session
151
- request.session
152
- end
153
-
154
- # Accessor for @_response. Please use response and never @_response directly.
155
- def response
156
- @_response
157
- end
158
-
159
- # Accessor for @_route. Please use route and never @_route directly.
160
- def route
161
- request.route
162
- end
163
-
164
- # Sends mail via a MailController (a tutorial can be found in the
165
- # MailController docs).
166
- #
167
- # send_mail FooMailer, :bar, :from => "foo@bar.com", :to => "baz@bat.com"
168
- #
169
- # would send an email via the FooMailer's bar method.
170
- #
171
- # The mail_params hash would be sent to the mailer, and includes items
172
- # like from, to subject, and cc. See
173
- # Merb::MailController#dispatch_and_deliver for more details.
174
- #
175
- # The send_params hash would be sent to the MailController, and is
176
- # available to methods in the MailController as <tt>params</tt>. If you do
177
- # not send any send_params, this controller's params will be available to
178
- # the MailController as <tt>params</tt>
179
- def send_mail(klass, method, mail_params, send_params = nil)
180
- klass.new(send_params || params, self).dispatch_and_deliver(method, mail_params)
181
- end
182
-
183
- # Dispatches a PartController. Use like:
184
- #
185
- # <%= part TodoPart => :list %>
186
- #
187
- # will instantiate a new TodoPart controller and call the :list action
188
- # invoking the Part's before and after filters as part of the call.
189
- #
190
- # returns a string containing the results of the Part controllers dispatch
191
- #
192
- # You can compose parts easily as well, these two parts will stil be wrapped
193
- # in the layout of the Foo controller:
194
- #
195
- # class Foo < Application
196
- # def some_action
197
- # wrap_layout(part(TodoPart => :new) + part(TodoPart => :list))
198
- # end
199
- # end
200
- #
201
- def part(opts={})
202
- res = opts.inject([]) do |memo,(klass,action)|
203
- memo << klass.new(self).dispatch(action)
204
- end
205
- res.size == 1 ? res[0] : res
206
- end
207
-
208
- private
209
-
210
- # This method is here to overwrite the one in the general_controller mixin
211
- # The method ensures that when a url is generated with a hash, it contains a controller
212
- def get_controller_for_url_generation(options)
213
- controller = options[:controller] || params[:controller]
214
- controller = params[:controller] if controller == :current
215
- controller
216
- end
217
-
218
- end
219
-
220
- end
data/lib/merb/cookies.rb DELETED
@@ -1,95 +0,0 @@
1
- module Merb
2
-
3
- # Cookies are read and written through Merb::Controller#cookies. The cookies
4
- # you read are those received in request along with those that have been set
5
- # during the current request. The cookies you write will be sent out with the
6
- # response. Cookies are read by value (so you won't get the cookie object
7
- # itself back -- just the value it holds).
8
- #
9
- # == Writing
10
- #
11
- # cookies[:user] = "dave" # => Sets a simple session cookie
12
- # cookies[:token] = { :value => user.token, :expires => Time.now + 2.weeks }
13
- # # => Will set a cookie that expires in 2 weeks
14
- #
15
- # == Reading
16
- #
17
- # cookies[:user] # => "dave"
18
- # cookies.size # => 2 (the number of cookies)
19
- #
20
- # == Deleting
21
- #
22
- # cookies.delete(:user)
23
- #
24
- # == Options
25
- #
26
- # * +value+ - the cookie's value
27
- # * +path+ - the path for which this cookie applies. Defaults to the root
28
- # of the application.
29
- # * +expires+ - the time at which this cookie expires, as a +Time+ object.
30
- class Cookies
31
-
32
- def initialize(request_cookies, headers)
33
- @_cookies = request_cookies
34
- @_headers = headers
35
- end
36
-
37
- # Returns the value of the cookie by +name+ or nil if no such cookie
38
- # exists. You set new cookies using cookies[]=
39
- def [](name)
40
- @_cookies[name]
41
- end
42
-
43
- # Sets the value of a cookie. You can set the value directly or pass a hash
44
- # with options.
45
- #
46
- # == Example
47
- #
48
- # cookies[:user] = "dave" # => Sets a simple session cookie
49
- # cookies[:token] = { :value => user.token, :expires => Time.now + 2.weeks }
50
- # # => Will set a cookie that expires in 2 weeks
51
- #
52
- # == Options
53
- #
54
- # * +value+ - the cookie's value or list of values (as an array).
55
- # * +path+ - the path for which this cookie applies. Defaults to the root
56
- # '/' of the application.
57
- # * +expires+ - the time at which this cookie expires, as a +Time+ object.
58
- def []=(name, options)
59
- value = ''
60
- if options.is_a?(Hash)
61
- options = Mash.new(options)
62
- value = Merb::Request.escape(options.delete(:value))
63
- else
64
- value = Merb::Request.escape(options)
65
- options = Mash.new
66
- end
67
- @_cookies[name] = value
68
- set_cookie(name, value, options)
69
- Merb.logger.info("Cookie set: #{name} => #{value} -- #{options.inspect}")
70
- return options
71
- end
72
-
73
- # Removes the cookie on the client machine by setting the value to an empty string
74
- # and setting its expiration date into the past.
75
- def delete(name, options = {})
76
- cookie = @_cookies.delete(name)
77
- options = Mash.new(options)
78
- options[:expires] = Time.at(0)
79
- set_cookie(name, "", options)
80
- Merb.logger.info("Cookie deleted: #{name} => #{cookie.inspect}")
81
- return cookie
82
- end
83
-
84
- private
85
- def set_cookie(name, value, options)
86
- options[:path] = '/' unless options[:path]
87
- if expiry = options[:expires]
88
- options[:expires] = expiry.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT)
89
- end
90
- # options are sorted for testing purposes
91
- (@_headers['Set-Cookie'] ||=[]) << "#{name}=#{value}; " +
92
- options.map{|k, v| "#{k}=#{v};"}.sort.join(' ')
93
- end
94
- end
95
- end
data/lib/merb/core_ext.rb DELETED
@@ -1,15 +0,0 @@
1
- corelib = File.dirname(__FILE__) + '/core_ext'
2
-
3
- %w[ inflector
4
- class
5
- kernel
6
- object
7
- mash
8
- enumerable
9
- module
10
- string
11
- hash
12
- numeric
13
- symbol
14
- get_args
15
- ].each {|fn| require File.join(corelib, fn)}
File without changes
@@ -1,180 +0,0 @@
1
- # Allows attributes to be shared within an inheritance hierarchy, but where each descendant gets a copy of
2
- # their parents' attributes, instead of just a pointer to the same. This means that the child can add elements
3
- # to, for example, an array without those additions being shared with either their parent, siblings, or
4
- # children, which is unlike the regular class-level attributes that are shared across the entire hierarchy.
5
- class Class # :nodoc:
6
- def cattr_reader(*syms)
7
- syms.flatten.each do |sym|
8
- next if sym.is_a?(Hash)
9
- class_eval(<<-EOS, __FILE__, __LINE__)
10
- unless defined? @@#{sym}
11
- @@#{sym} = nil
12
- end
13
-
14
- def self.#{sym}
15
- @@#{sym}
16
- end
17
-
18
- def #{sym}
19
- @@#{sym}
20
- end
21
- EOS
22
- end
23
- end
24
-
25
- def cattr_writer(*syms)
26
- options = syms.last.is_a?(Hash) ? syms.pop : {}
27
- syms.flatten.each do |sym|
28
- class_eval(<<-EOS, __FILE__, __LINE__)
29
- unless defined? @@#{sym}
30
- @@#{sym} = nil
31
- end
32
-
33
- def self.#{sym}=(obj)
34
- @@#{sym} = obj
35
- end
36
-
37
- #{"
38
- def #{sym}=(obj)
39
- @@#{sym} = obj
40
- end
41
- " unless options[:instance_writer] == false }
42
- EOS
43
- end
44
- end
45
-
46
- def cattr_accessor(*syms)
47
- cattr_reader(*syms)
48
- cattr_writer(*syms)
49
- end
50
- def class_inheritable_reader(*syms)
51
- syms.each do |sym|
52
- next if sym.is_a?(Hash)
53
- class_eval <<-EOS
54
- def self.#{sym}
55
- read_inheritable_attribute(:#{sym})
56
- end
57
-
58
- def #{sym}
59
- self.class.#{sym}
60
- end
61
- EOS
62
- end
63
- end
64
-
65
- def class_inheritable_writer(*syms)
66
- options = syms.last.is_a?(Hash) ? syms.pop : {}
67
- syms.each do |sym|
68
- class_eval <<-EOS
69
- def self.#{sym}=(obj)
70
- write_inheritable_attribute(:#{sym}, obj)
71
- end
72
-
73
- #{"
74
- def #{sym}=(obj)
75
- self.class.#{sym} = obj
76
- end
77
- " unless options[:instance_writer] == false }
78
- EOS
79
- end
80
- end
81
-
82
- def class_inheritable_array_writer(*syms)
83
- options = syms.last.is_a?(Hash) ? syms.pop : {}
84
- syms.each do |sym|
85
- class_eval <<-EOS
86
- def self.#{sym}=(obj)
87
- write_inheritable_array(:#{sym}, obj)
88
- end
89
-
90
- #{"
91
- def #{sym}=(obj)
92
- self.class.#{sym} = obj
93
- end
94
- " unless options[:instance_writer] == false }
95
- EOS
96
- end
97
- end
98
-
99
- def class_inheritable_hash_writer(*syms)
100
- options = syms.last.is_a?(Hash) ? syms.pop : {}
101
- syms.each do |sym|
102
- class_eval <<-EOS
103
- def self.#{sym}=(obj)
104
- write_inheritable_hash(:#{sym}, obj)
105
- end
106
-
107
- #{"
108
- def #{sym}=(obj)
109
- self.class.#{sym} = obj
110
- end
111
- " unless options[:instance_writer] == false }
112
- EOS
113
- end
114
- end
115
-
116
- def class_inheritable_accessor(*syms)
117
- class_inheritable_reader(*syms)
118
- class_inheritable_writer(*syms)
119
- end
120
-
121
- def class_inheritable_array(*syms)
122
- class_inheritable_reader(*syms)
123
- class_inheritable_array_writer(*syms)
124
- end
125
-
126
- def class_inheritable_hash(*syms)
127
- class_inheritable_reader(*syms)
128
- class_inheritable_hash_writer(*syms)
129
- end
130
-
131
- def inheritable_attributes
132
- @inheritable_attributes ||= EMPTY_INHERITABLE_ATTRIBUTES
133
- end
134
-
135
- def write_inheritable_attribute(key, value)
136
- if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
137
- @inheritable_attributes = {}
138
- end
139
- inheritable_attributes[key] = value
140
- end
141
-
142
- def write_inheritable_array(key, elements)
143
- write_inheritable_attribute(key, []) if read_inheritable_attribute(key).nil?
144
- write_inheritable_attribute(key, read_inheritable_attribute(key) + elements)
145
- end
146
-
147
- def write_inheritable_hash(key, hash)
148
- write_inheritable_attribute(key, {}) if read_inheritable_attribute(key).nil?
149
- write_inheritable_attribute(key, read_inheritable_attribute(key).merge(hash))
150
- end
151
-
152
- def read_inheritable_attribute(key)
153
- inheritable_attributes[key]
154
- end
155
-
156
- def reset_inheritable_attributes
157
- @inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
158
- end
159
-
160
- private
161
- # Prevent this constant from being created multiple times
162
- EMPTY_INHERITABLE_ATTRIBUTES = {}.freeze unless const_defined?(:EMPTY_INHERITABLE_ATTRIBUTES)
163
-
164
- def inherited_with_inheritable_attributes(child)
165
- inherited_without_inheritable_attributes(child) if respond_to?(:inherited_without_inheritable_attributes)
166
-
167
- if inheritable_attributes.equal?(EMPTY_INHERITABLE_ATTRIBUTES)
168
- new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
169
- else
170
- new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)|
171
- memo.update(key => (value.dup rescue value))
172
- end
173
- end
174
-
175
- child.instance_variable_set('@inheritable_attributes', new_inheritable_attributes)
176
- end
177
-
178
- alias inherited_without_inheritable_attributes inherited
179
- alias inherited inherited_with_inheritable_attributes
180
- end