Class: Alchemy::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Alchemy::Generators::InstallGenerator
- Defined in:
- lib/generators/alchemy/install/install_generator.rb
Instance Method Summary collapse
- #add_npm_package ⇒ Object
- #copy_alchemy_entry_point ⇒ Object
- #copy_config ⇒ Object
- #copy_demo_views ⇒ Object
- #copy_dragonfly_config ⇒ Object
- #copy_yml_files ⇒ Object
- #finalize ⇒ Object
- #install_assets ⇒ Object
- #install_gutentag_migrations ⇒ Object
- #mount ⇒ Object
- #run_webpacker_installer ⇒ Object
- #set_primary_language ⇒ Object
- #setup ⇒ Object
- #setup_database ⇒ Object
Instance Method Details
#add_npm_package ⇒ Object
116 117 118 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 116 def add_npm_package run "yarn add @alchemy_cms/admin@~#{Alchemy.version}" end |
#copy_alchemy_entry_point ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 120 def copy_alchemy_entry_point webpack_config = YAML.safe_load( File.read(app_root.join("config", "webpacker.yml")), aliases: true )[Rails.env] copy_file "alchemy_admin.js", app_root.join(webpack_config["source_path"], webpack_config["source_entry_path"], "alchemy/admin.js") end |
#copy_config ⇒ Object
60 61 62 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 60 def copy_config copy_file "#{gem_config_path}/config.yml", app_config_path.join("alchemy", "config.yml") end |
#copy_demo_views ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 75 def copy_demo_views return if [:skip_demo_files] copy_file "application.html.erb", app_views_path.join("layouts", "application.html.erb") copy_file "article.scss", app_assets_path.join("stylesheets", "alchemy", "elements", "article.scss") stylesheet_require = " *= require_tree ./alchemy/elements\n" if File.exist?(app_assets_path.join("stylesheets", "application.css")) insert_into_file app_assets_path.join("stylesheets", "application.css"), stylesheet_require, before: " */" else create_file app_assets_path.join("stylesheets", "application.css"), "/*\n#{stylesheet_require} */\n" end copy_file "_article.html.erb", app_views_path.join("alchemy", "elements", "_article.html.erb") copy_file "_standard.html.erb", app_views_path.join("alchemy", "page_layouts", "_standard.html.erb") copy_file "alchemy.en.yml", app_config_path.join("locales", "alchemy.en.yml") end |
#copy_dragonfly_config ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 94 def copy_dragonfly_config template( "#{__dir__}/templates/dragonfly.rb.tt", app_config_path.join("initializers", "dragonfly.rb"), skip: [:auto_accept] ) end |
#copy_yml_files ⇒ Object
64 65 66 67 68 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 64 def copy_yml_files %w(elements page_layouts menus).each do |file| template "#{__dir__}/templates/#{file}.yml.tt", app_config_path.join("alchemy", "#{file}.yml") end end |
#finalize ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 147 def finalize header say "Alchemy successfully installed!" say "Now start the server with:\n\n" say " bin/rails server\n\n" say "and point your browser to\n\n" say " http://localhost:3000/admin\n\n" say "and follow the onscreen instructions to finalize the installation.\n\n" end |
#install_assets ⇒ Object
70 71 72 73 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 70 def install_assets copy_file "all.js", app_vendor_assets_path.join("javascripts", "alchemy", "admin", "all.js") copy_file "all.css", app_vendor_assets_path.join("stylesheets", "alchemy", "admin", "all.css") end |
#install_gutentag_migrations ⇒ Object
102 103 104 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 102 def install_gutentag_migrations rake "gutentag:install:migrations" end |
#mount ⇒ Object
54 55 56 57 58 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 54 def mount return if [:skip_mount] install_tasks.inject_routes([:auto_accept]) end |
#run_webpacker_installer ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 106 def run_webpacker_installer unless [:skip_webpacker_installer] # Webpacker does not create a package.json, but we need one unless File.exist? app_root.join("package.json") in_root { run "echo '{}' > package.json" } end rake("webpacker:install", abort_on_failure: true) end end |
#set_primary_language ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 129 def set_primary_language header install_tasks.set_primary_language( code: [:default_language_code], name: [:default_language_name], auto_accept: [:auto_accept] ) end |
#setup ⇒ Object
48 49 50 51 52 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 48 def setup header say "Welcome to AlchemyCMS!" say "Let's begin with some questions.\n\n" end |
#setup_database ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/generators/alchemy/install/install_generator.rb', line 138 def setup_database rake("db:create", abort_on_failure: true) unless [:skip_db_create] # We can't invoke this rake task, because Rails will use wrong engine names otherwise rake("alchemy:install:migrations", abort_on_failure: true) rake("db:migrate", abort_on_failure: true) install_tasks.inject_seeder rake("db:seed", abort_on_failure: true) end |