diff options
Diffstat (limited to 'actionmailer/lib/action_mailer')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 74 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/collector.rb | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/log_subscriber.rb | 6 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 9 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railtie.rb | 5 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_case.rb | 26 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_helper.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/version.rb | 4 |
8 files changed, 77 insertions, 53 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index cb289fd693..c508512ff6 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,8 +1,6 @@ require 'mail' require 'action_mailer/collector' -require 'active_support/core_ext/array/wrap' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/proc' require 'active_support/core_ext/string/inflections' require 'active_support/core_ext/hash/except' require 'action_mailer/log_subscriber' @@ -16,15 +14,15 @@ module ActionMailer #:nodoc: # # $ rails generate mailer Notifier # - # The generated model inherits from <tt>ActionMailer::Base</tt>. Emails are defined by creating methods - # within the model which are then used to set variables to be used in the mail template, to - # change options on the mail, or to add attachments. + # The generated model inherits from <tt>ActionMailer::Base</tt>. A mailer model defines methods + # used to generate an email message. In these methods, you can setup variables to be used in + # the mailer views, options on the mail itself such as the <tt>:from</tt> address, and attachments. # # Examples: # # class Notifier < ActionMailer::Base # default :from => 'no-reply@example.com', - # :return_path => 'system@example.com' + # :return_path => 'system@example.com' # # def welcome(recipient) # @account = recipient @@ -100,12 +98,12 @@ module ActionMailer #:nodoc: # You can even use Action Pack helpers in these views. For example: # # You got a new note! - # <%= truncate(@note.body, 25) %> + # <%= truncate(@note.body, :length => 25) %> # # If you need to access the subject, from or the recipients in the view, you can do that through message object: # # You got a new note from <%= message.from %>! - # <%= truncate(@note.body, 25) %> + # <%= truncate(@note.body, :length => 25) %> # # # = Generating URLs @@ -122,8 +120,8 @@ module ActionMailer #:nodoc: # # <%= users_url(:host => "example.com") %> # - # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the - # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will + # You should use the <tt>named_route_url</tt> style (which generates absolute URLs) and avoid using the + # <tt>named_route_path</tt> style (which generates relative URLs), since clients reading the mail will # have no concept of a current URL from which to determine a relative path. # # It is also possible to set a default host that will be used in all mailers by setting the <tt>:host</tt> @@ -132,7 +130,7 @@ module ActionMailer #:nodoc: # config.action_mailer.default_url_options = { :host => "example.com" } # # When you decide to set a default <tt>:host</tt> for your mailers, then you need to make sure to use the - # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. Since the <tt>url_for</tt> view helper + # <tt>:only_path => false</tt> option when using <tt>url_for</tt>. Since the <tt>url_for</tt> view helper # will generate relative URLs by default when a <tt>:host</tt> option isn't explicitly provided, passing # <tt>:only_path => false</tt> will ensure that absolute URLs are generated. # @@ -149,8 +147,8 @@ module ActionMailer #:nodoc: # # = Multipart Emails # - # Multipart messages can also be used implicitly because Action Mailer will automatically detect and use - # multipart templates, where each template is named after the name of the action, followed by the content + # Multipart messages can also be used implicitly because Action Mailer will automatically detect and use + # multipart templates, where each template is named after the name of the action, followed by the content # type. Each such detected template will be added as a separate part to the message. # # For example, if the following templates exist: @@ -269,6 +267,33 @@ module ActionMailer #:nodoc: # set something in the defaults using a proc, and then set the same thing inside of your # mailer method, it will get over written by the mailer method. # + # = Callbacks + # + # You can specify callbacks using before_filter and after_filter for configuring your messages. + # This may be useful, for example, when you want to add default inline attachments for all + # messages sent out by a certain mailer class: + # + # class Notifier < ActionMailer::Base + # before_filter :add_inline_attachment! + # + # def welcome + # mail + # end + # + # private + # + # def add_inline_attachment! + # attachments.inline["footer.jpg"] = File.read('/path/to/filename.jpg') + # end + # end + # + # Callbacks in ActionMailer are implemented using AbstractController::Callbacks, so you + # can define and configure callbacks in the same manner that you would use callbacks in + # classes that inherit from ActionController::Base. + # + # Note that unless you have a specific reason to do so, you should prefer using before_filter + # rather than after_filter in your ActionMailer classes so that headers are parsed properly. + # # = Configuration options # # These options are specified on the class level, like @@ -332,8 +357,9 @@ module ActionMailer #:nodoc: include AbstractController::Helpers include AbstractController::Translation include AbstractController::AssetPaths + include AbstractController::Callbacks - self.protected_instance_variables = %w(@_action_has_layout) + self.protected_instance_variables = [:@_action_has_layout] helper ActionMailer::MailHelper @@ -410,7 +436,7 @@ module ActionMailer #:nodoc: # and passing a Mail::Message will do nothing except tell the logger you sent the email. def deliver_mail(mail) #:nodoc: ActiveSupport::Notifications.instrument("deliver.action_mailer") do |payload| - self.set_payload_for_mail(payload, mail) + set_payload_for_mail(payload, mail) yield # Let Mail do the delivery actions end end @@ -524,7 +550,7 @@ module ActionMailer #:nodoc: # # * <tt>:subject</tt> - The subject of the message, if this is omitted, Action Mailer will # ask the Rails I18n class for a translated <tt>:subject</tt> in the scope of - # <tt>[:actionmailer, mailer_scope, action_name]</tt> or if this is missing, will translate the + # <tt>[mailer_scope, action_name]</tt> or if this is missing, will translate the # humanized version of the <tt>action_name</tt> # * <tt>:to</tt> - Who the message is destined for, can be a string of addresses, or an array # of addresses. @@ -603,9 +629,6 @@ module ActionMailer #:nodoc: # end # def mail(headers={}, &block) - # Guard flag to prevent both the old and the new API from firing - # Should be removed when old API is removed - @mail_was_called = true m = @_message # At the beginning, do not consider class default for parts order neither content_type @@ -613,8 +636,9 @@ module ActionMailer #:nodoc: parts_order = headers[:parts_order] # Call all the procs (if any) - default_values = self.class.default.merge(self.class.default) do |k,v| - v.respond_to?(:call) ? v.bind(self).call : v + class_default = self.class.default + default_values = class_default.merge(class_default) do |k,v| + v.respond_to?(:to_proc) ? instance_eval(&v) : v end # Handle defaults @@ -668,11 +692,11 @@ module ActionMailer #:nodoc: end end - # Translates the +subject+ using Rails I18n class under <tt>[:actionmailer, mailer_scope, action_name]</tt> scope. + # Translates the +subject+ using Rails I18n class under <tt>[mailer_scope, action_name]</tt> scope. # If it does not find a translation for the +subject+ under the specified scope it will default to a # humanized version of the <tt>action_name</tt>. def default_i18n_subject #:nodoc: - mailer_scope = self.class.mailer_name.gsub('/', '.') + mailer_scope = self.class.mailer_name.tr('/', '.') I18n.t(:subject, :scope => [mailer_scope, action_name], :default => action_name.humanize) end @@ -707,8 +731,8 @@ module ActionMailer #:nodoc: end def each_template(paths, name, &block) #:nodoc: - templates = lookup_context.find_all(name, Array.wrap(paths)) - templates.uniq_by { |t| t.formats }.each(&block) + templates = lookup_context.find_all(name, Array(paths)) + templates.uniq { |t| t.formats }.each(&block) end def create_parts_from_responses(m, responses) #:nodoc: diff --git a/actionmailer/lib/action_mailer/collector.rb b/actionmailer/lib/action_mailer/collector.rb index d03e085e83..17b22aea2a 100644 --- a/actionmailer/lib/action_mailer/collector.rb +++ b/actionmailer/lib/action_mailer/collector.rb @@ -22,9 +22,9 @@ module ActionMailer #:nodoc: def custom(mime, options={}) options.reverse_merge!(:content_type => mime.to_s) - @context.freeze_formats([mime.to_sym]) + @context.formats = [mime.to_sym] options[:body] = block_given? ? yield : @default_render.call @responses << options end end -end
\ No newline at end of file +end diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index 7ba57b19e0..a6c163832e 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -1,9 +1,7 @@ -require 'active_support/core_ext/array/wrap' - module ActionMailer class LogSubscriber < ActiveSupport::LogSubscriber def deliver(event) - recipients = Array.wrap(event.payload[:to]).join(', ') + recipients = Array(event.payload[:to]).join(', ') info("\nSent mail to #{recipients} (%1.fms)" % event.duration) debug(event.payload[:mail]) end @@ -19,4 +17,4 @@ module ActionMailer end end -ActionMailer::LogSubscriber.attach_to :action_mailer
\ No newline at end of file +ActionMailer::LogSubscriber.attach_to :action_mailer diff --git a/actionmailer/lib/action_mailer/mail_helper.rb b/actionmailer/lib/action_mailer/mail_helper.rb index 6f22adc479..2036883b22 100644 --- a/actionmailer/lib/action_mailer/mail_helper.rb +++ b/actionmailer/lib/action_mailer/mail_helper.rb @@ -1,11 +1,10 @@ module ActionMailer module MailHelper - # Uses Text::Format to take the text and format it, indented two spaces for - # each line, and wrapped at 72 columns. + # Take the text and format it, indented two spaces for each line, and wrapped at 72 columns. def block_format(text) - formatted = text.split(/\n\r\n/).collect { |paragraph| + formatted = text.split(/\n\r?\n/).collect { |paragraph| format_paragraph(paragraph) - }.join("\n") + }.join("\n\n") # Make list points stand on their own line formatted.gsub!(/[ ]*([*]+) ([^*]*)/) { |s| " #{$1} #{$2.strip}\n" } @@ -41,7 +40,7 @@ module ActionMailer sentences = [[]] text.split.each do |word| - if (sentences.last + [word]).join(' ').length > len + if sentences.first.present? && (sentences.last + [word]).join(' ').length > len sentences << [word] else sentences.last << word diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index 444754d0e9..5c03a29f0f 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -19,8 +19,9 @@ module ActionMailer options.stylesheets_dir ||= paths["public/stylesheets"].first # make sure readers methods get compiled - options.asset_path ||= app.config.asset_path - options.asset_host ||= app.config.asset_host + options.asset_path ||= app.config.asset_path + options.asset_host ||= app.config.asset_host + options.relative_url_root ||= app.config.relative_url_root ActiveSupport.on_load(:action_mailer) do include AbstractController::UrlFor diff --git a/actionmailer/lib/action_mailer/test_case.rb b/actionmailer/lib/action_mailer/test_case.rb index 63e18147f6..529140dfad 100644 --- a/actionmailer/lib/action_mailer/test_case.rb +++ b/actionmailer/lib/action_mailer/test_case.rb @@ -1,3 +1,4 @@ +require 'active_support/test_case' require 'active_support/core_ext/class/attribute' module ActionMailer @@ -15,9 +16,22 @@ module ActionMailer include TestHelper + included do + class_attribute :_mailer_class + setup :initialize_test_deliveries + setup :set_expected_mail + end + module ClassMethods def tests(mailer) - self._mailer_class = mailer + case mailer + when String, Symbol + self._mailer_class = mailer.to_s.camelize.constantize + when Module + self._mailer_class = mailer + else + raise NonInferrableMailerError.new(mailer) + end end def mailer_class @@ -35,8 +49,6 @@ module ActionMailer end end - module InstanceMethods - protected def initialize_test_deliveries @@ -64,16 +76,8 @@ module ActionMailer def read_fixture(action) IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action)) end - end - - included do - class_attribute :_mailer_class - setup :initialize_test_deliveries - setup :set_expected_mail - end end include Behavior - end end diff --git a/actionmailer/lib/action_mailer/test_helper.rb b/actionmailer/lib/action_mailer/test_helper.rb index 5beab87ad2..7204822395 100644 --- a/actionmailer/lib/action_mailer/test_helper.rb +++ b/actionmailer/lib/action_mailer/test_helper.rb @@ -1,7 +1,5 @@ module ActionMailer module TestHelper - extend ActiveSupport::Concern - # Asserts that the number of emails sent matches the given number. # # def test_emails diff --git a/actionmailer/lib/action_mailer/version.rb b/actionmailer/lib/action_mailer/version.rb index b74ba3cb0d..0cb5dc6d64 100644 --- a/actionmailer/lib/action_mailer/version.rb +++ b/actionmailer/lib/action_mailer/version.rb @@ -1,7 +1,7 @@ module ActionMailer module VERSION #:nodoc: - MAJOR = 3 - MINOR = 2 + MAJOR = 4 + MINOR = 0 TINY = 0 PRE = "beta" |