From 10451e9e3854e4962c55f5beb5282221e7c8f668 Mon Sep 17 00:00:00 2001 From: Bounmy Stephane Date: Tue, 13 Sep 2011 00:19:48 -0700 Subject: [PATCH] added mailviewsgenerator now mail generator can copy markerb or erb mail template views --- .../confirmation_instructions.html.erb | 0 .../reset_password_instructions.html.erb | 0 .../{ => erb}/unlock_instructions.html.erb | 0 .../markerb/confirmation_instructions.markerb | 0 .../reset_password_instructions.markerb | 0 .../markerb/unlock_instructions.markerb | 0 lib/generators/devise/views_generator.rb | 22 +++++++++++++++---- test/generators/views_generator_test.rb | 21 +++++++++++++----- 8 files changed, 33 insertions(+), 10 deletions(-) rename app/views/devise/mailer/{ => erb}/confirmation_instructions.html.erb (100%) rename app/views/devise/mailer/{ => erb}/reset_password_instructions.html.erb (100%) rename app/views/devise/mailer/{ => erb}/unlock_instructions.html.erb (100%) create mode 100644 app/views/devise/mailer/markerb/confirmation_instructions.markerb create mode 100644 app/views/devise/mailer/markerb/reset_password_instructions.markerb create mode 100644 app/views/devise/mailer/markerb/unlock_instructions.markerb diff --git a/app/views/devise/mailer/confirmation_instructions.html.erb b/app/views/devise/mailer/erb/confirmation_instructions.html.erb similarity index 100% rename from app/views/devise/mailer/confirmation_instructions.html.erb rename to app/views/devise/mailer/erb/confirmation_instructions.html.erb diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/erb/reset_password_instructions.html.erb similarity index 100% rename from app/views/devise/mailer/reset_password_instructions.html.erb rename to app/views/devise/mailer/erb/reset_password_instructions.html.erb diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/erb/unlock_instructions.html.erb similarity index 100% rename from app/views/devise/mailer/unlock_instructions.html.erb rename to app/views/devise/mailer/erb/unlock_instructions.html.erb diff --git a/app/views/devise/mailer/markerb/confirmation_instructions.markerb b/app/views/devise/mailer/markerb/confirmation_instructions.markerb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/devise/mailer/markerb/reset_password_instructions.markerb b/app/views/devise/mailer/markerb/reset_password_instructions.markerb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/devise/mailer/markerb/unlock_instructions.markerb b/app/views/devise/mailer/markerb/unlock_instructions.markerb new file mode 100644 index 00000000..e69de29b diff --git a/lib/generators/devise/views_generator.rb b/lib/generators/devise/views_generator.rb index 59ab5fde..b0be2f78 100644 --- a/lib/generators/devise/views_generator.rb +++ b/lib/generators/devise/views_generator.rb @@ -23,8 +23,8 @@ module Devise protected - def view_directory(name) - directory name.to_s, "#{target_path}/#{name}" + def view_directory(name, _target_path = nil) + directory name.to_s, _target_path || "#{target_path}/#{name}" end def target_path @@ -39,7 +39,6 @@ module Devise # Override copy_views to just copy mailer and shared. def copy_views - view_directory :mailer view_directory :shared end end @@ -56,6 +55,21 @@ module Devise desc "Copies simple form enabled views to your application." end + class MailViewsGenerator < Rails::Generators::Base #:nodoc: + include ViewPathTemplates + source_root File.expand_path("../../../../app/views/devise/mailer", __FILE__) + desc "Copies Devise mail views to your application." + class_option :mail_template_engine, :default => :erb, :aliases => "-m" + + def copy_views + view_directory options[:mail_template_engine], target_path + end + + def target_path + "app/views/#{scope || :devise}/mailer" + end + end + class ViewsGenerator < Rails::Generators::Base desc "Copies Devise views to your application." @@ -63,7 +77,7 @@ module Devise :desc => "The scope to copy views to" invoke SharedViewsGenerator - + invoke MailViewsGenerator hook_for :form_builder, :aliases => "-b", :desc => "Form builder to be used", :default => defined?(SimpleForm) ? "simple_form_for" : "form_for" diff --git a/test/generators/views_generator_test.rb b/test/generators/views_generator_test.rb index b7974e59..f74a5d77 100644 --- a/test/generators/views_generator_test.rb +++ b/test/generators/views_generator_test.rb @@ -21,19 +21,28 @@ class ViewsGeneratorTest < Rails::Generators::TestCase test "Assert views with simple form" do run_generator %w(-b simple_form_for) assert_files - assert_file "app/views/devise/confirmations/new.html.erb", /simple_form_for/ + assert_file "app/views/devise/confirmations/new.html.erb", :template_engine => /simple_form_for/ run_generator %w(users -b simple_form_for) assert_files "users" - assert_file "app/views/users/confirmations/new.html.erb", /simple_form_for/ + assert_file "app/views/users/confirmations/new.html.erb", :template_engine => /simple_form_for/ end - def assert_files(scope = nil, template_engine = nil) + test "Assert views with markerb" do + run_generator %w(-m markerb) + assert_files nil, :mail_template_engine => "markerb" + end + + def assert_files(scope = nil, options={}) scope = "devise" if scope.nil? + default_template = "html.erb" + template_engine = options[:template_engine] || default_template + mail_template_engine = options[:mail_template_engine] || default_template + assert_file "app/views/#{scope}/confirmations/new.html.erb" - assert_file "app/views/#{scope}/mailer/confirmation_instructions.html.erb" - assert_file "app/views/#{scope}/mailer/reset_password_instructions.html.erb" - assert_file "app/views/#{scope}/mailer/unlock_instructions.html.erb" + assert_file "app/views/#{scope}/mailer/confirmation_instructions.#{mail_template_engine}" + assert_file "app/views/#{scope}/mailer/reset_password_instructions.#{mail_template_engine}" + assert_file "app/views/#{scope}/mailer/unlock_instructions.#{mail_template_engine}" assert_file "app/views/#{scope}/passwords/edit.html.erb" assert_file "app/views/#{scope}/passwords/new.html.erb" assert_file "app/views/#{scope}/registrations/new.html.erb"