2010-06-13 11:04:24 +00:00
|
|
|
module Devise
|
|
|
|
module Generators
|
2011-06-27 14:31:29 +00:00
|
|
|
# Include this module in your generator to generate Devise views.
|
|
|
|
# `copy_views` is the main method and by default copies all views
|
|
|
|
# with forms.
|
|
|
|
module ViewPathTemplates #:nodoc:
|
2011-06-27 14:20:32 +00:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
argument :scope, :required => false, :default => nil,
|
|
|
|
:desc => "The scope to copy views to"
|
2011-06-27 14:31:29 +00:00
|
|
|
|
|
|
|
public_task :copy_views
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_views
|
|
|
|
view_directory :confirmations
|
|
|
|
view_directory :passwords
|
|
|
|
view_directory :registrations
|
|
|
|
view_directory :sessions
|
|
|
|
view_directory :unlocks
|
2011-06-27 14:20:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def view_directory(name)
|
|
|
|
directory "devise/#{name}", "#{target_path}/#{name}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def target_path
|
|
|
|
@target_path ||= "app/views/#{scope || :devise}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-27 14:31:29 +00:00
|
|
|
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
2011-06-27 14:20:32 +00:00
|
|
|
include ViewPathTemplates
|
2011-06-27 14:31:29 +00:00
|
|
|
|
|
|
|
source_root File.expand_path("../../../../app/views", __FILE__)
|
2011-06-27 14:20:32 +00:00
|
|
|
desc "Copies shared Devise views to your application."
|
|
|
|
|
2011-06-27 14:31:29 +00:00
|
|
|
# Override copy_views to just copy mailer and shared.
|
2011-06-27 14:20:32 +00:00
|
|
|
def copy_views
|
|
|
|
view_directory :mailer
|
|
|
|
view_directory :shared
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-27 14:31:29 +00:00
|
|
|
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
2011-06-27 14:20:32 +00:00
|
|
|
include ViewPathTemplates
|
2011-06-27 14:31:29 +00:00
|
|
|
source_root File.expand_path("../../../../app/views", __FILE__)
|
2011-06-27 14:20:32 +00:00
|
|
|
desc "Copies default Devise views to your application."
|
2011-06-27 14:31:29 +00:00
|
|
|
end
|
2010-06-13 11:04:24 +00:00
|
|
|
|
2011-06-27 14:31:29 +00:00
|
|
|
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
|
|
|
include ViewPathTemplates
|
|
|
|
source_root File.expand_path("../templates", __FILE__)
|
|
|
|
desc "Copies simple form enabled views to your application."
|
|
|
|
end
|
|
|
|
|
|
|
|
class ViewsGenerator < Rails::Generators::Base
|
|
|
|
desc "Copies Devise views to your application."
|
|
|
|
|
|
|
|
argument :scope, :required => false, :default => nil,
|
|
|
|
: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"
|
2010-06-13 11:04:24 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-11 10:56:43 +00:00
|
|
|
end
|