diff options
author | José Valim <jose.valim@gmail.com> | 2009-10-17 10:31:11 -0300 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-11-01 02:23:47 +0100 |
commit | a9751a7034c5a2a49fd90e9f79ad5fcae103487b (patch) | |
tree | 59845a0bb38830586cbe475ec82ec50d6c545618 /actionmailer/lib/action_mailer | |
parent | f4f76772fb5c25357a54baaa9cd20f7e9a1cd653 (diff) | |
download | rails-a9751a7034c5a2a49fd90e9f79ad5fcae103487b.tar.gz rails-a9751a7034c5a2a49fd90e9f79ad5fcae103487b.tar.bz2 rails-a9751a7034c5a2a49fd90e9f79ad5fcae103487b.zip |
Refactor ActionMailer layout and remove legacy one.
Diffstat (limited to 'actionmailer/lib/action_mailer')
6 files changed, 31 insertions, 36 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 898356075f..29afa2692a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -1,6 +1,4 @@ -require "active_support/core_ext/class" -# Use the old layouts until actionmailer gets refactored -require "action_controller/legacy/layout" +require 'active_support/core_ext/class' module ActionMailer #:nodoc: # Action Mailer allows you to send email from your application using a mailer model and views. @@ -254,11 +252,12 @@ module ActionMailer #:nodoc: # +implicit_parts_order+. class Base include AdvAttrAccessor, PartContainer, Quoting, Utils - extend AbstractController::RenderingController + + include AbstractController::RenderingController + include AbstractController::Layouts if Object.const_defined?(:ActionController) include ActionController::UrlWriter - include ActionController::Layout end private_class_method :new #:nodoc: @@ -569,8 +568,7 @@ module ActionMailer #:nodoc: end @template = initialize_template_class(body) - layout = _pick_layout(layout, true) unless - ActionController::Base.exempt_from_layout.include?(template.handler) + layout = _layout_for_option(:default, :formats => formats) @template._render_template(template, layout, {}) ensure @current_template_content_type = nil @@ -583,25 +581,23 @@ module ActionMailer #:nodoc: end def render(opts) + file = opts[:file] opts[:locals] ||= {} - layout, file = opts.delete(:layout), opts[:file] - - begin - @template = initialize_template_class(opts.delete(:body)) - - if file - prefix = mailer_name unless file =~ /\// - template = view_paths.find(file, {:formats => formats}, prefix) - end - layout = _pick_layout(layout, - !template || ActionController::Base.exempt_from_layout.include?(template.handler)) + @template = initialize_template_class(opts.delete(:body)) - if template - @template._render_template(template, layout, opts) - elsif inline = opts[:inline] - @template._render_inline(inline, layout, opts) - end + if file + prefix = mailer_name unless file =~ /\// + template = view_paths.find(file, {:formats => formats}, prefix) + end + + layout = opts.key?(:layout) ? opts.delete(:layout) : :default + layout = _layout_for_option(layout, :formats => formats) + + if template + @template._render_template(template, layout, opts) + elsif inline = opts[:inline] + @template._render_inline(inline, layout, opts) end end diff --git a/actionmailer/lib/action_mailer/delivery_method.rb b/actionmailer/lib/action_mailer/delivery_method.rb index ffba3c418c..29a51afdc3 100644 --- a/actionmailer/lib/action_mailer/delivery_method.rb +++ b/actionmailer/lib/action_mailer/delivery_method.rb @@ -2,10 +2,10 @@ require "active_support/core_ext/class" module ActionMailer module DeliveryMethod - autoload :File, 'action_mailer/delivery_method/file' + autoload :File, 'action_mailer/delivery_method/file' autoload :Sendmail, 'action_mailer/delivery_method/sendmail' - autoload :Smtp, 'action_mailer/delivery_method/smtp' - autoload :Test, 'action_mailer/delivery_method/test' + autoload :Smtp, 'action_mailer/delivery_method/smtp' + autoload :Test, 'action_mailer/delivery_method/test' # Creates a new DeliveryMethod object according to the given options. # @@ -27,18 +27,17 @@ module ActionMailer def self.lookup_method(delivery_method) case delivery_method when Symbol - method_name = delivery_method.to_s.camelize + method_name = delivery_method.to_s.camelize method_class = ActionMailer::DeliveryMethod.const_get(method_name) - method_class.new() - when nil + method_class.new + when nil # default Smtp.new else delivery_method end end - # An abstract delivery method class. There are multiple delivery method - # classes, documented under + # An abstract delivery method class. There are multiple delivery method classes. # See the classes under the ActionMailer::DeliveryMethod, e.g. # ActionMailer::DeliveryMethod::Smtp. # Smtp is the default delivery method for production @@ -47,8 +46,8 @@ module ActionMailer # each delivery method exposes just one method # # delivery_method = ActionMailer::DeliveryMethod::Smtp.new - # # delivery_method.perform_delivery(mail) # send the mail via smtp + # class Method superclass_delegating_accessor :settings self.settings = {} diff --git a/actionmailer/lib/action_mailer/delivery_method/file.rb b/actionmailer/lib/action_mailer/delivery_method/file.rb index 8807a05221..587ae37ffa 100644 --- a/actionmailer/lib/action_mailer/delivery_method/file.rb +++ b/actionmailer/lib/action_mailer/delivery_method/file.rb @@ -1,10 +1,10 @@ require 'tmpdir' + module ActionMailer module DeliveryMethod # A delivery method implementation which writes all mails to a file. class File < Method - self.settings = { :location => defined?(Rails) ? "#{Rails.root}/tmp/mails" : "#{Dir.tmpdir}/mails" } diff --git a/actionmailer/lib/action_mailer/delivery_method/sendmail.rb b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb index 34e03b8060..db55af79f1 100644 --- a/actionmailer/lib/action_mailer/delivery_method/sendmail.rb +++ b/actionmailer/lib/action_mailer/delivery_method/sendmail.rb @@ -3,7 +3,6 @@ module ActionMailer # A delivery method implementation which sends via sendmail. class Sendmail < Method - self.settings = { :location => '/usr/sbin/sendmail', :arguments => '-i -t' @@ -18,5 +17,6 @@ module ActionMailer end end end + end end diff --git a/actionmailer/lib/action_mailer/delivery_method/smtp.rb b/actionmailer/lib/action_mailer/delivery_method/smtp.rb index e39f97330c..86b0ae8329 100644 --- a/actionmailer/lib/action_mailer/delivery_method/smtp.rb +++ b/actionmailer/lib/action_mailer/delivery_method/smtp.rb @@ -1,6 +1,5 @@ module ActionMailer module DeliveryMethod - # A delivery method implementation which sends via smtp. class Smtp < Method @@ -27,5 +26,6 @@ module ActionMailer end end end + end end diff --git a/actionmailer/lib/action_mailer/delivery_method/test.rb b/actionmailer/lib/action_mailer/delivery_method/test.rb index e63e0abbb8..6e3239d52a 100644 --- a/actionmailer/lib/action_mailer/delivery_method/test.rb +++ b/actionmailer/lib/action_mailer/delivery_method/test.rb @@ -3,10 +3,10 @@ module ActionMailer # A delivery method implementation designed for testing, which just appends each record to the :deliveries array class Test < Method - def perform_delivery(mail) ActionMailer::Base.deliveries << mail end end + end end |