HTML
end
# Add navbar partial
create_file 'app/views/shared/_navbar.html.erb', <<-HTML
HTML
# Use after_bundle block to run code after Rails has generated the application
after_bundle do
# Importmap pins
append_to_file 'config/importmap.rb', <<-RUBY.strip_heredoc
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@5.1.3/dist/js/bootstrap.esm.js"
pin "@popperjs/core", to: "https://unpkg.com/@popperjs/core@2.11.2/dist/esm/index.js" # use unpkg.com as ga.jspm.io contains a broken popper package
RUBY
# Append Bootstrap import statements to app/javascript/application.js
append_to_file 'app/javascript/application.js', <<-JS.strip_heredoc
// Bootstrap
import '@popperjs/core';
import * as bootstrap from 'bootstrap';
JS
end
# Application stylesheet
remove_file 'app/assets/stylesheets/application.css'
create_file 'app/assets/stylesheets/application.scss' do <<-SCSS
@import 'bootstrap';
SCSS
end
# Full title helper
inject_into_file 'app/helpers/application_helper.rb', after: "module ApplicationHelper\n" do
<<-RUBY
def full_title(page_title = '')
base_title = 'My App'
if page_title.empty?
base_title
else
page_title + ' | ' + base_title
end
end
RUBY
end
# Config variables
inject_into_file 'config/application.rb', after: "class Application < Rails::Application\n" do
<<-RUBY
config.generators do |generate|
generate.helper false
generate.assets false
generate.view_specs false
generate.helper_specs false
generate.routing_specs false
generate.controller_specs false
generate.system_tests false
end
RUBY
end
# Dotenv
create_file '.env' do <<-FILE
SECRET_KEY_BASE=placeholder
FILE
end
# Add root route
route "root to: 'pages#index'"
# Add routes
route "get 'about', to: 'pages#about'"
# Pages controller
create_file 'app/controllers/pages_controller.rb' do
<<-RUBY
class PagesController < ApplicationController
def index
end
def about
end
end
RUBY
end
# Index view
create_file 'app/views/pages/index.html.erb' do
<<-HTML.strip_heredoc
<%= content_for :title, 'Home' %>
Hello world
This is the home page.
HTML
end
# About view
create_file 'app/views/pages/about.html.erb' do
<<-HTML.strip_heredoc
<%= content_for :title, 'About' %>