diff options
Diffstat (limited to 'actionmailer/lib')
-rw-r--r-- | actionmailer/lib/action_mailer.rb | 3 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 56 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/collector.rb | 4 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/delivery_methods.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/mail_helper.rb | 9 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/test_helper.rb | 2 | ||||
-rw-r--r-- | actionmailer/lib/rails/generators/mailer/templates/mailer.rb | 6 |
7 files changed, 51 insertions, 31 deletions
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb index 1045dd58ef..e45a1cd5ff 100644 --- a/actionmailer/lib/action_mailer.rb +++ b/actionmailer/lib/action_mailer.rb @@ -21,9 +21,6 @@ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ -actionpack_path = File.expand_path('../../../actionpack/lib', __FILE__) -$:.unshift(actionpack_path) if File.directory?(actionpack_path) && !$:.include?(actionpack_path) - require 'abstract_controller' require 'action_view' require 'action_mailer/version' diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 7d8852f961..4f0cff0612 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,9 +1,9 @@ require 'mail' require 'action_mailer/collector' 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 'active_support/core_ext/module/anonymous' require 'action_mailer/log_subscriber' module ActionMailer #:nodoc: @@ -15,15 +15,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 @@ -268,6 +268,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 @@ -331,6 +358,7 @@ module ActionMailer #:nodoc: include AbstractController::Helpers include AbstractController::Translation include AbstractController::AssetPaths + include AbstractController::Callbacks self.protected_instance_variables = [:@_action_has_layout] @@ -374,7 +402,7 @@ module ActionMailer #:nodoc: end def mailer_name - @mailer_name ||= name.underscore + @mailer_name ||= anonymous? ? "anonymous" : name.underscore end attr_writer :mailer_name alias :controller_path :mailer_name @@ -409,7 +437,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 @@ -459,7 +487,7 @@ module ActionMailer #:nodoc: self.class.mailer_name end - # Allows you to pass random and unusual headers to the new +Mail::Message+ object + # Allows you to pass random and unusual headers to the new <tt>Mail::Message</tt> object # which will add them to itself. # # headers['X-Special-Domain-Specific-Header'] = "SecretValue" @@ -470,7 +498,7 @@ module ActionMailer #:nodoc: # headers 'X-Special-Domain-Specific-Header' => "SecretValue", # 'In-Reply-To' => incoming.message_id # - # The resulting Mail::Message will have the following in it's header: + # The resulting Mail::Message will have the following in its header: # # X-Special-Domain-Specific-Header: SecretValue def headers(args=nil) @@ -602,9 +630,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 @@ -612,8 +637,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 @@ -671,7 +697,7 @@ module ActionMailer #:nodoc: # 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 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/delivery_methods.rb b/actionmailer/lib/action_mailer/delivery_methods.rb index d1467fb526..3b38dbccc7 100644 --- a/actionmailer/lib/action_mailer/delivery_methods.rb +++ b/actionmailer/lib/action_mailer/delivery_methods.rb @@ -65,7 +65,7 @@ module ActionMailer when NilClass raise "Delivery method cannot be nil" when Symbol - if klass = delivery_methods[method.to_sym] + if klass = delivery_methods[method] mail.delivery_method(klass, send(:"#{method}_settings")) else raise "Invalid delivery method #{method.inspect}" 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/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/rails/generators/mailer/templates/mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb index aaa1f79732..edcfb4233d 100644 --- a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb +++ b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb @@ -1,17 +1,17 @@ <% module_namespacing do -%> class <%= class_name %> < ActionMailer::Base - default <%= key_value :from, '"from@example.com"' %> + default from: "from@example.com" <% actions.each do |action| -%> # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # - # en.<%= file_path.gsub("/",".") %>.<%= action %>.subject + # en.<%= file_path.tr("/",".") %>.<%= action %>.subject # def <%= action %> @greeting = "Hi" - mail <%= key_value :to, '"to@example.org"' %> + mail to: "to@example.org" end <% end -%> end |