Class: AdminLte2Generator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/admin_lte2/admin_lte2_generator.rb

Instance Method Summary collapse

Instance Method Details

#mainObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/admin_lte2/admin_lte2_generator.rb', line 5

def main
  stylesheet_extension = options[:stylesheet_engine] || 'css'

  inject_into_file "app/assets/stylesheets/application.#{stylesheet_extension}", "@import \"AdminLTE/skins/skin-blue\";\n", after: ' */'
  inject_into_file "app/assets/stylesheets/application.#{stylesheet_extension}", "@import \"AdminLTE/AdminLTE\";\n", after: ' */'
  inject_into_file "app/assets/stylesheets/application.#{stylesheet_extension}", "@import \"bootstrap\";\n", after: ' */'
  inject_into_file "app/assets/stylesheets/application.#{stylesheet_extension}", "\[email protected] \"bootstrap-sprockets\";\n", after: ' */'

  inject_into_file "app/assets/javascripts/application.js", "//= require bootstrap-sprockets\n", after: "//= require jquery\n"
  inject_into_application_javascript('app', before: '//= require_tree')

  copy_file '_admin_lte_2_header.html.erb', 'app/views/layouts/_admin_lte_2_header.html.erb'
  copy_file '_admin_lte_2_sidebar.html.erb', 'app/views/layouts/_admin_lte_2_sidebar.html.erb'
  copy_file 'admin_lte_2.html.erb', 'app/views/layouts/admin_lte_2.html.erb'

  if yes?('Add layout to ApplicationController ? (y/n) ')
    inject_into_file 'app/controllers/application_controller.rb', "\n  layout 'admin_lte_2'\n", after: 'class ApplicationController < ActionController::Base'
  end

  if yes?('Login Page ? (y/n)')
    copy_file 'admin_lte_2_login.html.erb', 'app/views/layouts/admin_lte_2_login.html.erb'
  end

  if yes?('Devise ? (y/n) ')
    gem 'devise'

    run 'bundle install'
    generate 'devise:install'

    inject_into_file 'app/controllers/application_controller.rb', "\n  before_action :authenticate_user!\n", after: 'class ApplicationController < ActionController::Base'

    environment "
    config.to_prepare do
      Devise::SessionsController.layout 'admin_lte_2_login'
    end
    "
  end
end