# frozen_string_literal: true def yarn(lib) run("yarn add #{lib}") end run("yarn install") generate(:controller, 'bootstrap', 'index') yarn 'jquery' yarn 'popper.js' yarn 'bootstrap' inject_into_file 'config/webpack/environment.js', after: "const { environment } = require('@rails/webpacker')\n" do <<~EOF const webpack = require('webpack') environment.plugins.append('Provide', new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery', Popper: ['popper.js', 'default'] })) EOF end inject_into_file 'app/javascript/packs/application.js', after: "require(\"channels\")\n" do <<~EOF import 'bootstrap/dist/js/bootstrap' import 'bootstrap/dist/css/bootstrap' EOF end inject_into_file 'app/views/bootstrap/index.html.erb', after: "<p>Find me in app/views/bootstrap/index.html.erb</p>\n" do <<~EOF <div class="spinner-border text-primary" role="status"> <span class="sr-only">Loading...</span> </div> EOF end say "all done. start your server and navigate to http://localhost:3000/bootstrap/index to test that it's working"