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

73 lines
2.2 KiB
Ruby
Raw Normal View History

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
2011-06-27 10:31:29 -04:00
class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
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"
end
end
end