Class: HappySeed::Generators::AdminGenerator

Inherits:
HappySeedGenerator show all
Defined in:
lib/generators/happy_seed/admin/admin_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fingerprintObject



11
12
13
# File 'lib/generators/happy_seed/admin/admin_generator.rb', line 11

def self.fingerprint
  gem_available? 'activeadmin'
end

Instance Method Details

#install_active_adminObject



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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/generators/happy_seed/admin/admin_generator.rb', line 15

def install_active_admin
  return if already_installed

  seperate_admin_user = yes? "Install seperate AdminUser (otherwise add role to User)?"

  if !seperate_admin_user
    require_generator RolesGenerator
  end

  require_generator CkeditorGenerator

  gem 'activeadmin', github: 'activeadmin'
  gem 'inherited_resources', github: 'activeadmin/inherited_resources'
  gem 'ransack',    github: 'activerecord-hackery/ransack'
  gem 'kaminari',   github: 'amatsuda/kaminari', branch: '0-17-stable'
  gem 'formtastic', github: 'justinfrench/formtastic'
  gem 'draper',     github: 'audionerd/draper', branch: 'rails5', ref: 'e816e0e587'

  # To fix a Draper deprecation error
  gem 'activemodel-serializers-xml', github: 'rails/activemodel-serializers-xml'

  gem 'dateslices'

  Bundler.with_clean_env do
    run "bundle install --without production"
  end

  if seperate_admin_user
    generate 'active_admin:install'
  else
    generate 'active_admin:install --skip-users'
  end

  remove_file "app/admin/dashboard.rb"
  remove_file "spec/factories/admin_users.rb"

  directory 'app'
  directory "docs"
  directory "spec"
  directory "vendor"

  insert_into_file "config/initializers/active_admin.rb", "  config.register_javascript '//www.google.com/jsapi'\n  config.register_javascript 'chartkick.js'\n  config.register_javascript 'ckeditor/init.js'", :after => "To load a javascript file:\n"

  if !seperate_admin_user
    gsub_file "config/initializers/active_admin.rb", /# config.authentication_method.*/, "config.authentication_method = :authenticate_user!"
    gsub_file "config/initializers/active_admin.rb", /# config.authorization_adapter = ActiveAdmin::CanCanAdapter/, "config.authorization_adapter = ActiveAdmin::CanCanAdapter"
    gsub_file "config/initializers/active_admin.rb", /# config.on_unauthorized_access = :access_denied/, "config.on_unauthorized_access = :access_denied"
    gsub_file "config/initializers/active_admin.rb", /# config.current_user_method.*/, "config.current_user_method = :current_user"
    gsub_file "config/initializers/active_admin.rb", /config.logout_link_path.*/, "config.logout_link_path = :destroy_user_session_path"
    gsub_file "config/initializers/active_admin.rb", /# config.logout_link_method.*/, "config.logout_link_method = :delete"
  end

  append_to_file "config/initializers/assets.rb", "\nRails.application.config.assets.precompile += %w( chartkick.js )\n"

  inject_into_file 'config/application.rb', after: "config.generators do |g|\n" do <<-'RUBY'
g.scaffold_controller "scaffold_controller"
RUBY
  end

  inject_into_file "config/environments/production.rb", "  config.assets.precompile += Ckeditor.assets\n  config.assets.precompile += ['ckeditor/*']\n", before: "end\n"
  append_to_file "app/assets/stylesheets/active_admin.scss", "\n.cke_chrome {\n  width: 79.5% !important;\n  overflow: hidden;\n}"

  route <<-'ROUTE'
namespace :admin do
    # get "/stats" => "stats#stats"
    devise_scope :admin_user do
get '/stats/:scope' => "stats#stats", as: :admin_stats
    end
  end
ROUTE


end