aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib')
-rw-r--r--actionmailer/lib/action_mailer.rb12
-rw-r--r--actionmailer/lib/action_mailer/base.rb45
-rw-r--r--actionmailer/lib/action_mailer/helpers.rb4
3 files changed, 46 insertions, 15 deletions
diff --git a/actionmailer/lib/action_mailer.rb b/actionmailer/lib/action_mailer.rb
index 2e324d4637..2a9210deb9 100644
--- a/actionmailer/lib/action_mailer.rb
+++ b/actionmailer/lib/action_mailer.rb
@@ -21,13 +21,13 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
-unless defined?(ActionController)
- begin
- $:.unshift "#{File.dirname(__FILE__)}/../../actionpack/lib"
+begin
+ require 'action_controller'
+rescue LoadError
+ actionpack_path = "#{File.dirname(__FILE__)}/../../actionpack/lib"
+ if File.directory?(actionpack_path)
+ $:.unshift actionpack_path
require 'action_controller'
- rescue LoadError
- require 'rubygems'
- gem 'actionpack', '>= 1.12.5'
end
end
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb
index 72c94529b5..96e514e0db 100644
--- a/actionmailer/lib/action_mailer/base.rb
+++ b/actionmailer/lib/action_mailer/base.rb
@@ -246,7 +246,10 @@ module ActionMailer #:nodoc:
# +implicit_parts_order+.
class Base
include AdvAttrAccessor, PartContainer
- include ActionController::UrlWriter if Object.const_defined?(:ActionController)
+ if Object.const_defined?(:ActionController)
+ include ActionController::UrlWriter
+ include ActionController::Layout
+ end
private_class_method :new #:nodoc:
@@ -362,6 +365,7 @@ module ActionMailer #:nodoc:
# The mail object instance referenced by this mailer.
attr_reader :mail
+ attr_reader :template_name, :default_template_name, :action_name
class << self
attr_writer :mailer_name
@@ -374,11 +378,16 @@ module ActionMailer #:nodoc:
alias_method :controller_name, :mailer_name
alias_method :controller_path, :mailer_name
- def method_missing(method_symbol, *parameters)#:nodoc:
- case method_symbol.id2name
- when /^create_([_a-z]\w*)/ then new($1, *parameters).mail
- when /^deliver_([_a-z]\w*)/ then new($1, *parameters).deliver!
- when "new" then nil
+ def respond_to?(method_symbol, include_private = false) #:nodoc:
+ matches_dynamic_method?(method_symbol) || super
+ end
+
+ def method_missing(method_symbol, *parameters) #:nodoc:
+ match = matches_dynamic_method?(method_symbol)
+ case match[1]
+ when 'create' then new(match[2], *parameters).mail
+ when 'deliver' then new(match[2], *parameters).deliver!
+ when 'new' then nil
else super
end
end
@@ -424,6 +433,12 @@ module ActionMailer #:nodoc:
def template_root=(root)
self.view_paths = ActionView::Base.process_view_paths(root)
end
+
+ private
+ def matches_dynamic_method?(method_name) #:nodoc:
+ method_name = method_name.to_s
+ /(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
+ end
end
# Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer
@@ -519,6 +534,7 @@ module ActionMailer #:nodoc:
@content_type ||= @@default_content_type.dup
@implicit_parts_order ||= @@default_implicit_parts_order.dup
@template ||= method_name
+ @default_template_name = @action_name = @template
@mailer_name ||= self.class.name.underscore
@parts ||= []
@headers ||= {}
@@ -535,7 +551,22 @@ module ActionMailer #:nodoc:
if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render))
opts[:file] = "#{mailer_name}/#{opts[:file]}"
end
- initialize_template_class(body).render(opts)
+
+ begin
+ old_template, @template = @template, initialize_template_class(body)
+ layout = respond_to?(:pick_layout, true) ? pick_layout(opts) : false
+ @template.render(opts.merge(:layout => layout))
+ ensure
+ @template = old_template
+ end
+ end
+
+ def default_template_format
+ :html
+ end
+
+ def candidate_for_layout?(options)
+ !@template.send(:_exempt_from_layout?, default_template_name)
end
def template_root
diff --git a/actionmailer/lib/action_mailer/helpers.rb b/actionmailer/lib/action_mailer/helpers.rb
index 9c5fcc6afb..5f6dcd77cd 100644
--- a/actionmailer/lib/action_mailer/helpers.rb
+++ b/actionmailer/lib/action_mailer/helpers.rb
@@ -72,7 +72,7 @@ module ActionMailer
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
def #{method}(*args, &block)
- controller.send!(%(#{method}), *args, &block)
+ controller.__send__(%(#{method}), *args, &block)
end
end_eval
end
@@ -92,7 +92,7 @@ module ActionMailer
inherited_without_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send! :include, master_helper_module
+ child.master_helper_module.__send__(:include, master_helper_module)
child.helper child.name.to_s.underscore
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.name.to_s.underscore}_helper")