Class: MaquinaNewsletters::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- MaquinaNewsletters::Generators::InstallGenerator
- Defined in:
- lib/generators/maquina_newsletters/install/install_generator.rb
Overview
Installs the MaquinaNewsletters engine into a host Rails app:
bin/rails generate maquina_newsletters:install
Mounts the engine, writes the configuration initializer, ensures the ActiveStorage + ActionText (Trix) dependencies the newsletter body relies on are set up, and copies the engine’s migrations into the host.
Instance Method Summary collapse
- #create_initializer ⇒ Object
- #install_action_text ⇒ Object
-
#install_active_storage ⇒ Object
The newsletter body is an ActionText rich-text field with image attachments, so the host needs ActiveStorage + ActionText (Trix).
- #install_migrations ⇒ Object
- #mount_engine ⇒ Object
- #show_post_install_message ⇒ Object
Instance Method Details
#create_initializer ⇒ Object
35 36 37 |
# File 'lib/generators/maquina_newsletters/install/install_generator.rb', line 35 def create_initializer template "initializer.rb", "config/initializers/maquina_newsletters.rb" end |
#install_action_text ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/generators/maquina_newsletters/install/install_generator.rb', line 50 def install_action_text if File.exist?(File.join(destination_root, "app/assets/stylesheets/actiontext.css")) say_status :skip, "ActionText already installed", :blue else rails_command "action_text:install", inline: true end end |
#install_active_storage ⇒ Object
The newsletter body is an ActionText rich-text field with image attachments, so the host needs ActiveStorage + ActionText (Trix). Run their installers if they don’t appear to be set up yet.
42 43 44 45 46 47 48 |
# File 'lib/generators/maquina_newsletters/install/install_generator.rb', line 42 def install_active_storage if migration_exists?("create_active_storage_tables") say_status :skip, "ActiveStorage already installed", :blue else rails_command "active_storage:install", inline: true end end |
#install_migrations ⇒ Object
58 59 60 |
# File 'lib/generators/maquina_newsletters/install/install_generator.rb', line 58 def install_migrations rails_command "maquina_newsletters:install:migrations", inline: true end |
#mount_engine ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/generators/maquina_newsletters/install/install_generator.rb', line 22 def mount_engine route_line = %(mount MaquinaNewsletters::Engine => "#{[:mount_path]}") routes_file = "config/routes.rb" if File.exist?(File.join(destination_root, routes_file)) && File.read(File.join(destination_root, routes_file)).include?("MaquinaNewsletters::Engine") say_status :skip, "engine already mounted", :blue return end route route_line end |
#show_post_install_message ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/maquina_newsletters/install/install_generator.rb', line 62 def say "" say "=" * 64 say " MaquinaNewsletters installed.", :green say "=" * 64 say "" say "Next steps:" say "" say "1. Review config/initializers/maquina_newsletters.rb — set" say " recipient_model/scope/email_attr and base_controller_class." say "" say "2. Authentication is the HOST's job. Point base_controller_class at" say " your authenticated base controller (e.g. \"BackstageController\")," say " or enable the engine's optional HTTP Basic Auth fallback." say "" say "3. Apply the migrations:" say " bin/rails db:migrate" say "" say "Mounted at: #{[:mount_path]}" say "" end |