Move mailer initialization to a separate (overridable) method, so that subclasses may alter the various defaults #1727

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2035 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2005-08-22 20:53:27 +00:00
parent b13efaf985
commit f474f337b1
2 changed files with 17 additions and 9 deletions

@ -1,5 +1,7 @@
*SVN*
* Move mailer initialization to a separate (overridable) method, so that subclasses may alter the various defaults #1727
* Look at content-location header (if available) to determine filename of attachments #1670
* ActionMailer::Base.deliver(email) had been accidentally removed, but was documented in the Rails book #1849

@ -199,15 +199,7 @@ def initialize(method_name=nil, *parameters) #:nodoc:
# Initialize the mailer via the given +method_name+. The body will be
# rendered and a new TMail::Mail object created.
def create!(method_name, *parameters) #:nodoc:
@bcc = @cc = @from = @recipients = @sent_on = @subject = nil
@charset = @@default_charset.dup
@content_type = @@default_content_type.dup
@implicit_parts_order = @@default_implicit_parts_order.dup
@template = method_name
@parts = []
@headers = {}
@body = {}
initialize_defaults(method_name)
send(method_name, *parameters)
# If an explicit, textual body has not been set, we check assumptions.
@ -268,6 +260,20 @@ def deliver!(mail = @mail) #:nodoc:
end
private
# Set up the default values for the various instance variables of this
# mailer. Subclasses may override this method to provide different
# defaults.
def initialize_defaults(method_name)
@bcc = @cc = @from = @recipients = @sent_on = @subject = nil
@charset = @@default_charset.dup
@content_type = @@default_content_type.dup
@implicit_parts_order = @@default_implicit_parts_order.dup
@template = method_name
@parts = []
@headers = {}
@body = {}
end
def render_message(method_name, body)
initialize_template_class(body).render_file(method_name)
end