mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Use template engine as option since it's the one used by rails.
This commit is contained in:
parent
e81d428d53
commit
185541b9e4
1 changed files with 12 additions and 12 deletions
|
@ -4,15 +4,15 @@ class DeviseViewsGenerator < Rails::Generators::Base
|
||||||
argument :scope, :required => false, :default => nil,
|
argument :scope, :required => false, :default => nil,
|
||||||
:desc => "The scope to copy views to"
|
:desc => "The scope to copy views to"
|
||||||
|
|
||||||
class_option :engine, :type => :string, :aliases => "-t", :default => "erb",
|
class_option :template_engine, :type => :string, :aliases => "-t", :default => "erb",
|
||||||
:desc => "Template engine for the views. Available options are 'erb' and 'haml'."
|
:desc => "Template engine for the views. Available options are 'erb' and 'haml'."
|
||||||
|
|
||||||
def self.source_root
|
def self.source_root
|
||||||
@_devise_source_root ||= File.expand_path("../../../../app/views", __FILE__)
|
@_devise_source_root ||= File.expand_path("../../../../app/views", __FILE__)
|
||||||
end
|
end
|
||||||
|
|
||||||
def copy_views
|
def copy_views
|
||||||
case options[:engine]
|
case options[:template_engine]
|
||||||
when "erb"
|
when "erb"
|
||||||
directory "devise", "app/views/devise/#{scope}"
|
directory "devise", "app/views/devise/#{scope}"
|
||||||
when "haml"
|
when "haml"
|
||||||
|
@ -43,23 +43,23 @@ class DeviseViewsGenerator < Rails::Generators::Base
|
||||||
def create_and_copy_haml_views
|
def create_and_copy_haml_views
|
||||||
require 'tmpdir'
|
require 'tmpdir'
|
||||||
|
|
||||||
devise_html_source_root = "#{DeviseViewsGenerator.source_root}/devise"
|
html_root = "#{self.class.source_root}/devise"
|
||||||
devise_haml_source_root = "#{Dir.tmpdir}/devise-haml"
|
haml_root = "#{Dir.tmpdir}/devise-haml"
|
||||||
|
|
||||||
# reset the temp folder so that no deprecated files (if any) will get copied across
|
# Reset the temp folder so that no deprecated files (if any) will get copied across
|
||||||
FileUtils.remove_dir devise_haml_source_root, true
|
FileUtils.rm_rf(haml_root, true)
|
||||||
|
|
||||||
Dir["#{devise_html_source_root}/**/*"].each do |path|
|
Dir["#{html_root}/**/*"].each do |path|
|
||||||
relative_path = path.sub(devise_html_source_root, "")
|
relative_path = path.sub(html_root, "")
|
||||||
source_path = (devise_haml_source_root + relative_path).sub(/erb$/, "haml")
|
source_path = (haml_root + relative_path).sub(/erb$/, "haml")
|
||||||
|
|
||||||
if File.directory?(path)
|
if File.directory?(path)
|
||||||
FileUtils.mkdir_p source_path
|
FileUtils.mkdir_p(source_path)
|
||||||
else
|
else
|
||||||
`html2haml -r #{path} #{source_path}`
|
`html2haml -r #{path} #{source_path}`
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
directory devise_haml_source_root, "app/views/devise/#{scope}"
|
directory haml_root, "app/views/devise/#{scope}"
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Add table
Reference in a new issue