Skip to content

Commit 137882f

Browse files
committed
Merge pull request #94 from mfung/add-correct-mailer-generators
Mailer generator now creates mailer layouts and both html/text templates
2 parents 04a7501 + 7c08f6c commit 137882f

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

lib/generators/haml/mailer/mailer_generator.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,30 @@ module Generators
55
class MailerGenerator < ControllerGenerator
66
source_root File.expand_path("../templates", __FILE__)
77

8-
protected
8+
def copy_view_files
9+
view_base_path = File.join("app/views", class_path, file_name)
10+
empty_directory view_base_path
11+
12+
if self.behavior == :invoke
13+
formats.each do |format|
14+
layout_path = File.join("app/views/layouts", filename_with_extensions("mailer", format))
15+
template filename_with_extensions(:layout, format), layout_path
16+
end
17+
end
18+
19+
actions.each do |action|
20+
@action = action
921

10-
def format
11-
:text
22+
formats.each do |format|
23+
@path = File.join(view_base_path, filename_with_extensions(action, format))
24+
template filename_with_extensions(:view, format), @path
25+
end
26+
end
27+
end
28+
29+
protected
30+
def formats
31+
[:text, :html]
1232
end
1333

1434
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%hmtl
2+
%body
3+
= yield
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
= yield
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%h1= class_name + "#" + @action
2+
3+
%p
4+
= @greeting + ", find me in <%= @path %>"

test/lib/generators/haml/mailer_generator_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,33 @@ class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
1111

1212
test "should invoke template engine" do
1313
run_generator
14+
15+
assert_file "app/views/layouts/mailer.text.haml" do |view|
16+
assert_match /\= yield/, view
17+
end
18+
19+
assert_file "app/views/layouts/mailer.html.haml" do |view|
20+
assert_match /\= yield/, view
21+
end
22+
1423
assert_file "app/views/notifier/foo.text.haml" do |view|
1524
assert_match %r(app/views/notifier/foo\.text\.haml), view
1625
assert_match /\= @greeting/, view
1726
end
1827

28+
assert_file "app/views/notifier/foo.html.haml" do |view|
29+
assert_match %r(app/views/notifier/foo\.html\.haml), view
30+
assert_match /\= @greeting/, view
31+
end
32+
1933
assert_file "app/views/notifier/bar.text.haml" do |view|
2034
assert_match %r(app/views/notifier/bar\.text\.haml), view
2135
assert_match /\= @greeting/, view
2236
end
37+
38+
assert_file "app/views/notifier/bar.html.haml" do |view|
39+
assert_match %r(app/views/notifier/bar\.html\.haml), view
40+
assert_match /\= @greeting/, view
41+
end
2342
end
2443
end

0 commit comments

Comments
 (0)