Sha256: 18bedaa636f11d4a9f468bf0a70e6ee3f15de1370e33bf89031f861c512ff6b8

Contents?: true

Size: 1.8 KB

Versions: 4

Compression:

Stored size: 1.8 KB

Contents

module Activoate
  class InstallGenerator < Rails::Generators::Base
    desc "Installs the activo layout"
    source_root File.expand_path('../templates', __FILE__)
    
    argument :layout_name, :type => :string, :default => 'activo'
    
    class_option :app_name,     :type => :string,   :default => 'Web App',                            :desc => 'Specify the application name'
    class_option :engine,       :type => :string,   :default => Activoate::Engine.config.engine,      :desc => 'Specify the template engine'
    class_option :formtastic,   :type => :string,   :default => Activoate::Engine.config.formtastic,  :desc => 'Specify the template engine'
    class_option :layout_type,  :type => :string,   :default => 'admin',                              :desc => 'Layout type, admin or sign'
    
    def copy_layout
      return if options.no_layout      
      admin_layout_name = options.layout_type == 'sign' ? "layout_sign.html.erb" : "layout_admin.html.erb"
      case options.engine
      when 'erb'
        template  admin_layout_name, "app/views/layouts/#{layout_name.underscore}.html.erb"
      when 'haml'
        generate_haml_layout(admin_layout_name)        
      end                  
    end
    
  protected
  
    def generate_haml_layout(admin_layout_name)
      require 'haml'
      Dir.mktmpdir('activoate-haml') do |haml_root|
        tmp_html_path = "#{haml_root}/#{admin_layout_name}"
        tmp_haml_path = "#{haml_root}/#{admin_layout_name}.haml"
        template admin_layout_name, tmp_html_path, :verbose => false
        `html2haml --erb --xhtml #{tmp_html_path} #{tmp_haml_path}`
        copy_file tmp_haml_path, "app/views/layouts/#{layout_name.underscore}.html.haml"
      end
    rescue LoadError
      say "HAML is not installed, or it is not specified in your Gemfile."
      exit
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activoate-0.8.1 lib/generators/activoate/install/install_generator.rb
activoate-0.7.9 lib/generators/activoate/install/install_generator.rb
activoate-0.7.5 lib/generators/activoate/install/install_generator.rb
activoate-0.7.2 lib/generators/activoate/install/install_generator.rb