use autoload instead of explicit requires for ActionMailer
This commit is contained in:
parent
04d2d043ca
commit
e201fc750b
|
@ -31,22 +31,32 @@ rescue LoadError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require 'action_mailer/vendor'
|
module ActionMailer
|
||||||
require 'tmail'
|
def self.load_all!
|
||||||
|
[Base, Part, ::Text::Format, ::Net::SMTP]
|
||||||
|
end
|
||||||
|
|
||||||
require 'action_mailer/base'
|
autoload :AdvAttrAccessor, 'action_mailer/adv_attr_accessor'
|
||||||
require 'action_mailer/helpers'
|
autoload :Base, 'action_mailer/base'
|
||||||
require 'action_mailer/mail_helper'
|
autoload :Helpers, 'action_mailer/helpers'
|
||||||
require 'action_mailer/quoting'
|
autoload :Part, 'action_mailer/part'
|
||||||
require 'action_mailer/test_helper'
|
autoload :PartContainer, 'action_mailer/part_container'
|
||||||
|
autoload :Quoting, 'action_mailer/quoting'
|
||||||
require 'net/smtp'
|
autoload :TestCase, 'action_mailer/test_case'
|
||||||
|
autoload :TestHelper, 'action_mailer/test_helper'
|
||||||
ActionMailer::Base.class_eval do
|
autoload :Utils, 'action_mailer/utils'
|
||||||
include ActionMailer::Quoting
|
|
||||||
include ActionMailer::Helpers
|
|
||||||
|
|
||||||
helper MailHelper
|
|
||||||
end
|
end
|
||||||
|
|
||||||
silence_warnings { TMail::Encoder.const_set("MAX_LINE_LEN", 200) }
|
module Text
|
||||||
|
autoload :Format, 'action_mailer/vendor/text_format'
|
||||||
|
end
|
||||||
|
|
||||||
|
module Net
|
||||||
|
autoload :SMTP, 'net/smtp'
|
||||||
|
end
|
||||||
|
|
||||||
|
autoload :MailHelper, 'action_mailer/mail_helper'
|
||||||
|
autoload :TMail, 'action_mailer/vendor/tmail'
|
||||||
|
|
||||||
|
# TODO: Don't explicitly load entire lib
|
||||||
|
ActionMailer.load_all!
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
require 'action_mailer/adv_attr_accessor'
|
|
||||||
require 'action_mailer/part'
|
|
||||||
require 'action_mailer/part_container'
|
|
||||||
require 'action_mailer/utils'
|
|
||||||
require 'tmail/net'
|
require 'tmail/net'
|
||||||
|
|
||||||
module ActionMailer #:nodoc:
|
module ActionMailer #:nodoc:
|
||||||
|
@ -245,7 +241,7 @@ module ActionMailer #:nodoc:
|
||||||
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
|
# and appear last in the mime encoded message. You can also pick a different order from inside a method with
|
||||||
# +implicit_parts_order+.
|
# +implicit_parts_order+.
|
||||||
class Base
|
class Base
|
||||||
include AdvAttrAccessor, PartContainer
|
include AdvAttrAccessor, PartContainer, Quoting, Utils
|
||||||
if Object.const_defined?(:ActionController)
|
if Object.const_defined?(:ActionController)
|
||||||
include ActionController::UrlWriter
|
include ActionController::UrlWriter
|
||||||
include ActionController::Layout
|
include ActionController::Layout
|
||||||
|
@ -648,11 +644,11 @@ module ActionMailer #:nodoc:
|
||||||
|
|
||||||
if @parts.empty?
|
if @parts.empty?
|
||||||
m.set_content_type(real_content_type, nil, ctype_attrs)
|
m.set_content_type(real_content_type, nil, ctype_attrs)
|
||||||
m.body = Utils.normalize_new_lines(body)
|
m.body = normalize_new_lines(body)
|
||||||
else
|
else
|
||||||
if String === body
|
if String === body
|
||||||
part = TMail::Mail.new
|
part = TMail::Mail.new
|
||||||
part.body = Utils.normalize_new_lines(body)
|
part.body = normalize_new_lines(body)
|
||||||
part.set_content_type(real_content_type, nil, ctype_attrs)
|
part.set_content_type(real_content_type, nil, ctype_attrs)
|
||||||
part.set_content_disposition "inline"
|
part.set_content_disposition "inline"
|
||||||
m.parts << part
|
m.parts << part
|
||||||
|
@ -698,4 +694,9 @@ module ActionMailer #:nodoc:
|
||||||
deliveries << mail
|
deliveries << mail
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Base.class_eval do
|
||||||
|
include Helpers
|
||||||
|
helper MailHelper
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
require 'text/format'
|
|
||||||
|
|
||||||
module MailHelper
|
module MailHelper
|
||||||
# Uses Text::Format to take the text and format it, indented two spaces for
|
# Uses Text::Format to take the text and format it, indented two spaces for
|
||||||
# each line, and wrapped at 72 columns.
|
# each line, and wrapped at 72 columns.
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
require 'action_mailer/adv_attr_accessor'
|
|
||||||
require 'action_mailer/part_container'
|
|
||||||
require 'action_mailer/utils'
|
|
||||||
|
|
||||||
module ActionMailer
|
module ActionMailer
|
||||||
# Represents a subpart of an email message. It shares many similar
|
# Represents a subpart of an email message. It shares many similar
|
||||||
# attributes of ActionMailer::Base. Although you can create parts manually
|
# attributes of ActionMailer::Base. Although you can create parts manually
|
||||||
# and add them to the +parts+ list of the mailer, it is easier
|
# and add them to the +parts+ list of the mailer, it is easier
|
||||||
# to use the helper methods in ActionMailer::PartContainer.
|
# to use the helper methods in ActionMailer::PartContainer.
|
||||||
class Part
|
class Part
|
||||||
include ActionMailer::AdvAttrAccessor
|
include AdvAttrAccessor, PartContainer, Utils
|
||||||
include ActionMailer::PartContainer
|
|
||||||
|
|
||||||
# Represents the body of the part, as a string. This should not be a
|
# Represents the body of the part, as a string. This should not be a
|
||||||
# Hash (like ActionMailer::Base), but if you want a template to be rendered
|
# Hash (like ActionMailer::Base), but if you want a template to be rendered
|
||||||
|
@ -64,7 +59,7 @@ module ActionMailer
|
||||||
when "base64" then
|
when "base64" then
|
||||||
part.body = TMail::Base64.folding_encode(body)
|
part.body = TMail::Base64.folding_encode(body)
|
||||||
when "quoted-printable"
|
when "quoted-printable"
|
||||||
part.body = [Utils.normalize_new_lines(body)].pack("M*")
|
part.body = [normalize_new_lines(body)].pack("M*")
|
||||||
else
|
else
|
||||||
part.body = body
|
part.body = body
|
||||||
end
|
end
|
||||||
|
@ -102,7 +97,6 @@ module ActionMailer
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def squish(values={})
|
def squish(values={})
|
||||||
values.delete_if { |k,v| v.nil? }
|
values.delete_if { |k,v| v.nil? }
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ module ActionMailer
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestCase < ActiveSupport::TestCase
|
class TestCase < ActiveSupport::TestCase
|
||||||
include ActionMailer::Quoting
|
include Quoting, TestHelper
|
||||||
|
|
||||||
setup :initialize_test_deliveries
|
setup :initialize_test_deliveries
|
||||||
setup :set_expected_mail
|
setup :set_expected_mail
|
||||||
|
|
|
@ -58,6 +58,7 @@ module ActionMailer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: Deprecate this
|
||||||
module Test
|
module Test
|
||||||
module Unit
|
module Unit
|
||||||
class TestCase
|
class TestCase
|
||||||
|
|
|
@ -3,6 +3,5 @@ module ActionMailer
|
||||||
def normalize_new_lines(text)
|
def normalize_new_lines(text)
|
||||||
text.to_s.gsub(/\r\n?/, "\n")
|
text.to_s.gsub(/\r\n?/, "\n")
|
||||||
end
|
end
|
||||||
module_function :normalize_new_lines
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
# Prefer gems to the bundled libs.
|
|
||||||
require 'rubygems'
|
|
||||||
|
|
||||||
begin
|
|
||||||
gem 'tmail', '~> 1.2.3'
|
|
||||||
rescue Gem::LoadError
|
|
||||||
$:.unshift "#{File.dirname(__FILE__)}/vendor/tmail-1.2.3"
|
|
||||||
end
|
|
||||||
|
|
||||||
begin
|
|
||||||
gem 'text-format', '>= 0.6.3'
|
|
||||||
rescue Gem::LoadError
|
|
||||||
$:.unshift "#{File.dirname(__FILE__)}/vendor/text-format-0.6.3"
|
|
||||||
end
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Prefer gems to the bundled libs.
|
||||||
|
require 'rubygems'
|
||||||
|
|
||||||
|
begin
|
||||||
|
gem 'text-format', '>= 0.6.3'
|
||||||
|
rescue Gem::LoadError
|
||||||
|
$:.unshift "#{File.dirname(__FILE__)}/text-format-0.6.3"
|
||||||
|
end
|
||||||
|
|
||||||
|
require 'text/format'
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Prefer gems to the bundled libs.
|
||||||
|
require 'rubygems'
|
||||||
|
|
||||||
|
begin
|
||||||
|
gem 'tmail', '~> 1.2.3'
|
||||||
|
rescue Gem::LoadError
|
||||||
|
$:.unshift "#{File.dirname(__FILE__)}/tmail-1.2.3"
|
||||||
|
end
|
||||||
|
|
||||||
|
module TMail
|
||||||
|
end
|
||||||
|
|
||||||
|
require 'tmail'
|
||||||
|
|
||||||
|
silence_warnings do
|
||||||
|
TMail::Encoder.const_set("MAX_LINE_LEN", 200)
|
||||||
|
end
|
Loading…
Reference in New Issue