1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge pull request #2916 from kayline/master

Add ability to generate only specified view directories
This commit is contained in:
Lucas Mazza 2014-03-09 20:49:27 -03:00
commit ccfe389be1
2 changed files with 47 additions and 7 deletions

View file

@ -16,6 +16,7 @@ module Devise
# It should be fixed in future Rails releases
class_option :form_builder, aliases: "-b"
class_option :markerb
class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)"
public_task :copy_views
end
@ -28,11 +29,17 @@ module Devise
end
def copy_views
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
if options[:views]
options[:views].each do |directory|
view_directory directory.to_sym
end
else
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
end
end
protected
@ -85,7 +92,9 @@ module Devise
hide!
def copy_views
view_directory :mailer
if !options[:views] || options[:views].include?('mailer')
view_directory :mailer
end
end
end
@ -96,7 +105,9 @@ module Devise
hide!
def copy_views
view_directory :markerb, target_path
if !options[:views] || options[:views].include?('mailer')
view_directory :markerb, target_path
end
end
def target_path

View file

@ -36,6 +36,35 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
assert_files nil, mail_template_engine: "markerb"
end
test "Assert only views within specified directories" do
run_generator %w(-v sessions registrations)
assert_file "app/views/devise/sessions/new.html.erb"
assert_file "app/views/devise/registrations/new.html.erb"
assert_file "app/views/devise/registrations/edit.html.erb"
assert_no_file "app/views/devise/confirmations/new.html.erb"
assert_no_file "app/views/devise/mailer/confirmation_instructions.html.erb"
end
test "Assert specified directories with scope" do
run_generator %w(users -v sessions)
assert_file "app/views/users/sessions/new.html.erb"
assert_no_file "app/views/users/confirmations/new.html.erb"
end
test "Assert specified directories with simple form" do
run_generator %w(-v registrations -b simple_form_for)
assert_file "app/views/devise/registrations/new.html.erb", /simple_form_for/
assert_no_file "app/views/devise/confirmations/new.html.erb"
end
test "Assert specified directories with markerb" do
run_generator %w(--markerb -v passwords mailer)
assert_file "app/views/devise/passwords/new.html.erb"
assert_no_file "app/views/devise/confirmations/new.html.erb"
assert_file "app/views/devise/mailer/reset_password_instructions.markerb"
end
def assert_files(scope = nil, options={})
scope = "devise" if scope.nil?
mail_template_engine = options[:mail_template_engine] || "html.erb"