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

Simple use hook_for.

This commit is contained in:
José Valim 2011-06-27 11:31:29 -03:00
parent 29a0af78bc
commit 0bf28b19ab

View file

@ -1,34 +1,24 @@
module Devise
module Generators
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"
class_option :form_builder, :type => :string, :aliases => "-b",
:desc => "Form builder to be used",
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
def copy_views
invoke SharedViewsGenerator
if options[:form_builder] == "form_for"
invoke DefaultViewsGenerator
else
invoke SimpleFormViewsGenerator
end
end
end
module ViewPathTemplates
# 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:
extend ActiveSupport::Concern
included do
source_root File.expand_path("../../../../app/views", __FILE__)
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
public_task :copy_views
end
def copy_views
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
end
protected
@ -42,27 +32,42 @@ module Devise
end
end
class SharedViewsGenerator < Rails::Generators::Base
class SharedViewsGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views", __FILE__)
desc "Copies shared Devise views to your application."
# Override copy_views to just copy mailer and shared.
def copy_views
view_directory :mailer
view_directory :shared
end
end
class DefaultViewsGenerator < Rails::Generators::Base
class FormForGenerator < Rails::Generators::Base #:nodoc:
include ViewPathTemplates
source_root File.expand_path("../../../../app/views", __FILE__)
desc "Copies default Devise views to your application."
end
def copy_views
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
end
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"
end
end
end