2010-06-13 07:04:24 -04:00
|
|
|
module Devise
|
|
|
|
module Generators
|
2011-06-27 10:31:29 -04: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 10:20:32 -04:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
argument :scope, :required => false, :default => nil,
|
|
|
|
:desc => "The scope to copy views to"
|
2011-06-27 10:31:29 -04: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 10:20:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def view_directory(name)
|
2011-06-27 10:50:28 -04:00
|
|
|
directory name.to_s, "#{target_path}/#{name}"
|
2011-06-27 10:20:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def target_path
|
|
|
|
@target_path ||= "app/views/#{scope || :devise}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-27 10:31:29 -04:00
|
|
|
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
|
2011-06-27 10:20:32 -04:00
|
|
|
include ViewPathTemplates
|
2011-06-27 10:50:28 -04:00
|
|
|
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
2011-06-27 10:20:32 -04:00
|
|
|
desc "Copies shared Devise views to your application."
|
|
|
|
|
2011-06-27 10:31:29 -04:00
|
|
|
# Override copy_views to just copy mailer and shared.
|
2011-06-27 10:20:32 -04:00
|
|
|
def copy_views
|
|
|
|
view_directory :mailer
|
|
|
|
view_directory :shared
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-27 10:31:29 -04:00
|
|
|
class FormForGenerator < Rails::Generators::Base #:nodoc:
|
2011-06-27 10:20:32 -04:00
|
|
|
include ViewPathTemplates
|
2011-06-27 10:50:28 -04:00
|
|
|
source_root File.expand_path("../../../../app/views/devise", __FILE__)
|
2011-06-27 10:20:32 -04:00
|
|
|
desc "Copies default Devise views to your application."
|
2011-06-27 10:31:29 -04:00
|
|
|
end
|
2010-06-13 07:04:24 -04:00
|
|
|
|
2011-06-27 10:31:29 -04:00
|
|
|
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
|
|
|
|
include ViewPathTemplates
|
2011-06-30 14:09:54 -04:00
|
|
|
source_root File.expand_path("../../templates/simple_form_for", __FILE__)
|
2011-06-27 10:31:29 -04:00
|
|
|
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 07:04:24 -04:00
|
|
|
end
|
|
|
|
end
|
2011-01-11 05:56:43 -05:00
|
|
|
end
|