2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-06-25 06:57:58 -04:00
|
|
|
module Rails
|
|
|
|
module Generators
|
|
|
|
class MailerGenerator < NamedBase
|
2017-05-15 10:17:28 -04:00
|
|
|
source_root File.expand_path("templates", __dir__)
|
2010-04-30 06:42:12 -04:00
|
|
|
|
2012-10-07 13:54:14 -04:00
|
|
|
argument :actions, type: :array, default: [], banner: "method method"
|
2014-12-17 13:18:22 -05:00
|
|
|
|
|
|
|
check_class_collision suffix: "Mailer"
|
2009-06-25 06:57:58 -04:00
|
|
|
|
|
|
|
def create_mailer_file
|
2016-08-06 13:01:31 -04:00
|
|
|
template "mailer.rb", File.join("app/mailers", class_path, "#{file_name}_mailer.rb")
|
2016-03-11 19:43:37 -05:00
|
|
|
|
2016-03-11 19:59:06 -05:00
|
|
|
in_root do
|
2017-01-05 03:20:57 -05:00
|
|
|
if behavior == :invoke && !File.exist?(application_mailer_file_name)
|
2016-08-06 13:01:31 -04:00
|
|
|
template "application_mailer.rb", application_mailer_file_name
|
2016-03-11 19:59:06 -05:00
|
|
|
end
|
2016-03-11 19:43:37 -05:00
|
|
|
end
|
2009-06-25 06:57:58 -04:00
|
|
|
end
|
|
|
|
|
2009-06-27 08:27:26 -04:00
|
|
|
hook_for :template_engine, :test_framework
|
2014-12-17 13:18:22 -05:00
|
|
|
|
2016-12-22 04:57:02 -05:00
|
|
|
private
|
|
|
|
def file_name # :doc:
|
2018-04-22 01:30:07 -04:00
|
|
|
@_file_name ||= super.sub(/_mailer\z/i, "")
|
2014-12-17 13:18:22 -05:00
|
|
|
end
|
2016-03-11 22:31:06 -05:00
|
|
|
|
|
|
|
def application_mailer_file_name
|
|
|
|
@_application_mailer_file_name ||= if mountable_engine?
|
2017-01-03 21:51:18 -05:00
|
|
|
"app/mailers/#{namespaced_path}/application_mailer.rb"
|
2016-08-08 12:17:28 -04:00
|
|
|
else
|
|
|
|
"app/mailers/application_mailer.rb"
|
|
|
|
end
|
2016-03-11 22:31:06 -05:00
|
|
|
end
|
2009-06-25 06:57:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|