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

Added HAML as a template engine option to devise_views generator (-t or --engine). HAML files are created based on the erb files on the fly using 'html2haml' command that comes with HAML.

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Fred Wu 2010-03-14 01:17:12 +11:00 committed by José Valim
parent 3f0bae1968
commit 90e8253205

View file

@ -1,14 +1,43 @@
class DeviseViewsGenerator < Rails::Generators::Base
desc "Copies all Devise views to your application."
argument :scope, :required => false, :default => nil,
:desc => "The scope to copy views to"
class_option :engine, :type => :string, :aliases => "-t", :default => "erb",
:desc => "Template engine for the views. Available options are 'erb' and 'haml'."
def self.source_root
@_devise_source_root ||= File.expand_path("../../../../app/views", __FILE__)
end
def copy_views
directory "devise", "app/views/devise/#{scope}"
case options[:engine]
when "erb"
directory "devise", "app/views/devise/#{scope}"
when "haml"
require 'haml'
create_and_copy_haml_views
end
end
protected
def create_and_copy_haml_views
devise_html_source_root = "#{DeviseViewsGenerator.source_root}/devise"
devise_haml_source_root = "#{DeviseViewsGenerator.source_root}/devise-haml"
Dir["#{devise_html_source_root}/**/*"].each do |path|
relative_path = path.sub(devise_html_source_root, "")
source_path = (devise_haml_source_root + relative_path).sub(/erb$/, "haml")
if File.directory?(path)
FileUtils.mkdir_p source_path
else
`html2haml -r #{path} #{source_path}`
end
end
directory devise_haml_source_root, "app/views/devise/#{scope}"
end
end