mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
added mailviewsgenerator
now mail generator can copy markerb or erb mail template views
This commit is contained in:
parent
263e903046
commit
10451e9e38
8 changed files with 33 additions and 10 deletions
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue