Start a new Perron-powered site

rails new my-new-site --minimal -T -O -m https://perron.railsdesigner.com/library/new/template.rb

This snippet configures a Rails application to use with Perron. It removes database dependencies, cleans up unnecessary files and adds the Perron gem. With this template you have the quickest way to start a new static site with Perron.

Template source

gsub_file "Gemfile", /gem "sqlite3".*$/, ""
gsub_file "Gemfile", /gem "activerecord".*$/, ""

remove_file "config/database.yml"
remove_file "config/credentials.yml.enc"
remove_file "config/master.key"

remove_file "public/400.html"
remove_file "public/406-unsupported-browser.html"
remove_file "public/422.html"
remove_file "public/500.html"

run "rm -r app/views/pwa"

remove_file "app/controllers/application_controller.rb"
create_file "app/controllers/application_controller.rb", <<~RB
class ApplicationController < ActionController::Base
end
RB

remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.erb", <<~ERB
<!DOCTYPE html>
<html>
  <head>
    <%= meta_tags %>
    <meta name="viewport" content="width=device-width,initial-scale=1">

    <%= yield :head %>

    <link rel="icon" href="/icon.png" type="image/png">
    <link rel="icon" href="/icon.svg" type="image/svg+xml">
    <link rel="apple-touch-icon" href="/icon.png">

    <%= stylesheet_link_tag :app %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>
ERB

append_to_file ".gitignore", "/output/\n"

gem "perron"

after_bundle do
  rails_command("generate perron:install")

  markdown_gem = ask("Which markdown parser would you like to use? (commonmarker/kramdown/redcarpet or leave blank to skip):")

  unless markdown_gem.blank?
    case markdown_gem.strip.downcase
    when "commonmarker"
      uncomment_lines "Gemfile", /gem "commonmarker"/

      Bundler.with_unbundled_env { run "bundle install" }
    when "kramdown"
      uncomment_lines "Gemfile", /gem "kramdown"/

      Bundler.with_unbundled_env { run "bundle install" }
    when "redcarpet"
      uncomment_lines "Gemfile", /gem "redcarpet"/

      Bundler.with_unbundled_env { run "bundle install" }
    else
      say "Invalid markdown parser option. Skipping…", :yellow
    end
  end
end

remove_file "README.md"
create_file "README.md", <<~MARKDOWN
  # My New Site

  TBD


  ## Development

  ```
  bin/dev
  ```


  ## Deploy/publish

  ```
  RAILS_ENV=production rails perron:build
  ```
MARKDOWN