Merge pull request #1326 from sbounmy/master

feature added : markerb generator for mails
This commit is contained in:
José Valim 2011-11-10 03:27:53 -08:00
commit 0fd5493220
5 changed files with 78 additions and 10 deletions

View File

@ -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,30 @@ module Devise
desc "Copies simple form enabled views to your application."
end
class ErbGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views/devise", __FILE__)
desc "Copies Devise mail erb views to your application."
def copy_views
view_directory :mailer
end
end
class MarkerbGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../templates", __FILE__)
desc "Copies Devise mail markerb views to your application."
def copy_views
view_directory :markerb, 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,10 +86,13 @@ module Devise
:desc => "The scope to copy views to"
invoke SharedViewsGenerator
hook_for :form_builder, :aliases => "-b",
:desc => "Form builder to be used",
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
:default => defined?(Markerb) ? :markerb : :erb,
:type => :boolean
end
end
end

View File

@ -0,0 +1,5 @@
Welcome <%= @resource.email %>!
You can confirm your account through the link below:
<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>

View File

@ -0,0 +1,8 @@
Hello <%= @resource.email %>!
Someone has requested a link to change your password, and you can do this through the link below.
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
If you didn't request this, please ignore this email.
Your password won't change until you access the link above and create a new one.

View File

@ -0,0 +1,7 @@
Hello <%= @resource.email %>!
Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
Click the link below to unlock your account:
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>

View File

@ -21,19 +21,41 @@ 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 simple form if defined" do
run_generator
assert_files nil, :template_engine => /simple_form_for/
assert_file "app/views/devise/confirmations/new.html.erb", :template_engine => /simple_form_for/
end
test "Assert views with markerb" do
run_generator %w(--markerb)
assert_files nil, :mail_template_engine => "markerb"
end
test "Assert views with markerb by if Markerb is defined" do
class Markerb ;; end
run_generator
pending "Doesn't work: defined?(Markerb) returns nil in Devise::Generators::ViewsGenerator"
# 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"