aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionmailer/lib')
-rw-r--r--actionmailer/lib/generators/mailer/USAGE15
-rw-r--r--actionmailer/lib/generators/mailer/templates/mailer.rb16
-rw-r--r--actionmailer/lib/generators/mailer_generator.rb18
3 files changed, 49 insertions, 0 deletions
diff --git a/actionmailer/lib/generators/mailer/USAGE b/actionmailer/lib/generators/mailer/USAGE
new file mode 100644
index 0000000000..a08d459739
--- /dev/null
+++ b/actionmailer/lib/generators/mailer/USAGE
@@ -0,0 +1,15 @@
+Description:
+ Stubs out a new mailer and its views. Pass the mailer name, either
+ CamelCased or under_scored, and an optional list of emails as arguments.
+
+ This generates a mailer class in app/mailers and invokes your template
+ engine and test framework generators.
+
+Example:
+ `rails generate mailer Notifications signup forgot_password invoice`
+
+ creates a Notifications mailer class, views, test, and fixtures:
+ Mailer: app/mailers/notifications.rb
+ Views: app/views/notifications/signup.erb [...]
+ Test: test/functional/notifications_test.rb
+ Fixtures: test/fixtures/notifications/signup [...]
diff --git a/actionmailer/lib/generators/mailer/templates/mailer.rb b/actionmailer/lib/generators/mailer/templates/mailer.rb
new file mode 100644
index 0000000000..7343eb28b3
--- /dev/null
+++ b/actionmailer/lib/generators/mailer/templates/mailer.rb
@@ -0,0 +1,16 @@
+class <%= class_name %> < ActionMailer::Base
+ default :from => "from@example.com"
+<% for action in actions -%>
+
+ # Subject can be set in your I18n file at config/locales/en.yml
+ # with the following lookup:
+ #
+ # en.actionmailer.<%= file_name %>.<%= action %>.subject
+ #
+ def <%= action %>
+ @greeting = "Hi"
+
+ mail :to => "to@example.org"
+ end
+<% end -%>
+end
diff --git a/actionmailer/lib/generators/mailer_generator.rb b/actionmailer/lib/generators/mailer_generator.rb
new file mode 100644
index 0000000000..d3048c3168
--- /dev/null
+++ b/actionmailer/lib/generators/mailer_generator.rb
@@ -0,0 +1,18 @@
+module Rails
+ module Generators
+ class MailerGenerator < NamedBase
+ argument :actions, :type => :array, :default => [], :banner => "method method"
+ check_class_collision
+
+ def self.source_root
+ File.expand_path("../mailer/templates", __FILE__)
+ end
+
+ def create_mailer_file
+ template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb")
+ end
+
+ hook_for :template_engine, :test_framework
+ end
+ end
+end