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,35 +0,0 @@
1
- module Merb
2
-
3
- module AuthenticationMixin
4
- require 'base64'
5
-
6
- def credentials
7
- if d = %w{REDIRECT_X_HTTP_AUTHORIZATION X_HTTP_AUTHORIZATION
8
- X-HTTP_AUTHORIZATION HTTP_AUTHORIZATION}.
9
- inject([]) { |d,h| request.env.has_key?(h) ? request.env[h].to_s.split : d }
10
- return Base64.decode64(d[1]).split(':')[0..1] if d[0] == 'Basic'
11
- end
12
- end
13
-
14
- def authenticated?
15
- username, password = *credentials
16
- username == Merb::Config[:basic_auth][:username] and password == Merb::Config[:basic_auth][:password]
17
- end
18
-
19
- def basic_authentication
20
- if !authenticated?
21
- throw :halt, :access_denied
22
- end
23
- end
24
-
25
- def access_denied
26
- set_status(401)
27
- headers['Content-type'] = 'text/plain'
28
- headers['Status'] = 'Unauthorized'
29
- headers['WWW-Authenticate'] = "Basic realm=\"#{Merb::Config[:basic_auth][:domain]}\""
30
- return 'Unauthorized'
31
- end
32
-
33
- end
34
-
35
- end
@@ -1,160 +0,0 @@
1
- module Merb
2
- # Module that is mixed in to all implemented controllers.
3
- module ControllerMixin
4
-
5
- # Renders the block given as a parameter using chunked
6
- # encoding.
7
- #
8
- # ==== Examples
9
- #
10
- # def stream
11
- # prefix = '<p>'
12
- # suffix = "</p>\r\n"
13
- # render_chunked do
14
- # IO.popen("cat /tmp/test.log") do |io|
15
- # done = false
16
- # until done
17
- # sleep 0.3
18
- # line = io.gets.chomp
19
- #
20
- # if line == 'EOF'
21
- # done = true
22
- # else
23
- # send_chunk(prefix + line + suffix)
24
- # end
25
- # end
26
- # end
27
- # end
28
- # end
29
- #
30
- def render_chunked(&blk)
31
- headers['Transfer-Encoding'] = 'chunked'
32
- Proc.new {
33
- response.send_status_no_connection_close(0)
34
- response.send_header
35
- blk.call
36
- response.write("0\r\n\r\n")
37
- }
38
- end
39
-
40
- # Returns a +Proc+ that Mongrel can call later, allowing
41
- # Merb to release the thread lock and render another request.
42
- #
43
- def render_deferred(&blk)
44
- Proc.new {
45
- result = blk.call
46
- response.send_status(result.length)
47
- response.send_header
48
- response.write(result)
49
- }
50
- end
51
-
52
- # Writes a chunk from render_chunked to the response that
53
- # is sent back to the client.
54
- def send_chunk(data)
55
- response.write('%x' % data.size + "\r\n")
56
- response.write(data + "\r\n")
57
- end
58
-
59
- # Redirects to a URL. The +url+ parameter can be either
60
- # a relative URL (e.g., +/posts/34+) or a fully-qualified URL
61
- # (e.g., +http://www.merbivore.com/+).
62
- #
63
- # ==== Parameters
64
- #
65
- # +url+ - URL to redirect to; it can be either a relative or
66
- # fully-qualified URL.
67
- # +permanent+ - Whether to use permanent redirection.
68
- #
69
- def redirect(url, permanent = false)
70
- status = permanent ? 301 : 302
71
- Merb.logger.info("Redirecting to: #{url} status: #{status}")
72
- set_status(status)
73
- headers['Location'] = url
74
- "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
75
- end
76
-
77
- # Sends a file over HTTP. When given a path to a file, it will set the
78
- # right headers so that the static file is served directly.
79
- #
80
- # ==== Parameters
81
- #
82
- # +file+ - Path to file to send to the client.
83
- #
84
- def send_file(file, opts={})
85
- opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
86
- disposition = opts[:disposition].dup || 'attachment'
87
- disposition << %(; filename="#{opts[:filename] ? opts[:filename] : File.basename(file)}")
88
- headers.update(
89
- 'Content-Type' => opts[:type].strip, # fixes a problem with extra '\r' with some browsers
90
- 'Content-Disposition' => disposition,
91
- 'Content-Transfer-Encoding' => 'binary',
92
- 'X-SENDFILE' => file
93
- )
94
- return
95
- end
96
-
97
- # Streams a file over HTTP.
98
- #
99
- # ==== Example
100
- #
101
- # stream_file( { :filename => file_name,
102
- # :type => content_type,
103
- # :content_length => content_length }) do
104
- # AWS::S3::S3Object.stream(user.folder_name + "-" + user_file.unique_id, bucket_name) do |chunk|
105
- # response.write chunk
106
- # end
107
- # end
108
- def stream_file(opts={}, &stream)
109
- opts.update(Merb::Const::DEFAULT_SEND_FILE_OPTIONS.merge(opts))
110
- disposition = opts[:disposition].dup || 'attachment'
111
- disposition << %(; filename="#{opts[:filename]}")
112
- response.headers.update(
113
- 'Content-Type' => opts[:type].strip, # fixes a problem with extra '\r' with some browsers
114
- 'Content-Disposition' => disposition,
115
- 'Content-Transfer-Encoding' => 'binary',
116
- 'CONTENT-LENGTH' => opts[:content_length]
117
- )
118
- response.send_status(opts[:content_length])
119
- response.send_header
120
- stream
121
- end
122
-
123
-
124
- # Uses the nginx specific +X-Accel-Redirect+ header to send
125
- # a file directly from nginx. For more information, see the nginx wiki:
126
- # http://wiki.codemongers.com/NginxXSendfile
127
- #
128
- # ==== Parameters
129
- #
130
- # +file+ - Path to file to send to the client.
131
- #
132
- def nginx_send_file(file)
133
- headers['X-Accel-Redirect'] = File.expand_path(file)
134
- return
135
- end
136
-
137
- # Sets a cookie to be included in the response. This method is used
138
- # primarily internally in Merb.
139
- #
140
- # If you need to set a cookie, then use the +cookies+ hash.
141
- #
142
- def set_cookie(name, value, expires)
143
- (headers['Set-Cookie'] ||=[]) << (Merb::Const::SET_COOKIE % [
144
- name.to_s,
145
- escape(value.to_s),
146
- # Cookie expiration time must be GMT. See RFC 2109
147
- expires.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT)
148
- ])
149
- end
150
-
151
- # Marks a cookie as deleted and gives it an expires stamp in
152
- # the past. This method is used primarily internally in Merb.
153
- #
154
- # Use the +cookies+ hash to manipulate cookies instead.
155
- #
156
- def delete_cookie(name)
157
- set_cookie(name, nil, Merb::Const::COOKIE_EXPIRED_TIME)
158
- end
159
- end
160
- end
@@ -1,68 +0,0 @@
1
- module Merb
2
-
3
-
4
-
5
- module ErubisCaptureMixin
6
-
7
- # Provides direct acccess to the buffer for this view context
8
- def _buffer( the_binding )
9
- @_buffer = eval( "_buf", the_binding )
10
- end
11
-
12
- # Capture allows you to extract a part of the template into an
13
- # instance variable. You can use this instance variable anywhere
14
- # in your templates and even in your layout.
15
- #
16
- # Example of capture being used in a .herb page:
17
- #
18
- # <% @foo = capture do %>
19
- # <p>Some Foo content!</p>
20
- # <% end %>
21
- def capture(*args, &block)
22
- # execute the block
23
- begin
24
- buffer = _buffer( block.binding )
25
- rescue
26
- buffer = nil
27
- end
28
-
29
- if buffer.nil?
30
- capture_block(*args, &block)
31
- else
32
- capture_erb_with_buffer(buffer, *args, &block)
33
- end
34
- end
35
-
36
- private
37
- def capture_block(*args, &block)
38
- block.call(*args)
39
- end
40
-
41
- def capture_erb(*args, &block)
42
- buffer = _buffer
43
- capture_erb_with_buffer(buffer, *args, &block)
44
- end
45
-
46
- def capture_erb_with_buffer(buffer, *args, &block)
47
- pos = buffer.length
48
- block.call(*args)
49
-
50
- # extract the block
51
- data = buffer[pos..-1]
52
-
53
- # replace it in the original with empty string
54
- buffer[pos..-1] = ''
55
-
56
- data
57
- end
58
-
59
- def erb_content_for(name, &block)
60
- controller.thrown_content[name] << capture_erb( &block )
61
- end
62
-
63
- def block_content_for(name, &block)
64
- controller.thrown_content[name] << capture_block( &block )
65
- end
66
- end
67
-
68
- end
@@ -1,253 +0,0 @@
1
- # This module provides helper style functionality to all controllers.
2
- module Merb
3
- module GeneralControllerMixin
4
- include Merb::ControllerExceptions
5
-
6
- # Returns a URL according to the defined route. Accepts the path and
7
- # an options hash. The path specifies the route requested. The options
8
- # hash fills in the dynamic parts of the route.
9
- #
10
- # Merb routes can often be one-way; if they use a regex to define
11
- # the route, then knowing the controller & action won't be enough
12
- # to reverse-generate the route. However, if you use the default
13
- # /controller/action/id?query route, +default_route+ can generate
14
- # it for you.
15
- #
16
- # For easy reverse-routes that use a Regex, be sure to also add
17
- # a name to the route, so +url+ can find it.
18
- #
19
- # Nested resources such as:
20
- #
21
- # r.resources :blogposts do |post|
22
- # post.resources :comments
23
- # end
24
- #
25
- # Provide the following routes:
26
- #
27
- # [:blogposts, "/blogposts"]
28
- # [:blogpost, "/blogposts/:id"]
29
- # [:edit_blogpost, "/blogposts/:id/edit"]
30
- # [:new_blogpost, "/blogposts/new"]
31
- # [:custom_new_blogpost, "/blogposts/new/:action"]
32
- # [:comments, "/blogposts/:blogpost_id/comments"]
33
- # [:comment, "/blogposts/:blogpost_id/comments/:id"]
34
- # [:edit_comment, "/blogposts/:blogpost_id/comments/:id/edit"]
35
- # [:new_comment, "/blogposts/:blogpost_id/comments/new"]
36
- # [:custom_new_comment, "/blogposts/:blogpost_id/comments/new/:action"]
37
- #
38
- #
39
- # ==== Parameters
40
- #
41
- # :route_name: - Symbol that represents a named route that you want to use, such as +:edit_post+.
42
- # :new_params: - Parameters to be passed to the generated URL, such as the +id+ for a record to edit.
43
- #
44
- # ==== Examples
45
- #
46
- # @post = Post.find(1)
47
- # @comment = @post.comments.find(1)
48
- #
49
- # url(:blogposts) # => /blogposts
50
- # url(:new_post) # => /blogposts/new
51
- # url(:blogpost, @post) # => /blogposts/1
52
- # url(:edit_blogpost, @post) # => /blogposts/1/edit
53
- # url(:custom_new_blogpost, :action => 'alternate') # => /blogposts/new/alternate
54
- #
55
- # url(:comments, :blogpost_id => @post) # => /blogposts/1/comments
56
- # url(:new_comment, :blogpost_id => @post) # => /blogposts/1/comments/new
57
- # url(:comment, @comment) # => /blogposts/1/comments/1
58
- # url(:edit_comment, @comment) # => /blogposts/1/comments/1/edit
59
- # url(:custom_new_comment, :blogpost_id => @post)
60
- #
61
- # url(:page => 2) # => /posts/show/1?page=2
62
- # url(:new_post, :page => 3) # => /posts/new?page=3
63
- # url('/go/here', :page => 3) # => /go/here?page=3
64
- #
65
- # url(:controller => "welcome") # => /welcome
66
- # url(:controller => "welcome", :action => "greet")
67
- # # => /welcome/greet
68
- #
69
- def url(route_name = nil, new_params = {})
70
- if route_name.is_a?(Hash)
71
- new_params = route_name
72
- route_name = nil
73
- end
74
-
75
- url = if new_params.respond_to?(:keys) && route_name.nil? &&
76
- !(new_params.keys & [:controller, :action, :id]).empty?
77
- url_from_default_route(new_params)
78
- elsif route_name.nil? && !route.regexp?
79
- url_from_route(route, new_params)
80
- elsif route_name.nil?
81
- request.path + (new_params.empty? ? "" : "?" + params_to_query_string(new_params))
82
- elsif route_name.is_a?(Symbol)
83
- url_from_route(route_name, new_params)
84
- elsif route_name.is_a?(String)
85
- route_name + (new_params.empty? ? "" : "?" + params_to_query_string(new_params))
86
- else
87
- raise "URL not generated: #{route_name.inspect}, #{new_params.inspect}"
88
- end
89
- url = Merb::Config[:path_prefix] + url if Merb::Config[:path_prefix]
90
- url
91
- end
92
-
93
- def url_from_route(symbol, new_params = {})
94
- if new_params.respond_to?(:new_record?) && new_params.new_record?
95
- symbol = "#{symbol}".singularize.to_sym
96
- new_params = {}
97
- end
98
- route = symbol.is_a?(Symbol) ? Merb::Router.named_routes[symbol] : symbol
99
- unless route
100
- raise "URL could not be constructed. Route symbol not found: #{symbol.inspect}"
101
- end
102
-
103
- path = route.generate(new_params, params)
104
- keys = route.symbol_segments
105
-
106
- if new_params.is_a? Hash
107
- if ext = format_extension(new_params)
108
- new_params.delete(:format)
109
- path += "." + ext
110
- end
111
- extras = new_params.reject{ |k, v| keys.include?(k) }
112
- path += "?" + params_to_query_string(extras) unless extras.empty?
113
- end
114
- path
115
- end
116
-
117
- # this is pretty ugly, but it works. TODO: make this cleaner
118
- def url_from_default_route(new_params)
119
- query_params = new_params.reject do |k,v|
120
- [:controller, :action, :id, :format].include?(k)
121
- end
122
- controller = get_controller_for_url_generation(new_params)
123
- url = "/#{controller}"
124
- if new_params[:action] || new_params[:id] ||
125
- new_params[:format] || !query_params.empty?
126
- action = new_params[:action] || params[:action]
127
- url += "/#{action}"
128
- end
129
- if new_params[:id]
130
- url += "/#{new_params[:id]}"
131
- end
132
- if format = new_params[:format]
133
- format = params[:format] if format == :current
134
- url += ".#{format}"
135
- end
136
- unless query_params.empty?
137
- url += "?" + params_to_query_string(query_params)
138
- end
139
- url
140
- end
141
-
142
- protected
143
-
144
- # Creates query string from params, supporting nested arrays and hashes.
145
- # ==== Example
146
- # params_to_query_string(:user => {:filter => {:name => "quux*"}, :order => ["name"]})
147
- # # => user[filter][name]=quux%2A&user[order][]=name
148
- def params_to_query_string(value, prefix = nil)
149
- case value
150
- when Array
151
- value.map { |v|
152
- params_to_query_string(v, "#{prefix}[]")
153
- } * "&"
154
- when Hash
155
- value.map { |k, v|
156
- params_to_query_string(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
157
- } * "&"
158
- else
159
- "#{prefix}=#{escape(value)}"
160
- end
161
- end
162
-
163
- # +format_extension+ dictates when named route URLs generated by the url
164
- # method will have a file extension. It will return either nil or the format
165
- # extension to append.
166
- #
167
- # ==== Configuration Options
168
- #
169
- # By default, non-HTML URLs will be given an extension. It is posible
170
- # to override this behaviour by setting +:use_format_in_urls+ in your
171
- # Merb config (merb.yml) to either true/false.
172
- #
173
- # +true+ Results in all URLs (even HTML) being given extensions.
174
- # This effect is often desirable when you have many formats and dont
175
- # wish to treat .html any differently than any other format.
176
- # +false+ Results in no URLs being given extensions and +format+
177
- # gets treated just like any other param (default).
178
- #
179
- # ==== Method parameters
180
- #
181
- # +new_params+ - New parameters to be appended to the URL
182
- #
183
- # ==== Examples
184
- #
185
- # url(:post, :id => post, :format => 'xml')
186
- # # => /posts/34.xml
187
- #
188
- # url(:accounts, :format => 'yml')
189
- # # => /accounts.yml
190
- #
191
- # url(:edit_product, :id => 3, :format => 'html')
192
- # # => /products/3
193
- #
194
- def format_extension(new_params={})
195
- format = params.merge(new_params)[:format] || 'html'
196
- if format != 'html' || always_use_format_extension?
197
- format || 'html'
198
- end
199
- end
200
-
201
- def always_use_format_extension?
202
- Merb::Config[:use_format_in_urls]
203
- end
204
-
205
-
206
- # Creates an MD5 hashed token based on the current time.
207
- #
208
- # ==== Example
209
- # make_token
210
- # # => "b9a82e011694cc13a4249731b9e83cea"
211
- #
212
- def make_token
213
- require 'digest/md5'
214
- Digest::MD5.hexdigest("#{inspect}#{Time.now}#{rand}")
215
- end
216
-
217
- # Escapes the string representation of +obj+ and escapes
218
- # it for use in XML.
219
- #
220
- # ==== Parameter
221
- #
222
- # +obj+ - The object to escape for use in XML.
223
- #
224
- def escape_xml(obj)
225
- obj.to_s.gsub(/[&<>"']/) { |s| Merb::Const::ESCAPE_TABLE[s] }
226
- end
227
- alias h escape_xml
228
- alias html_escape escape_xml
229
-
230
- def escape(s)
231
- ::Merb::Request.escape(s)
232
- end
233
-
234
- # Unescapes a string (i.e., reverse URL escaping).
235
- #
236
- # ==== Parameter
237
- #
238
- # +s+ - String to unescape.
239
- #
240
- def unescape(s)
241
- ::Merb::Request.unescape(s)
242
- end
243
-
244
-
245
- private
246
- # Used for sepccing
247
- def get_controller_for_url_generation(options)
248
- raise "Controller Not Specified" unless options[:controller]
249
- options[:controller]
250
- end
251
-
252
- end
253
- end