Class: Chaltron::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Chaltron::InstallGenerator
- Defined in:
- lib/generators/chaltron/install_generator.rb
Overview
Install a skeleton application
Instance Method Summary collapse
- #add_gem_dependencies ⇒ Object
- #add_javascript ⇒ Object
- #add_stylesheets ⇒ Object
- #apply_layout ⇒ Object
- #create_index_controller ⇒ Object
- #db_migrations ⇒ Object
- #db_seed ⇒ Object
- #disclaimer ⇒ Object
- #gem_priority ⇒ Object
- #setup_authorization ⇒ Object
- #setup_chaltron ⇒ Object
- #setup_navigation ⇒ Object
Instance Method Details
#add_gem_dependencies ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/chaltron/install_generator.rb', line 18 def add_gem_dependencies gem 'devise' gem 'omniauth' gem 'omniauth-rails_csrf_protection' gem 'gitlab_omniauth-ldap' gem 'cancancan' gem 'bootstrap', '~> 4.6' gem 'autoprefixer-rails' gem 'font-awesome-sass' gem 'jquery-rails' gem 'jquery-datatables' gem 'ajax-datatables-rails' gem 'bootstrap_form' gem 'nprogress-rails' gem 'simple-navigation' gem 'rails-i18n' end |
#add_javascript ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/generators/chaltron/install_generator.rb', line 75 def add_javascript dependencies =<<EOF //= require jquery //= require popper //= require bootstrap //= require datatables/jquery.dataTables //= require datatables/dataTables.bootstrap4 //= require datatables/extensions/Responsive/dataTables.responsive //= require datatables/extensions/Responsive/responsive.bootstrap4 //= require nprogress //= require nprogress-turbolinks //= require nprogress-ajax //= require chaltron EOF inject_into_file 'app/assets/javascripts/application.js', dependencies, before: '//= require_tree .' javascript =<<JS document.addEventListener('DOMContentLoaded', function(event) { Chaltron.locale = $('body').data('locale'); }); NProgress.configure({ showSpinner: false, }); JS inject_into_file 'app/assets/javascripts/application.js', javascript, after: '//= require_tree .' end |
#add_stylesheets ⇒ Object
107 108 109 110 |
# File 'lib/generators/chaltron/install_generator.rb', line 107 def add_stylesheets copy_file 'app/assets/stylesheets/chaltron_custom.scss' copy_file 'app/assets/stylesheets/datatables.scss' end |
#apply_layout ⇒ Object
68 69 70 71 72 73 |
# File 'lib/generators/chaltron/install_generator.rb', line 68 def apply_layout # html remove_file 'app/views/layouts/application.html.erb' directory 'app/views/layouts' directory 'app/assets/images' end |
#create_index_controller ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/generators/chaltron/install_generator.rb', line 112 def create_index_controller generate 'controller home index' route "root to: 'home#index'" # controller, views and assets replacement copy_file 'app/controllers/home_controller.rb', force: true directory 'app/views/home/', force: true copy_file 'app/assets/javascripts/home.coffee', force: true copy_file 'app/assets/stylesheets/home.scss', force: true Array(1..10).each do |x| route "get 'home/test#{x}'" end end |
#db_migrations ⇒ Object
49 50 51 |
# File 'lib/generators/chaltron/install_generator.rb', line 49 def db_migrations rake 'chaltron_engine:install:migrations' end |
#db_seed ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/generators/chaltron/install_generator.rb', line 53 def db_seed append_file 'db/seeds.rb' do <<RUBY User.create do |u| u.username = 'bella' u.fullname = 'Bellatrix Lestrange' u.email = '[email protected]' u.password = 'password.1' u.password_confirmation = 'password.1' u.roles = Chaltron.roles end RUBY end end |
#disclaimer ⇒ Object
11 12 13 14 15 16 |
# File 'lib/generators/chaltron/install_generator.rb', line 11 def disclaimer if .interactive? exit unless yes?('Are you sure you want to continue? [yes/NO]') end end |
#gem_priority ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/chaltron/install_generator.rb', line 39 def gem_priority # chaltron gem must be loaded after devise to setup the correct view paths chaltron = File.readlines('Gemfile') .select { |l| l.match('chaltron') } .first gsub_file 'Gemfile', chaltron, '' append_file 'Gemfile', "\n#{chaltron}" end |
#setup_authorization ⇒ Object
135 136 137 |
# File 'lib/generators/chaltron/install_generator.rb', line 135 def copy_file 'app/models/ability.rb' end |
#setup_chaltron ⇒ Object
131 132 133 |
# File 'lib/generators/chaltron/install_generator.rb', line 131 def setup_chaltron copy_file 'config/initializers/chaltron.rb' end |
#setup_navigation ⇒ Object
127 128 129 |
# File 'lib/generators/chaltron/install_generator.rb', line 127 def copy_file 'config/navigation.rb' end |