Class: Bs5::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/bs5/install/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_bootstrapObject

rubocop:disable Metrics/MethodLength



7
8
9
10
11
12
13
14
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
# File 'lib/generators/bs5/install/install_generator.rb', line 7

def add_bootstrap # rubocop:disable Metrics/MethodLength
  run 'yarn add bootstrap@next @popperjs/core'

  create_file 'app/javascript/packs/styles.scss', <<~HEREDOC
    @import "~bootstrap/scss/bootstrap";
  HEREDOC

  copy_file 'bs5.js', 'app/javascript/bs5.js'

  append_file 'app/javascript/packs/application.js', <<~HEREDOC
    import * as bs5 from "bs5";

    document.addEventListener("turbolinks:load", function () {
      bs5.start();
    });
  HEREDOC

  inject_into_file 'app/views/layouts/application.html.erb', before: '</head>' do
    <<~HEREDOC
      <%= stylesheet_pack_tag 'styles', media: 'all', 'data-turbolinks-track': 'reload' %>
      <meta name="viewport" content="width=device-width, initial-scale=1">
    HEREDOC
  end

  inject_into_file 'app/controllers/application_controller.rb', after: "ActionController::Base\n" do
    <<~HEREDOC
      helper Bs5::Engine.helpers
    HEREDOC
  end

  inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do
    <<~HEREDOC
      mount Bs5::Engine => '/bs5'
    HEREDOC
  end

  gsub_file 'config/webpacker.yml', 'extract_css: false', 'extract_css: true'
end