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

Refactor view generators.

This commit is contained in:
José Valim 2011-06-27 11:20:32 -03:00
parent cf487c771e
commit 29a0af78bc
2 changed files with 58 additions and 11 deletions

View file

@ -1,7 +1,7 @@
PATH
remote: .
specs:
devise (1.4.0.dev)
devise (1.4.0)
bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
@ -43,7 +43,6 @@ GEM
addressable (2.2.4)
arel (2.0.9)
bcrypt-ruby (2.1.4)
bcrypt-ruby (2.1.4-java)
bson (1.3.0)
bson_ext (1.3.0)
builder (2.1.2)
@ -131,8 +130,8 @@ GEM
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.27)
warden (1.0.3)
rack (>= 1.0.0)
warden (1.0.4)
rack (>= 1.0)
weakling (0.0.4-java)
webrat (0.7.2)
nokogiri (>= 1.2.0)

View file

@ -1,19 +1,67 @@
require 'tmpdir'
module Devise
module Generators
class ViewsGenerator < Rails::Generators::Base
source_root File.expand_path("../../../../app/views", __FILE__)
desc "Copies all Devise views to your application."
desc "Copies Devise views to your application."
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
# class_option :template_engine, :type => :string, :aliases => "-t",
# :desc => "Template engine for the views. Available options are 'erb', 'haml' and 'slim'."
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
directory "devise", "app/views/#{scope || :devise}"
invoke SharedViewsGenerator
if options[:form_builder] == "form_for"
invoke DefaultViewsGenerator
else
invoke SimpleFormViewsGenerator
end
end
end
module ViewPathTemplates
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"
end
protected
def view_directory(name)
directory "devise/#{name}", "#{target_path}/#{name}"
end
def target_path
@target_path ||= "app/views/#{scope || :devise}"
end
end
class SharedViewsGenerator < Rails::Generators::Base
include ViewPathTemplates
desc "Copies shared Devise views to your application."
def copy_views
view_directory :mailer
view_directory :shared
end
end
class DefaultViewsGenerator < Rails::Generators::Base
include ViewPathTemplates
desc "Copies default Devise views to your application."
def copy_views
view_directory :confirmations
view_directory :passwords
view_directory :registrations
view_directory :sessions
view_directory :unlocks
end
end
end