0
# Sending mail from a controller involves three steps:
0
# * Set mail settings in merb_init.rb (Not shown here...see the Mailer docs).
0
@@ -62,43 +62,64 @@ module Merb
0
# * Render layouts and other templates.
0
# * Use any template engine supported by Merb.
0
class MailController < AbstractController
0
class_inheritable_accessor :_mailer_klass
0
self._mailer_klass = Merb::Mailer
0
attr_accessor :params, :mailer, :mail
0
attr_reader :session, :base_controller
0
+ # action<~to_s>:: The name of the action that will be rendered.
0
+ # The mime-type of the template that will be rendered. Defaults to nil.
0
+ # The name of the controller that will be rendered. Defaults to
0
+ # String:: The template location, i.e. ":controller/:action.:type".
0
def _template_location(action, type = nil, controller = controller_name)
0
"#{controller}/#{action}.#{type}"
0
- # You can initialize a MailController with a series of parameters that can
0
- # be used by methods in the class. You can also pass in a controller
0
- # object, which will be available to the MailController methods as
0
+ # params<Hash>:: Configuration parameters for the MailController.
0
+ # controller<Merb::Controller>:: The base controller.
0
def initialize(params = {}, controller = nil)
0
@base_controller = controller
0
@session = (controller && controller.session) || {}
0
+ # Sets the template root to the default mailer view directory.
0
+ # The Merb::MailController inheriting from the base class.
0
def self.inherited(klass)
0
klass.class_eval %{self._template_root = Merb.dir_for(:mailer) / "views"}
0
+ # Override filters halted to return nothing.
0
# Allows you to render various types of things into the text and HTML parts
0
# of an email If you include just text, the email will be sent as
0
# plain-text. If you include HTML, the email will be sent as a multi-part
0
+ # options<~to_s, Hash>::
0
+ # Options for rendering the email or an action name. See examples below
0
# There are a lot of ways to use render_mail, but it works similarly to the
0
# default Merb render method.
0
@@ -165,13 +186,13 @@ module Merb
0
@_missing_templates = false # used to make sure that at least one template was found
0
# # If the options are not a hash, normalize to an action hash
0
options = {:action => {:html => options, :text => options}} if !options.is_a?(Hash)
0
# Take care of the options
0
actions = opts.delete(:action) if opts[:action].is_a?(Hash)
0
templates = opts.delete(:template) if opts[:template].is_a?(Hash)
0
# Prepare the options hash for each format
0
# We need to delete anything relating to the other format here
0
# before we try to render the template.
0
@@ -183,13 +204,13 @@ module Merb
0
# debugger if $DEBUGGER
0
# Send the result to the mailer
0
{ :html => "rawhtml=", :text => "text="}.each do |fmt,meth|
0
local_opts = opts.merge(:format => fmt)
0
local_opts.merge!(:layout => false) if opts_hash[fmt].is_a?(String)
0
value = render opts_hash[fmt], local_opts
0
@mail.send(meth,value) unless value.nil? || value.empty?
0
@@ -203,21 +224,27 @@ module Merb
0
# Attaches a file or multiple files to an email. You call this from a
0
# method in your MailController (including a before filter).
0
+ # file_or_files<File, Array[File]>:: File(s) to attach.
0
+ # The attachment MIME type. If left out, it will be determined from
0
+ # headers<String, Array>:: Additional attachment headers.
0
# attach File.open("foo")
0
# attach [File.open("foo"), File.open("bar")]
0
- # You can also include the filename, mime-type, or headers in the
0
- # subsequent parameters.
0
# If you are passing an array of files, you should use an array of the
0
# attach [[File.open("foo"), "bar", "text/html"], [File.open("baz"),
0
# which would attach two files ("foo" and "baz" in the filesystem) as
0
# "bar" and "bat" respectively. It would also set the mime-type as
0
@@ -226,24 +253,27 @@ module Merb
0
type = nil, headers = nil)
0
@mailer.attach(file_or_files, filename, type, headers)
0
- # take a method name to dispatch to and mail parameters for the MailFactory object.
0
- # Available mail parameters include:
0
- # Other parameters passed in will be interpreted as email headers, with _'s converted
0
+ # method<~to_s>:: The method name to dispatch to.
0
+ # mail_params<Hash>:: Parameters to send to MailFactory (see below).
0
+ # ==== Options (mail_params)
0
+ # MailFactory recognizes the following parameters:
0
+ # Other parameters passed in will be interpreted as email headers, with
0
+ # underscores converted to dashes.
0
def dispatch_and_deliver(method, mail_params)
0
@mailer = self.class._mailer_klass.new(mail_params)
0
# dispatch and render use params[:action], so set it
0
self.action_name = method
0
@@ -256,26 +286,46 @@ module Merb
0
- # A convenience method that creates a blank copy of the MailController and runs
0
- # dispatch_and_deliver on it.
0
+ # A convenience method that creates a blank copy of the MailController and
0
+ # runs dispatch_and_deliver on it.
0
+ # method<~to_s>:: The method name to dispatch to.
0
+ # mail_params<Hash>:: Parameters to send to MailFactory.
0
+ # send_params<Hash>:: Configuration parameters for the MailController.
0
def self.dispatch_and_deliver(method, mail_params, send_params = {})
0
new(send_params).dispatch_and_deliver method, mail_params
0
+ # Hash:: The route from base controller.
0
@base_controller.route if @base_controller
0
# This method is here to overwrite the one in the general_controller mixin
0
- # The method ensures that when a url is generated with a hash, it contains a controller
0
+ # The method ensures that when a url is generated with a hash, it contains
0
+ # opts<Hash>:: The options to get the controller from (see below).
0
+ # :controller<Merb::Controller>:: The controller.
0
+ # The controller. If no controller was specified in opts, attempt to find
0
+ # it in the base controller params.
0
def get_controller_for_url_generation(opts)
0
controller = opts[:controller] || ( @base_controller.params[:controller] if @base_controller)
0
- raise "No Controller Specified for url()" unless controller
0
+ raise "No Controller Specified for url()" unless controller
0
\ No newline at end of file
Comments
No one has commented yet.