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,22 +0,0 @@
1
- require 'fileutils'
2
- require 'find'
3
-
4
- module Merb
5
-
6
- class PluginGenerator
7
- def self.run(path)
8
- require 'rubygems'
9
- require 'rubigen'
10
-
11
- require 'rubigen/scripts/generate'
12
- source = RubiGen::PathSource.new(:application,
13
- File.join(File.dirname(__FILE__), "../../../app_generators"))
14
- RubiGen::Base.reset_sources
15
- RubiGen::Base.append_sources source
16
- RubiGen::Scripts::Generate.new.run([path], :generator => 'merb_plugin', :backtrace => true)
17
- end
18
-
19
- end
20
-
21
- end
22
-
data/lib/merb/logger.rb DELETED
@@ -1,78 +0,0 @@
1
- module Merb
2
-
3
- class Logger
4
- module Severity
5
- DEBUG = 0
6
- INFO = 1
7
- WARN = 2
8
- ERROR = 3
9
- FATAL = 4
10
- UNKNOWN = 5
11
- end
12
- include Severity
13
-
14
- attr_accessor :level
15
- attr_reader :buffer
16
-
17
- def initialize(log, level = DEBUG)
18
- @level = level
19
- @buffer = []
20
- @aio = false
21
- if log.respond_to?(:write)
22
- @log = log
23
- elsif File.exist?(log)
24
- @log = open(log, (File::WRONLY | File::APPEND))
25
- @log.sync = true
26
- else
27
- @log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
28
- @log.sync = true
29
- @log.write("# Logfile created on %s\n" % [Time.now.to_s])
30
- end
31
- if !Merb.environment.match(/development|test/) &&
32
- !RUBY_PLATFORM.match(/java|mswin/) &&
33
- !(@log == STDOUT) &&
34
- @log.respond_to?(:write_nonblock)
35
- @aio = true
36
- end
37
- end
38
-
39
- def flush
40
- unless @buffer.size == 0
41
- if @aio
42
- @log.write_nonblock(@buffer.slice!(0..-1).to_s)
43
- else
44
- @log.write(@buffer.slice!(0..-1).to_s)
45
- end
46
- end
47
- end
48
-
49
- def close
50
- flush
51
- @log.close if @log.respond_to?(:close)
52
- @log = nil
53
- end
54
-
55
- def add(severity, message = nil, progname = nil, &block)
56
- return if @level > severity
57
- message = (message || (block && block.call) || progname).to_s
58
- # If a newline is necessary then create a new message ending with a newline.
59
- # Ensures that the original message is not mutated.
60
- message = "#{message}\n" unless message[-1] == ?\n
61
- @buffer << message
62
- message
63
- end
64
-
65
- Severity.constants.each do |severity|
66
- class_eval <<-EOT
67
- def #{severity.downcase}(message = nil, progname = nil, &block)
68
- add(#{severity}, message, progname, &block)
69
- end
70
-
71
- def #{severity.downcase}?
72
- #{severity} >= @level
73
- end
74
- EOT
75
- end
76
-
77
- end
78
- end
@@ -1,268 +0,0 @@
1
-
2
- module Merb
3
-
4
- # Sending mail from a controller involves three steps:
5
- #
6
- # * Set mail settings in merb_init.rb (Not shown here...see the Mailer docs).
7
- # * Create a MailController subclass with actions and templates.
8
- # * Call the MailController from another Controller via the send_mail method.
9
- #
10
- # First, create a file in app/mailers that subclasses Merb::MailController.
11
- # The actions in this controller will do nothing but render mail.
12
- #
13
- # # app/mailers/article_mailer.rb
14
- # class ArticleMailer < Merb::MailController
15
- #
16
- # def notify
17
- # @user = params[:user]
18
- # render_mail
19
- # end
20
- #
21
- # end
22
- #
23
- # You also can access the params hash for values passed with the
24
- # Controller.send_mail method. See also the documentation for
25
- # render_mail to see all the ways it can be called.
26
- #
27
- # Create a template in a subdirectory of app/mailers/views that corresponds
28
- # to the controller and action name. Put plain text and ERB tags here:
29
- #
30
- # # app/mailers/views/article_mailer/notify.text.erb
31
- # Hey, <%= @user.name %>,
32
- #
33
- # We're running a sale on dog bones!
34
- #
35
- # Finally, call the Controller.send_mail method from a standard
36
- # Merb controller.
37
- #
38
- # class Articles < Application
39
- #
40
- # def index
41
- # @user = User.find_by_name('louie')
42
- #
43
- # send_mail(ArticleMailer, :notify, {
44
- # :from => "me@example.com",
45
- # :to => "louie@example.com",
46
- # :subject => "Sale on Dog Bones!"
47
- # }, { :user => @user })
48
- # render
49
- # end
50
- #
51
- # end
52
- #
53
- # Note: If you don't pass a fourth argument to Controller.send_mail,
54
- # the controller's params will be sent to the MailController subclass
55
- # as params. However, you can explicitly send a hash of objects that
56
- # will populate the params hash instead. In either case, you must
57
- # set instance variables in the MailController's actions if you
58
- # want to use them in the MailController's views.
59
- #
60
- # The MailController class is very powerful. You can:
61
- #
62
- # * Send multipart email with a single call to render_mail.
63
- # * Attach files.
64
- # * Render layouts and other templates.
65
- # * Use any template engine supported by Merb.
66
-
67
- class MailController < AbstractController
68
-
69
- self._template_root = File.expand_path(self._template_root / "../mailers/views")
70
- class_inheritable_accessor :_mailer_klass
71
- self._mailer_klass = Merb::Mailer
72
-
73
- attr_accessor :params, :mailer, :mail
74
- attr_reader :session, :base_controller
75
-
76
- # You can initialize a MailController with a series of parameters that can
77
- # be used by methods in the class. You can also pass in a controller
78
- # object, which will be available to the MailController methods as
79
- # base_controller.
80
- def initialize(params = {}, controller = nil)
81
- @params = params
82
- @base_controller = controller
83
- @session = (controller && controller.session) || {}
84
- super
85
- end
86
-
87
- def filters_halted
88
- end
89
-
90
- # Allows you to render various types of things into the text and HTML parts
91
- # of an email If you include just text, the email will be sent as
92
- # plain-text. If you include HTML, the email will be sent as a multi-part
93
- # email.
94
- #
95
- # There are a lot of ways to use render_mail, but it works similarly to the
96
- # default Merb render method.
97
- #
98
- # First of all, you'll need to store email files in your
99
- # app/mailers/views directory. They should be under a directory that
100
- # matches the name of your mailer (e.g. TestMailer's views would be stored
101
- # under test_mailer).
102
- #
103
- # The files themselves should be named action_name.mime_type.extension. For
104
- # example, an erb template that should be the HTML part of the email, and
105
- # rendered from the "foo" action would be named foo.html.erb.
106
- #
107
- # The only mime-types currently supported are "html" and "text", which
108
- # correspond to text/html and text/plain respectively. All template systems
109
- # supported by your app are available to MailController, and the extensions
110
- # are the same as they are throughout the rest of Merb.
111
- #
112
- # render_mail can take any of the following option patterns:
113
- #
114
- # render_mail
115
- #
116
- # will attempt to render the current action. If the current action is
117
- # "foo", this is identical to render_mail :foo.
118
- #
119
- # render_mail :foo
120
- #
121
- # checks for foo.html.ext and foo.text.ext and applies them as appropriate.
122
- #
123
- # render_mail :action => {:html => :foo, :text => :bar}
124
- #
125
- # checks for foo.html.ext and bar.text.ext in the view directory of the
126
- # current controller and adds them to the mail object if found
127
- #
128
- # render_mail :template => {:html => "foo/bar", :text => "foo/baz"}
129
- #
130
- # checks for bar.html.ext and baz.text.ext in the foo directory and adds
131
- # them to the mail object if found.
132
- #
133
- # render_mail :html => :foo, :text => :bar
134
- #
135
- # the same as render_mail :action => {html => :foo, :text => :bar }
136
- #
137
- # render_mail :html => "FOO", :text => "BAR"
138
- #
139
- # adds the text "FOO" as the html part of the email and the text "BAR" as
140
- # the text part of the email. The difference between the last two examples
141
- # is that symbols represent actions to render, while string represent the
142
- # literal text to render. Note that you can use regular render methods
143
- # instead of literal strings here, like:
144
- #
145
- # render_mail :html => render(:action => :foo)
146
- #
147
- # but you're probably better off just using render_mail :action at that
148
- # point.
149
- #
150
- # You can also mix and match:
151
- #
152
- # render_mail :action => {:html => :foo}, :text => "BAR"
153
- #
154
- # which would be identical to:
155
- #
156
- # render_mail :html => :foo, :text => "BAR"
157
- def render_mail(options = @method)
158
- @_missing_templates = false # used to make sure that at least one template was found
159
- # # If the options are not a hash, normalize to an action hash
160
- options = {:action => {:html => options, :text => options}} if !options.is_a?(Hash)
161
-
162
- # Take care of the options
163
- use_options = {}
164
- opts = options.dup
165
- actions = opts.delete(:action) if opts[:action].is_a?(Hash)
166
- templates = opts.delete(:template) if opts[:template].is_a?(Hash)
167
-
168
- # Prepare the options hash for each format
169
- # We need to delete anything relating to the other format here
170
- # before we try to render the template.
171
- [:html, :text].each do |fmt|
172
- opts_hash = use_options[fmt] = {}
173
- opts_hash[fmt] = opts.delete(fmt)
174
- opts_hash[fmt] ||= actions[fmt] if actions && actions[fmt]
175
- opts_hash[:tempalte] = templates[fmt] if templates && templates[fmt]
176
- end
177
-
178
- # Send the result to the mailer
179
- { :html => "rawhtml=", :text => "text="}.each do |fmt,meth|
180
- begin
181
- value = render use_options[fmt].merge!(opts).merge!(:clean_context => true, :format => fmt)
182
- @mail.send(meth,value) unless value.nil? || value.empty?
183
- rescue => e
184
- # An error should be logged if no template is found instead of an error raised
185
- if @_missing_templates
186
- Merb.logger.error(e)
187
- else
188
- @_missing_templates = true
189
- end
190
- end
191
- end
192
- @mail
193
- end
194
-
195
- # Attaches a file or multiple files to an email. You call this from a
196
- # method in your MailController (including a before filter).
197
- #
198
- # attach File.open("foo")
199
- # attach [File.open("foo"), File.open("bar")]
200
- #
201
- # You can also include the filename, mime-type, or headers in the
202
- # subsequent parameters.
203
- #
204
- # If you are passing an array of files, you should use an array of the
205
- # allowed parameters:
206
- #
207
- # attach [[File.open("foo"), "bar", "text/html"], [File.open("baz"),
208
- # "bat", "text/css"]
209
- #
210
- # which would attach two files ("foo" and "baz" in the filesystem) as
211
- # "bar" and "bat" respectively. It would also set the mime-type as
212
- # "text/html" and "text/css" respectively.
213
- def attach( file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil,
214
- type = nil, headers = nil)
215
- @mail.attach(file_or_files, filename, type, headers)
216
- end
217
-
218
- # take a method name to dispatch to and mail parameters for the MailFactory object.
219
- #
220
- # Available mail parameters include:
221
- # to
222
- # from
223
- # replyto
224
- # subject
225
- # body
226
- # cc
227
- #
228
- # Other parameters passed in will be interpreted as email headers, with _'s converted
229
- # to -'s.
230
- def dispatch_and_deliver(method, mail_params)
231
- @mailer = self.class._mailer_klass.new(mail_params)
232
- @mail = @mailer.mail
233
- @method = method
234
-
235
- # dipatch and render use params[:action], so set it
236
- params[:action] = method
237
- body = dispatch method
238
- if !@mail.html.blank? || !@mail.text.blank?
239
- @mailer.deliver!
240
- Merb.logger.info "#{method} sent to #{@mail.to} about #{@mail.subject}"
241
- else
242
- Merb.logger.info "#{method} was not sent because nothing was rendered for it"
243
- end
244
- end
245
-
246
- # A convenience method that creates a blank copy of the MailController and runs
247
- # dispatch_and_deliver on it.
248
- def self.dispatch_and_deliver(method, mail_params, send_params = {})
249
- new(send_params).dispatch_and_deliver method, mail_params
250
- end
251
-
252
- protected
253
- def route
254
- @base_controller.route if @base_controller
255
- end
256
-
257
- private
258
- # This method is here to overwrite the one in the general_controller mixin
259
- # The method ensures that when a url is generated with a hash, it contains a controller
260
- def get_controller_for_url_generation(opts)
261
- controller = opts[:controller] || ( @base_controller.params[:controller] if @base_controller)
262
- raise "No Controller Specified for url()" unless controller
263
- controller
264
- end
265
-
266
-
267
- end
268
- end
data/lib/merb/mailer.rb DELETED
@@ -1,87 +0,0 @@
1
- begin
2
- require 'mailfactory'
3
- require 'net/smtp'
4
- rescue LoadError
5
- puts "You need to install the mailfactory gem to use Merb::Mailer"
6
- Merb.logger.warn "You need to install the mailfactory gem to use Merb::Mailer"
7
- end
8
-
9
- class MailFactory
10
- attr_reader :html, :text
11
- end
12
-
13
- module Merb
14
-
15
- # You'll need a simple config like this in merb_init.rb if you want
16
- # to actually send mail:
17
- #
18
- # Merb::Mailer.config = {
19
- # :host=>'smtp.yourserver.com',
20
- # :port=>'25',
21
- # :user=>'user',
22
- # :pass=>'pass',
23
- # :auth=>:plain # :plain, :login, :cram_md5, the default is no auth
24
- # }
25
- #
26
- # or
27
- #
28
- # Merb::Mailer.config = {:sendmail_path => '/somewhere/odd'}
29
- # Merb::Mailer.delivery_method = :sendmail
30
- #
31
- # You could send mail manually like this (but it's better to use
32
- # a MailController instead).
33
- #
34
- # m = Merb::Mailer.new :to => 'foo@bar.com',
35
- # :from => 'bar@foo.com',
36
- # :subject => 'Welcome to whatever!',
37
- # :body => partial(:sometemplate)
38
- # m.deliver!
39
-
40
- class Mailer
41
-
42
- class_inheritable_accessor :config, :delivery_method, :deliveries
43
- attr_accessor :mail
44
- self.deliveries = []
45
-
46
- def sendmail
47
- sendmail = IO.popen("#{config[:sendmail_path]} #{@mail.to}", 'w+')
48
- sendmail.puts @mail.to_s
49
- sendmail.close
50
- end
51
-
52
- # :plain, :login, or :cram_md5
53
- def net_smtp
54
- Net::SMTP.start(config[:host], config[:port].to_i, config[:domain],
55
- config[:user], config[:pass], config[:auth]) { |smtp|
56
- smtp.send_message(@mail.to_s, @mail.from.first, @mail.to.to_s.split(/[,;]/))
57
- }
58
- end
59
-
60
- def test_send
61
- deliveries << @mail
62
- end
63
-
64
- def deliver!
65
- send(delivery_method || :net_smtp)
66
- end
67
-
68
- def attach(file_or_files, filename = file_or_files.is_a?(File) ? File.basename(file_or_files.path) : nil,
69
- type = nil, headers = nil)
70
- if file_or_files.is_a?(Array)
71
- file_or_files.each {|k,v| @mail.add_attachment_as k, *v}
72
- else
73
- raise ArgumentError, "You did not pass in a file. Instead, you sent a #{file_or_files.class}" if !file_or_files.is_a?(File)
74
- @mail.add_attachment_as(file_or_files, filename, type, headers)
75
- end
76
- end
77
-
78
- def initialize(o={})
79
- self.config = {:sendmail_path => '/usr/sbin/sendmail'} if config.nil?
80
- o[:rawhtml] = o.delete(:html)
81
- m = MailFactory.new()
82
- o.each { |k,v| m.send "#{k}=", v }
83
- @mail = m
84
- end
85
-
86
- end
87
- end