Skip to content

Commit

Permalink
Added mailer generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kristensen authored and indirect committed Sep 7, 2010
1 parent ffc8f98 commit b463d08
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/generators/haml/mailer/mailer_generator.rb
@@ -0,0 +1,12 @@
require 'generators/haml/controller/controller_generator'

module Haml
module Generators
class MailerGenerator < ControllerGenerator
protected
def format
:text
end
end
end
end
3 changes: 3 additions & 0 deletions lib/generators/haml/mailer/templates/view.text.haml
@@ -0,0 +1,3 @@
<%= class_name %>#<%= @action %>

= @greeting + ", find me in <%= @path %>"
24 changes: 24 additions & 0 deletions test/lib/generators/haml/mailer_generator_test.rb
@@ -0,0 +1,24 @@
require 'test_helper'
require 'lib/generators/haml/testing_helper'

class Haml::Generators::MailerGeneratorTest < Rails::Generators::TestCase
destination File.join(Rails.root)
tests Rails::Generators::MailerGenerator
arguments %w(notifier foo bar --template-engine haml)

setup :prepare_destination
setup :copy_routes

test "should invoke template engine" do
run_generator
assert_file "app/views/notifier/foo.text.haml" do |view|
assert_match %r(app/views/notifier/foo\.text\.haml), view
assert_match /\= @greeting/, view
end

assert_file "app/views/notifier/bar.text.haml" do |view|
assert_match %r(app/views/notifier/bar\.text\.haml), view
assert_match /\= @greeting/, view
end
end
end
2 changes: 1 addition & 1 deletion test/lib/generators/haml/testing_helper.rb
@@ -1 +1 @@
require_generators :haml => ['scaffold', 'controller']
require_generators :haml => ['scaffold', 'controller', 'mailer']
11 changes: 7 additions & 4 deletions test/test_helper.rb
@@ -1,5 +1,4 @@
require 'rubygems'
gem 'test-unit'
require 'test/unit'
require 'rails/all'
require 'rails/generators'
Expand Down Expand Up @@ -46,8 +45,8 @@ def assert_class(klass, content)

def generator_list
{
:rails => ['scaffold', 'controller'],
:haml => ['scaffold', 'controller']
:rails => ['scaffold', 'controller', 'mailer'],
:haml => ['scaffold', 'controller', 'mailer']
}
end

Expand All @@ -63,7 +62,11 @@ def path_prefix(name)
def require_generators(generator_list)
generator_list.each do |name, generators|
generators.each do |generator_name|
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
if name.to_s == 'rails' && generator_name.to_s == 'mailer'
require File.join(path_prefix(name), generator_name.to_s, "#{generator_name}_generator")
else
require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
end
end
end
end
Expand Down

0 comments on commit b463d08

Please sign in to comment.