forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Decouple from ActionController and ActionMailer * Bring back localization support. * Prepare to decouple templates from the filesystem. * Prepare to decouple localization from ActionView * Fix ActionMailer to take advantage of ActionView::Path
- Loading branch information
Showing
26 changed files
with
165 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,48 +465,48 @@ def initialize(method_name=nil, *parameters) #:nodoc: | |
def create!(method_name, *parameters) #:nodoc: | ||
initialize_defaults(method_name) | ||
__send__(method_name, *parameters) | ||
|
||
# If an explicit, textual body has not been set, we check assumptions. | ||
unless String === @body | ||
# First, we look to see if there are any likely templates that match, | ||
# which include the content-type in their file name (i.e., | ||
# "the_template_file.text.html.erb", etc.). Only do this if parts | ||
# have not already been specified manually. | ||
if @parts.empty? | ||
Dir.glob("#{template_path}/#{@template}.*").each do |path| | ||
template = template_root.find_by_parts("#{mailer_name}/#{File.basename(path)}") | ||
|
||
# Skip unless template has a multipart format | ||
next unless template && template.multipart? | ||
|
||
# if @parts.empty? | ||
template_root.find_all_by_parts(@template, {}, template_path).each do |template| | ||
@parts << Part.new( | ||
:content_type => template.content_type, | ||
:content_type => Mime::Type.lookup_by_extension(template.content_type || "text").to_s, | ||
:disposition => "inline", | ||
:charset => charset, | ||
:body => render_template(template, @body) | ||
) | ||
end | ||
unless @parts.empty? | ||
|
||
if @parts.size > 1 | ||
@content_type = "multipart/alternative" if @content_type !~ /^multipart/ | ||
@parts = sort_parts(@parts, @implicit_parts_order) | ||
end | ||
end | ||
|
||
# end | ||
# Then, if there were such templates, we check to see if we ought to | ||
# also render a "normal" template (without the content type). If a | ||
# normal template exists (or if there were no implicit parts) we render | ||
# it. | ||
template_exists = @parts.empty? | ||
template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}") | ||
@body = render_message(@template, @body) if template_exists | ||
# ==== | ||
# TODO: Revisit this | ||
# template_exists = @parts.empty? | ||
# template_exists ||= template_root.find_by_parts("#{mailer_name}/#{@template}") | ||
# @body = render_message(@template, @body) if template_exists | ||
|
||
# Finally, if there are other message parts and a textual body exists, | ||
# we shift it onto the front of the parts and set the body to nil (so | ||
# that create_mail doesn't try to render it in addition to the parts). | ||
if !@parts.empty? && String === @body | ||
@parts.unshift Part.new(:charset => charset, :body => @body) | ||
@body = nil | ||
end | ||
# ==== | ||
# TODO: Revisit this | ||
# if [email protected]? && String === @body | ||
# @parts.unshift Part.new(:charset => charset, :body => @body) | ||
# @body = nil | ||
# end | ||
end | ||
|
||
# If this is a multipart e-mail add the mime_version if it is not | ||
|
@@ -580,7 +580,7 @@ def render(opts) | |
|
||
if file | ||
prefix = mailer_name unless file =~ /\// | ||
template = view_paths.find_by_parts(file, formats, prefix) | ||
template = view_paths.find_by_parts(file, {:formats => formats}, prefix) | ||
end | ||
|
||
layout = _pick_layout(layout, | ||
|
@@ -611,7 +611,7 @@ def template_root=(root) | |
end | ||
|
||
def template_path | ||
"#{template_root}/#{mailer_name}" | ||
"#{mailer_name}" | ||
end | ||
|
||
def initialize_template_class(assigns) | ||
|
@@ -622,7 +622,7 @@ def initialize_template_class(assigns) | |
|
||
def sort_parts(parts, order = []) | ||
order = order.collect { |s| s.downcase } | ||
|
||
parts = parts.sort do |a, b| | ||
a_ct = a.content_type.downcase | ||
b_ct = b.content_type.downcase | ||
|
@@ -663,10 +663,13 @@ def create_mail | |
headers.each { |k, v| m[k] = v } | ||
|
||
real_content_type, ctype_attrs = parse_content_type | ||
|
||
if @parts.empty? | ||
m.set_content_type(real_content_type, nil, ctype_attrs) | ||
m.body = normalize_new_lines(body) | ||
elsif @parts.size == 1 && @parts.first.parts.empty? | ||
m.set_content_type(real_content_type, nil, ctype_attrs) | ||
m.body = normalize_new_lines(@parts.first.body) | ||
else | ||
if String === body | ||
part = TMail::Mail.new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,7 @@ def test_nested_parts | |
|
||
def test_nested_parts_with_body | ||
created = nil | ||
TestMailer.create_nested_multipart_with_body(@recipient) | ||
assert_nothing_raised { created = TestMailer.create_nested_multipart_with_body(@recipient)} | ||
assert_equal 1,created.parts.size | ||
assert_equal 2,created.parts.first.parts.size | ||
|
@@ -351,8 +352,8 @@ def test_nested_parts_with_body | |
|
||
def test_attachment_with_custom_header | ||
created = nil | ||
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient)} | ||
assert_equal "<[email protected]>", created.parts[1].header['content-id'].to_s | ||
assert_nothing_raised { created = TestMailer.create_attachment_with_custom_header(@recipient) } | ||
assert created.parts.any? { |p| p.header['content-id'].to_s == "<[email protected]>" } | ||
end | ||
|
||
def test_signed_up | ||
|
@@ -824,7 +825,7 @@ def test_implicitly_multipart_messages | |
assert_equal 3, mail.parts.length | ||
assert_equal "1.0", mail.mime_version | ||
assert_equal "multipart/alternative", mail.content_type | ||
assert_equal "text/yaml", mail.parts[0].content_type | ||
assert_equal "application/x-yaml", mail.parts[0].content_type | ||
assert_equal "utf-8", mail.parts[0].sub_header("content-type", "charset") | ||
assert_equal "text/plain", mail.parts[1].content_type | ||
assert_equal "utf-8", mail.parts[1].sub_header("content-type", "charset") | ||
|
@@ -835,11 +836,11 @@ def test_implicitly_multipart_messages | |
def test_implicitly_multipart_messages_with_custom_order | ||
assert ActionView::Template.template_handler_extensions.include?("bak"), "bak extension was not registered" | ||
|
||
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"]) | ||
mail = TestMailer.create_implicitly_multipart_example(@recipient, nil, ["application/x-yaml", "text/plain"]) | ||
assert_equal 3, mail.parts.length | ||
assert_equal "text/html", mail.parts[0].content_type | ||
assert_equal "text/plain", mail.parts[1].content_type | ||
assert_equal "text/yaml", mail.parts[2].content_type | ||
assert_equal "application/x-yaml", mail.parts[2].content_type | ||
end | ||
|
||
def test_implicitly_multipart_messages_with_charset | ||
|
@@ -938,8 +939,7 @@ def test_deliver_with_mail_object | |
def test_multipart_with_template_path_with_dots | ||
mail = FunkyPathMailer.create_multipart_with_template_path_with_dots(@recipient) | ||
assert_equal 2, mail.parts.length | ||
assert_equal 'text/plain', mail.parts[0].content_type | ||
assert_equal 'utf-8', mail.parts[0].charset | ||
assert mail.parts.any? {|part| part.content_type == "text/plain" && part.charset == "utf-8"} | ||
end | ||
|
||
def test_custom_content_type_attributes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.