class AuthAssist::Generators::ViewsGenerator

Public Instance Methods

copy_views() click to toggle source
# File lib/generators/auth_assist/views/views_generator.rb, line 16
def copy_views
  case options[:template_engine]
  when "haml"
    verify_haml_existence
    verify_haml_version
    create_and_copy_haml_views
  else
    directory "auth_assist", "app/views/#{scope || 'devise'}"
  end
end

Protected Instance Methods

create_and_copy_haml_views() click to toggle source
# File lib/generators/auth_assist/views/views_generator.rb, line 45
def create_and_copy_haml_views
  require 'tmpdir'
  html_root = "#{self.class.source_root}/auth_assist"

  Dir.mktmpdir("auth_assist-haml.") do |haml_root|
    Dir["#{html_root}/**/*"].each do |path|
      relative_path = path.sub(html_root, "")
      source_path   = (haml_root + relative_path).sub(/erb$/, "haml")

      if File.directory?(path)
        FileUtils.mkdir_p(source_path)
      else
        %xhtml2haml -r #{path} #{source_path}`
      end
    end

    directory haml_root, "app/views/#{scope || 'devise'}"
  end
end
verify_haml_existence() click to toggle source
# File lib/generators/auth_assist/views/views_generator.rb, line 29
def verify_haml_existence
  begin
    require 'haml'
  rescue LoadError
    say "HAML is not installed, or it is not specified in your Gemfile."
    exit
  end
end
verify_haml_version() click to toggle source
# File lib/generators/auth_assist/views/views_generator.rb, line 38
def verify_haml_version
  unless Haml.version[:major] == 2 and Haml.version[:minor] >= 3 or Haml.version[:major] >= 3
    say "To generate HAML templates, you need to install HAML 2.3 or above."
    exit
  end
end

Public Class Methods

source_root() click to toggle source
# File lib/generators/auth_assist/views/views_generator.rb, line 12
def self.source_root
  @_devise_source_root ||= File.expand_path("../../../../app/views", __FILE__)
end