diff options
Diffstat (limited to 'actionmailer/lib')
4 files changed, 48 insertions, 2 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index d827ccdf2b..e566132f4e 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -291,8 +291,6 @@ module ActionMailer #:nodoc: :parts_order => [ "text/plain", "text/enriched", "text/html" ] }.freeze - ActiveSupport.run_load_hooks(:action_mailer, self) - class << self def mailer_name @@ -643,5 +641,6 @@ module ActionMailer #:nodoc: container.add_part(part) end + ActiveSupport.run_load_hooks(:action_mailer, self) end end 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..dd7fa640c9 --- /dev/null +++ b/actionmailer/lib/rails/generators/mailer/mailer_generator.rb @@ -0,0 +1,16 @@ +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 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 |