1
0
Fork 0
mirror of https://github.com/haml/haml-rails.git synced 2022-11-09 12:34:15 -05:00

Remove duplicate mailer suffixes

This commit is contained in:
Zeb Burke-Conte 2020-09-15 12:42:31 -07:00
parent fc6d0ace6e
commit 01cadeec6e
2 changed files with 24 additions and 33 deletions

View file

@ -1,42 +1,14 @@
require 'generators/haml/controller/controller_generator'
require 'rails/generators/erb/mailer/mailer_generator'
module Haml
module Generators
class MailerGenerator < ControllerGenerator
class MailerGenerator < Erb::Generators::MailerGenerator
source_root File.expand_path("../templates", __FILE__)
def copy_view_files
if ::Rails.version.to_s >= "4.2.0"
view_base_path = File.join("app/views", class_path, file_name + "_mailer")
empty_directory view_base_path
protected
if behavior == :invoke
formats.each do |format|
layout_path = File.join("app/views/layouts", class_path, filename_with_extensions("mailer", format))
template filename_with_extensions(:layout, format), layout_path unless File.exist?(layout_path)
end
end
actions.each do |action|
@action = action
formats.each do |format|
@path = File.join(view_base_path, filename_with_extensions(action, format))
template filename_with_extensions(:view, format), @path
end
end
else
super
end
end
protected
def format
:text
end
def formats
[:text, :html]
def handler
:haml
end
end
end

View file

@ -65,4 +65,23 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
end
end
end
test 'suffix is not duplicated' do
if ::Rails.version.to_s >= '4.2'
run_generator ['notifier_mailer', 'foo', 'bar', '--template-engine', 'haml']
assert_no_file 'app/views/notifier_mailer_mailer/'
assert_file 'app/views/notifier_mailer/'
assert_no_file 'app/views/notifier_mailer_mailer/foo.text.haml'
assert_file 'app/views/notifier_mailer/foo.text.haml'
assert_no_file 'app/views/notifier_mailer_mailer/foo.html.haml'
assert_file 'app/views/notifier_mailer/foo.html.haml'
assert_no_file 'app/views/notifier_mailer_mailer/bar.text.haml'
assert_file 'app/views/notifier_mailer/bar.text.haml'
assert_no_file 'app/views/notifier_mailer_mailer/bar.html.haml'
assert_file 'app/views/notifier_mailer/bar.html.haml'
end
end
end