Class: Decidim::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Decidim::Generators::InstallGenerator
- Defined in:
- lib/decidim/generators/install_generator.rb
Overview
Installs ‘decidim` to a Rails app by adding the needed lines of code automatically to important files in the Rails app.
Remember that, for how generators work, actions are executed based on the definition order of the public methods.
Instance Method Summary collapse
- #add_seeds ⇒ Object
- #build_api_docs ⇒ Object
- #bundle_install ⇒ Object
- #copy_migrations ⇒ Object
- #install ⇒ Object
- #install_decidim_webpacker ⇒ Object
- #letter_opener_web ⇒ Object
- #profiling_gems ⇒ Object
- #remove_layout ⇒ Object
- #secrets ⇒ Object
- #skip_gemfile_if_defined ⇒ Object
- #smtp_environment ⇒ Object
- #tweak_spring ⇒ Object
Instance Method Details
#add_seeds ⇒ Object
41 42 43 44 45 46 |
# File 'lib/decidim/generators/install_generator.rb', line 41 def add_seeds append_file "db/seeds.rb", <<~RUBY # You can remove the 'faker' gem if you do not want Decidim seeds. Decidim.seed! RUBY end |
#build_api_docs ⇒ Object
113 114 115 |
# File 'lib/decidim/generators/install_generator.rb', line 113 def build_api_docs rails "decidim_api:generate_docs" end |
#bundle_install ⇒ Object
170 171 172 |
# File 'lib/decidim/generators/install_generator.rb', line 170 def bundle_install run "bundle install" end |
#copy_migrations ⇒ Object
174 175 176 177 |
# File 'lib/decidim/generators/install_generator.rb', line 174 def copy_migrations rails "decidim:choose_target_plugins", "railties:install:migrations" recreate_db if [:recreate_db] end |
#install ⇒ Object
37 38 39 |
# File 'lib/decidim/generators/install_generator.rb', line 37 def install route "mount Decidim::Core::Engine => '/'" end |
#install_decidim_webpacker ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/decidim/generators/install_generator.rb', line 82 def install_decidim_webpacker # Copy CSS file copy_file "decidim_application.scss", "app/packs/stylesheets/decidim/decidim_application.scss" # Copy JS application file copy_file "decidim_application.js", "app/packs/src/decidim/decidim_application.js" # Create empty directory for images empty_directory "app/packs/images" # Add a .keep file so directory is included in git when committing create_file "app/packs/images/.keep" # Regenerate webpacker binstubs remove_file "bin/yarn" bundle_install rails "shakapacker:binstubs" # Copy package.json copy_file "package.json", "package.json" # Run Decidim custom webpacker installation rails "decidim:webpacker:install" # Run Decidim custom procfile installation rails "decidim:procfile:install" # Replace robots.txt remove_file "public/robots.txt" rails "decidim:robots:replace" end |
#letter_opener_web ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/decidim/generators/install_generator.rb', line 117 def letter_opener_web route <<~RUBY if Rails.env.development? mount LetterOpenerWeb::Engine, at: "/letter_opener" end RUBY inject_into_file "config/environments/development.rb", after: "config.action_mailer.raise_delivery_errors = false" do cut <<~RUBY | | config.action_mailer.delivery_method = :letter_opener_web | config.action_mailer.default_url_options = { port: 3000 } RUBY end end |
#profiling_gems ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/decidim/generators/install_generator.rb', line 135 def profiling_gems return unless [:profiling] append_file "Gemfile", <<~RUBY group :development do # Profiling gems gem "bullet" gem "flamegraph" gem "memory_profiler" gem "rack-mini-profiler", require: false gem "stackprof" end RUBY copy_file "bullet_initializer.rb", "config/initializers/bullet.rb" copy_file "rack_profiler_initializer.rb", "config/initializers/rack_profiler.rb" end |
#remove_layout ⇒ Object
52 53 54 55 |
# File 'lib/decidim/generators/install_generator.rb', line 52 def remove_layout remove_file "app/views/layouts/application.html.erb" remove_file "app/views/layouts/mailer.text.erb" end |
#secrets ⇒ Object
48 49 50 |
# File 'lib/decidim/generators/install_generator.rb', line 48 def secrets template "secrets.yml.erb", "config/secrets.yml", force: true end |
#skip_gemfile_if_defined ⇒ Object
76 77 78 79 80 |
# File 'lib/decidim/generators/install_generator.rb', line 76 def skip_gemfile_if_defined return unless [:skip_gemfile] remove_file "Gemfile" end |
#smtp_environment ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/decidim/generators/install_generator.rb', line 57 def smtp_environment inject_into_file "config/environments/production.rb", after: "config.log_formatter = ::Logger::Formatter.new" do cut <<~RUBY | | config.action_mailer.smtp_settings = { | :address => Rails.application.secrets.smtp_address, | :port => Rails.application.secrets.smtp_port, | :authentication => Rails.application.secrets.smtp_authentication, | :user_name => Rails.application.secrets.smtp_username, | :password => Rails.application.secrets.smtp_password, | :domain => Rails.application.secrets.smtp_domain, | :enable_starttls_auto => Rails.application.secrets.smtp_starttls_auto, | :openssl_verify_mode => 'none' | } RUBY end end |
#tweak_spring ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/decidim/generators/install_generator.rb', line 154 def tweak_spring run "bundle exec spring stop" run "bundle exec spring binstub --all" create_file "config/spring.rb", <<~CONFIG require "decidim/spring" Spring.watch( ".ruby-version", ".rbenv-vars", "tmp/restart.txt", "tmp/caching-dev.txt" ) CONFIG end |