2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:01:31 -04:00
|
|
|
require "active_job/railtie"
|
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
|
|
|
|
2014-10-25 06:14:05 -04:00
|
|
|
if app.config.force_ssl
|
|
|
|
options.default_url_options ||= {}
|
2016-08-06 13:01:31 -04:00
|
|
|
options.default_url_options[:protocol] ||= "https"
|
2014-10-25 06:14:05 -04:00
|
|
|
end
|
|
|
|
|
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
|
2014-07-01 12:09:24 -04:00
|
|
|
options.show_previews = Rails.env.development? if options.show_previews.nil?
|
2016-01-07 00:27:07 -05:00
|
|
|
options.cache_store ||= Rails.cache
|
2010-08-23 12:31:29 -04:00
|
|
|
|
2014-07-01 12:09:24 -04:00
|
|
|
if options.show_previews
|
2016-10-28 23:05:58 -04:00
|
|
|
options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil
|
2014-01-04 13:42:34 -05:00
|
|
|
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
|
2014-06-19 18:26:29 -04:00
|
|
|
extend ::AbstractController::Railties::RoutesHelpers.with(app.routes, false)
|
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))
|
2014-06-15 08:13:34 -04:00
|
|
|
register_preview_interceptors(options.delete(:preview_interceptors))
|
2011-04-02 04:51:47 -04:00
|
|
|
register_observers(options.delete(:observers))
|
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
options.each { |k, v| send("#{k}=", v) }
|
2009-12-23 20:01:07 -05:00
|
|
|
end
|
2016-03-06 21:52:51 -05:00
|
|
|
|
|
|
|
ActiveSupport.on_load(:action_dispatch_integration_test) { include ActionMailer::TestCase::ClearTestDeliveries }
|
2009-12-23 20:01:07 -05:00
|
|
|
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
|
|
|
|
2017-06-24 10:57:36 -04:00
|
|
|
initializer "action_mailer.eager_load_actions" do
|
|
|
|
ActiveSupport.on_load(:after_initialize) do
|
|
|
|
ActionMailer::Base.descendants.each(&:action_methods) if config.eager_load
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-20 15:04:45 -05:00
|
|
|
config.after_initialize do |app|
|
|
|
|
options = app.config.action_mailer
|
|
|
|
|
|
|
|
if options.show_previews
|
|
|
|
app.routes.prepend do
|
2016-08-06 13:01:31 -04:00
|
|
|
get "/rails/mailers" => "rails/mailers#index", internal: true
|
|
|
|
get "/rails/mailers/*path" => "rails/mailers#preview", internal: true
|
2016-02-20 15:04:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if options.preview_path
|
|
|
|
ActiveSupport::Dependencies.autoload_paths << options.preview_path
|
|
|
|
end
|
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
|