aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-19 01:35:41 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-19 01:36:07 +0100
commitf00cbf78725caa44ca46150c4708f9a4fad0e023 (patch)
tree85decb3287d4ecc2562371954ddc4a803e18d643 /actionmailer
parenta0374582ff6d403a48b018df666b064f4c261f20 (diff)
downloadrails-f00cbf78725caa44ca46150c4708f9a4fad0e023.tar.gz
rails-f00cbf78725caa44ca46150c4708f9a4fad0e023.tar.bz2
rails-f00cbf78725caa44ca46150c4708f9a4fad0e023.zip
Bring render_message back for 2.3 compatibility.
Diffstat (limited to 'actionmailer')
-rw-r--r--actionmailer/lib/action_mailer/base.rb42
-rw-r--r--actionmailer/test/mail_service_test.rb4
2 files changed, 33 insertions, 13 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 928fed4777..a8233512ab 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -143,12 +143,13 @@ module ActionMailer #:nodoc:
# subject "New account information"
# from "system@example.com"
# content_type "multipart/alternative"
+ # body :account => recipient
#
# part :content_type => "text/html",
- # :body => render_message("signup-as-html", :account => recipient)
+ # :data => render_message("signup-as-html")
#
# part "text/plain" do |p|
- # p.body = render_message("signup-as-plain", :account => recipient)
+ # p.body = render_message("signup-as-plain")
# p.content_transfer_encoding = "base64"
# end
# end
@@ -453,11 +454,13 @@ module ActionMailer #:nodoc:
# body, headers, etc.) can be set on it.
def part(params)
params = {:content_type => params} if String === params
+
if custom_headers = params.delete(:headers)
ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' <<
'Please just pass in custom headers directly.', caller[0,10])
params.merge!(custom_headers)
end
+
part = Mail::Part.new(params)
yield part if block_given?
@parts << part
@@ -475,6 +478,20 @@ module ActionMailer #:nodoc:
part(params, &block)
end
+ # Allow you to set assigns for your template:
+ #
+ # body :greetings => "Hi"
+ #
+ # Will make @greetings available in the template to be rendered.
+ def body(object=nil)
+ returning(super) do # Run deprecation hooks
+ if object.is_a?(Hash)
+ @assigns_set = true
+ object.each { |k, v| instance_variable_set(:"@#{k}", v) }
+ end
+ end
+ end
+
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
# will be initialized according to the named method. If not, the mailer will
# remain uninitialized (useful when you only need to invoke the "receive"
@@ -522,17 +539,20 @@ module ActionMailer #:nodoc:
private
- # Allow you to set assigns for your template:
+ # Render a message but does not set it as mail body. Useful for rendering
+ # data for part and attachments.
#
- # body :greetings => "Hi"
+ # Examples:
#
- # Will make @greetings available in the template to be rendered.
- def body(object=nil)
- super # Run deprecation hooks
-
- if object.is_a?(Hash)
- @assigns_set = true
- object.each { |k, v| instance_variable_set(:"@#{k}", v) }
+ # render_message "special_message"
+ # render_message :template => "special_message"
+ # render_message :inline => "<%= 'Hi!' %>"
+ def render_message(object)
+ case object
+ when String
+ render_to_body(:template => object)
+ else
+ render_to_body(object)
end
end
diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb
index d1c4f7b5e9..f87d9b2e5b 100644
--- a/actionmailer/test/mail_service_test.rb
+++ b/actionmailer/test/mail_service_test.rb
@@ -120,11 +120,11 @@ class TestMailer < ActionMailer::Base
content_type "multipart/alternative"
part "text/plain" do |p|
- p.body = "blah"
+ p.body = render_message(:text => "blah")
end
part "text/html" do |p|
- p.body = "<b>blah</b>"
+ p.body = render_message(:inline => "<%= content_tag(:b, 'blah') %>")
end
end