2009-12-23 20:01:07 -05:00
|
|
|
require "action_mailer"
|
2009-12-31 15:28:48 -05:00
|
|
|
require "rails"
|
2010-08-02 11:38:44 -04:00
|
|
|
require "abstract_controller/railties/routes_helpers"
|
2009-12-23 20:01:07 -05:00
|
|
|
|
|
|
|
module ActionMailer
|
2012-09-17 20:18:56 -04:00
|
|
|
class Railtie < Rails::Railtie # :nodoc:
|
2010-03-26 13:47:55 -04:00
|
|
|
config.action_mailer = ActiveSupport::OrderedOptions.new
|
2012-08-01 14:54:22 -04:00
|
|
|
config.eager_load_namespaces << ActionMailer
|
2009-12-23 20:01:07 -05:00
|
|
|
|
2010-01-24 19:06:12 -05:00
|
|
|
initializer "action_mailer.logger" do
|
2010-03-29 20:08:08 -04:00
|
|
|
ActiveSupport.on_load(:action_mailer) { self.logger ||= Rails.logger }
|
2010-01-24 19:06:12 -05:00
|
|
|
end
|
|
|
|
|
2009-12-23 20:01:07 -05:00
|
|
|
initializer "action_mailer.set_configs" do |app|
|
2010-08-23 12:31:29 -04:00
|
|
|
paths = app.config.paths
|
2010-07-23 18:48:12 -04:00
|
|
|
options = app.config.action_mailer
|
2010-06-02 17:49:02 -04:00
|
|
|
|
2010-10-06 11:18:59 -04:00
|
|
|
options.assets_dir ||= paths["public"].first
|
|
|
|
options.javascripts_dir ||= paths["public/javascripts"].first
|
|
|
|
options.stylesheets_dir ||= paths["public/stylesheets"].first
|
2010-08-23 12:31:29 -04:00
|
|
|
|
2014-01-04 13:42:34 -05:00
|
|
|
if Rails.env.development?
|
|
|
|
options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
|
|
|
|
end
|
|
|
|
|
2010-09-27 14:42:02 -04:00
|
|
|
# make sure readers methods get compiled
|
2011-12-12 10:52:56 -05:00
|
|
|
options.asset_host ||= app.config.asset_host
|
|
|
|
options.relative_url_root ||= app.config.relative_url_root
|
2010-09-27 14:42:02 -04:00
|
|
|
|
2010-03-29 20:08:08 -04:00
|
|
|
ActiveSupport.on_load(:action_mailer) do
|
2010-08-04 11:15:34 -04:00
|
|
|
include AbstractController::UrlFor
|
2010-08-06 10:34:48 -04:00
|
|
|
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes)
|
2010-09-06 14:47:25 -04:00
|
|
|
include app.routes.mounted_helpers
|
2011-04-02 04:51:47 -04:00
|
|
|
|
|
|
|
register_interceptors(options.delete(:interceptors))
|
|
|
|
register_observers(options.delete(:observers))
|
|
|
|
|
2010-07-23 18:48:12 -04:00
|
|
|
options.each { |k,v| send("#{k}=", v) }
|
2009-12-23 20:01:07 -05:00
|
|
|
end
|
|
|
|
end
|
2010-09-27 14:42:02 -04:00
|
|
|
|
|
|
|
initializer "action_mailer.compile_config_methods" do
|
|
|
|
ActiveSupport.on_load(:action_mailer) do
|
|
|
|
config.compile_methods! if config.respond_to?(:compile_methods!)
|
|
|
|
end
|
|
|
|
end
|
2013-12-16 00:52:58 -05:00
|
|
|
|
2014-01-04 13:42:34 -05:00
|
|
|
config.after_initialize do
|
2014-01-26 06:50:36 -05:00
|
|
|
if ActionMailer::Base.preview_path
|
2014-01-04 13:42:34 -05:00
|
|
|
ActiveSupport::Dependencies.autoload_paths << ActionMailer::Base.preview_path
|
2013-12-16 00:52:58 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-23 20:01:07 -05:00
|
|
|
end
|
2010-07-30 02:04:16 -04:00
|
|
|
end
|