From 7b98d2aa59e301c91d764262bba55133fef3538a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Apr 2010 12:11:38 +0200 Subject: Reorganize the mailer generator a bit. --- actionmailer/lib/rails/generators/mailer/USAGE | 15 +++++++++++++++ .../lib/rails/generators/mailer/mailer_generator.rb | 18 ++++++++++++++++++ .../lib/rails/generators/mailer/templates/mailer.rb | 16 ++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 actionmailer/lib/rails/generators/mailer/USAGE create mode 100644 actionmailer/lib/rails/generators/mailer/mailer_generator.rb create mode 100644 actionmailer/lib/rails/generators/mailer/templates/mailer.rb (limited to 'actionmailer/lib/rails') diff --git a/actionmailer/lib/rails/generators/mailer/USAGE b/actionmailer/lib/rails/generators/mailer/USAGE new file mode 100644 index 0000000000..a08d459739 --- /dev/null +++ b/actionmailer/lib/rails/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/rails/generators/mailer/mailer_generator.rb b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb new file mode 100644 index 0000000000..8f47539f42 --- /dev/null +++ b/actionmailer/lib/rails/generators/mailer/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("../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 diff --git a/actionmailer/lib/rails/generators/mailer/templates/mailer.rb b/actionmailer/lib/rails/generators/mailer/templates/mailer.rb new file mode 100644 index 0000000000..7343eb28b3 --- /dev/null +++ b/actionmailer/lib/rails/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 -- cgit v1.2.3 From cde168edbbe2d95dd8af40524dd9f42220481ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 30 Apr 2010 12:42:12 +0200 Subject: Update generators to use thor 0.13.6 with simpler source_root handling. --- actionmailer/lib/rails/generators/mailer/mailer_generator.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'actionmailer/lib/rails') diff --git a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb index 8f47539f42..dd7fa640c9 100644 --- a/actionmailer/lib/rails/generators/mailer/mailer_generator.rb +++ b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb @@ -1,13 +1,11 @@ module Rails module Generators class MailerGenerator < NamedBase + source_root File.expand_path("../templates", __FILE__) + argument :actions, :type => :array, :default => [], :banner => "method method" check_class_collision - def self.source_root - File.expand_path("../templates", __FILE__) - end - def create_mailer_file template "mailer.rb", File.join('app/mailers', class_path, "#{file_name}.rb") end -- cgit v1.2.3