From dba196cb7f8d34b93f6872e4a43737bb52019065 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 17 Jan 2010 03:26:20 +0530 Subject: Merge docrails --- actionmailer/lib/action_mailer/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index b9a01356ba..5be1beaedb 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -36,7 +36,7 @@ module ActionMailer #:nodoc: # * cc - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the Cc: header. # * bcc - Takes one or more email addresses. These addresses will receive a blind carbon copy of your email. Sets the Bcc: header. # * reply_to - Takes one or more email addresses. These addresses will be listed as the default recipients when replying to your email. Sets the Reply-To: header. - # * sent_on - The date on which the message was sent. If not set, the header wil be set by the delivery agent. + # * sent_on - The date on which the message was sent. If not set, the header will be set by the delivery agent. # * content_type - Specify the content type of the message. Defaults to text/plain. # * headers - Specify additional headers to be set for the message, e.g. headers 'X-Mail-Count' => 107370. # -- cgit v1.2.3 From a0374582ff6d403a48b018df666b064f4c261f20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 19 Jan 2010 01:15:57 +0100 Subject: Bring body(Hash) behavior back. --- actionmailer/lib/action_mailer/base.rb | 17 ++++++++-- actionmailer/lib/action_mailer/deprecated_body.rb | 38 ++++++++++------------- 2 files changed, 31 insertions(+), 24 deletions(-) (limited to 'actionmailer/lib') diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 5be1beaedb..928fed4777 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -23,8 +23,7 @@ module ActionMailer #:nodoc: # bcc ["bcc@example.com", "Order Watcher "] # from "system@example.com" # subject "New account information" - # - # @account = recipient + # body :account => recipient # end # end # @@ -523,6 +522,20 @@ module ActionMailer #:nodoc: private + # 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) + super # Run deprecation hooks + + if object.is_a?(Hash) + @assigns_set = true + object.each { |k, v| instance_variable_set(:"@#{k}", v) } + end + end + # Set up the default values for the various instance variables of this # mailer. Subclasses may override this method to provide different # defaults. diff --git a/actionmailer/lib/action_mailer/deprecated_body.rb b/actionmailer/lib/action_mailer/deprecated_body.rb index 20b0989a85..5379b33a54 100644 --- a/actionmailer/lib/action_mailer/deprecated_body.rb +++ b/actionmailer/lib/action_mailer/deprecated_body.rb @@ -1,15 +1,13 @@ module ActionMailer # TODO Remove this module all together in a next release. Ensure that super - # hooks in ActionMailer::Base are removed as well. + # hooks and @assigns_set in ActionMailer::Base are removed as well. module DeprecatedBody - def self.included(base) - base.class_eval do - # Define the body of the message. This is either a Hash (in which case it - # specifies the variables to pass to the template when it is rendered), - # or a string, in which case it specifies the actual text of the message. - adv_attr_accessor :body - end - end + extend ActionMailer::AdvAttrAccessor + + # Define the body of the message. This is either a Hash (in which case it + # specifies the variables to pass to the template when it is rendered), + # or a string, in which case it specifies the actual text of the message. + adv_attr_accessor :body def initialize_defaults(method_name) @body ||= {} @@ -18,32 +16,28 @@ module ActionMailer def attachment(params, &block) if params[:body] ActiveSupport::Deprecation.warn('attachment :body => "string" is deprecated. To set the body of an attachment ' << - 'please use :data instead, like attachment :data => "string".', caller[0,10]) + 'please use :data instead, like attachment :data => "string"', caller[0,10]) params[:data] = params.delete(:body) end end def create_parts - if String === @body - ActiveSupport::Deprecation.warn('body is deprecated. To set the body with a text ' << - 'call render(:text => "body").', caller[0,10]) + if String === @body && !defined?(@assigns_set) + ActiveSupport::Deprecation.warn('body(String) is deprecated. To set the body with a text ' << + 'call render(:text => "body")', caller[0,10]) self.response_body = @body - elsif @body.is_a?(Hash) && !@body.empty? - ActiveSupport::Deprecation.warn('body is deprecated. To set assigns simply ' << - 'use instance variables', caller[0,10]) - @body.each { |k, v| instance_variable_set(:"@#{k}", v) } + elsif self.response_body + @body = self.response_body end end def render(*args) options = args.last.is_a?(Hash) ? args.last : {} if options[:body] - ActiveSupport::Deprecation.warn(':body is deprecated. To set assigns simply ' << - 'use instance variables', caller[0,1]) + ActiveSupport::Deprecation.warn(':body in render deprecated. Please call body ' << + 'with a hash instead', caller[0,1]) - options.delete(:body).each do |k, v| - instance_variable_set(:"@#{k}", v) - end + body options.delete(:body) end super -- cgit v1.2.3 From f00cbf78725caa44ca46150c4708f9a4fad0e023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 19 Jan 2010 01:35:41 +0100 Subject: Bring render_message back for 2.3 compatibility. --- actionmailer/lib/action_mailer/base.rb | 42 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) (limited to 'actionmailer/lib') 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 -- cgit v1.2.3