Last active
July 3, 2022 20:47
-
-
Save geraldoantonio/6b3925c0df84ce14e7c89055a6b4b19b to your computer and use it in GitHub Desktop.
Ruby on Rails Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rails new . --database=postgresql -M -C -T --skip-hotwire --javascript=esbuild --css=bootstrap -m 'https://gist.githubusercontent.com/geraldoantonio/6b3925c0df84ce14e7c89055a6b4b19b/raw/template.rb' | |
gem_group :development, :test do | |
gem 'factory_bot_rails' | |
gem 'faker' | |
gem 'guard-rspec', require: false | |
gem 'pry' | |
gem 'rspec-rails' | |
end | |
gem_group :development do | |
gem 'meta_request', require: false | |
gem 'rubocop-rails', require: false | |
gem 'solargraph', require: false | |
end | |
gem_group :test do | |
gem 'database_cleaner' | |
end | |
gem 'newrelic_rpm' | |
gem 'rails-i18n' | |
gem 'rollbar' | |
gem 'sassc-rails' | |
run 'bundle install' | |
say 'RSpec setup', :yellow | |
generate 'rspec:install' | |
append_file '.rspec' do | |
<<~CODE | |
--color | |
--format documentation | |
CODE | |
end | |
say 'FactoryBot setup', :yellow | |
file 'spec/support/factory_bot.rb' do | |
<<~CODE | |
# frozen_string_literal: true | |
RSpec.configure do |config| | |
config.include FactoryBot::Syntax::Methods | |
end | |
CODE | |
end | |
file 'spec/factories.rb' do | |
<<~CODE | |
# frozen_string_literal: true | |
FactoryBot.define do | |
factory :short_link do | |
hash { SecureRandom.urlsafe_base64(4) } | |
long_url { Faker::Internet.url } | |
short_url { long_url + '/' + hash } | |
end | |
end | |
CODE | |
end | |
say 'Rollbar Setup', :yellow | |
generate(:rollbar) | |
say 'Application Configuration' | |
environment 'config.sass.inline_source_maps = true', env: 'development' | |
environment 'routes.default_url_options = { host: "localhost:3000" }', env: %w[development test] | |
environment 'routes.default_url_options = { host: ENV[\'APP_DOMAIN\']}', env: 'production' | |
environment 'config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")]' | |
environment 'config.i18n.default_locale = "pt-BR"' | |
environment 'config.time_zone = "Brazil/East"' | |
environment 'config.active_record.default_timezone = :local # Or :utc' | |
environment 'config.i18n.available_locales = "pt-BR"' | |
say 'Rubocop setup', :yellow | |
file '.rubocop.yml' do | |
<<~CODE | |
require: rubocop-rails | |
AllCops: | |
NewCops: enable | |
Exclude: | |
- "node_modules/**/*" | |
- "bin/**/*" | |
- "config/**/*" | |
- "tmp/**/*" | |
- "db/**/*" | |
- "vendor/bundle/**/*" | |
SuggestExtensions: false | |
Metrics/BlockLength: | |
Exclude: | |
- 'Guardfile' | |
Style/Documentation: | |
Enabled: false | |
CODE | |
end | |
say 'Guard setup', :yellow | |
run 'bundle exec guard init' | |
say 'Gihub CI setup', :yellow | |
file '.github/workflows/ci.yml' do | |
<<~CODE | |
name: Continuous Integration | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
backend: | |
name: backend | |
runs-on: ubuntu-latest | |
services: | |
postgres: | |
image: postgres:11 | |
ports: ["5432:5432"] | |
env: | |
POSTGRES_PASSWORD: "postgres" | |
options: >- | |
--health-cmd pg_isready | |
--health-retries 5 | |
--health-interval 5s | |
--health-timeout 10s | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Install system dependencies | |
run: sudo apt-get -yqq install libpq-dev | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
bundler-cache: true | |
- name: Check code with Rubocop linter | |
run: | | |
gem install rubocop | |
bundle exec rubocop | |
- name: Run rails tests | |
run: bundle exec rspec | |
CODE | |
end | |
rails_command('db:setup') | |
run 'rubocop -A' | |
file 'app/javascript/custom/flash_messages.js' do | |
<<~CODE | |
import toastr from 'toastr'; | |
document.addEventListener('DOMContentLoaded', () => { | |
const toastrTypes = { alert: "warning", error: "error", notice: "success" } | |
JSON.parse(document.body.dataset.flashMessages).forEach(flashMessage => { | |
const [type, message] = flashMessage | |
toastr[toastrTypes[type]](message, '', { | |
type: toastrTypes[type], | |
closeButton: true, | |
progressBar: true, | |
positionClass: 'toast-top-right', | |
showDuration: '300', | |
hideDuration: '1000', | |
timeOut: '5000', | |
extendedTimeOut: '1000', | |
showEasing: 'swing', | |
hideEasing: 'linear', | |
showMethod: 'fadeIn', | |
hideMethod: 'fadeOut' | |
}); | |
}) | |
}) | |
CODE | |
end | |
append_file 'app/helpers/application_helper.rb' do | |
<<~CODE | |
def app_name | |
Rails.application.class.module_parent_name | |
end | |
CODE | |
end | |
say 'Template setup', :yellow | |
file 'app/views/layouts/_header.html.erb' do | |
<<~CODE | |
<nav class="navbar navbar-expand-lg bg-light fixed-top"> | |
<div class="container-fluid"> | |
<%= link_to app_name, root_path, class: 'navbar-brand' %> | |
</div> | |
</nav> | |
CODE | |
end | |
file 'app/views/layouts/_footer.html.erb' do | |
<<~CODE | |
<footer class="fixed-bottom p-3 mt-3 bg-dark text-white d-flex flex-column align-items-end"> | |
<span> | |
developed by <%= link_to 'Geraldo Junior', "https://github.com/geraldoantonio" %> | |
</span> | |
</footer> | |
CODE | |
end | |
remove_file 'app/views/layouts/application.html.erb' | |
file 'app/views/layouts/application.html.erb' do | |
<<~CODE | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title><%= app_name %></title> | |
<meta name="viewport" content="width=device-width,initial-scale=1"> | |
<%= csrf_meta_tags %> | |
<%= csp_meta_tag %> | |
<%= stylesheet_link_tag "application" %> | |
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> | |
</head> | |
<body class="container-fluid" data-flash-messages="<%= JSON.dump(flash.to_a) %>"> | |
<%= render partial: 'layouts/header' %> | |
<main class="p-5 my-5"> | |
<%= yield %> | |
</main> | |
<%= render partial: 'layouts/footer' %> | |
</body> | |
</html> | |
CODE | |
end | |
route "root to: 'home#index'" | |
file 'app/controllers/home_controller.rb' do | |
<<~CODE | |
class HomeController < ApplicationController | |
def index | |
flash.now[:notice] = "Welcome to the \#{app_name}!" | |
flash.now[:error] = "Welcome to the \#{app_name}!" | |
flash.now[:alert] = "Welcome to the \#{app_name}!" | |
end | |
end | |
CODE | |
end | |
file 'app/views/home/index.html.erb' do | |
<<~CODE | |
<h3>Welcome to the <%= app_name %></h3> | |
CODE | |
end | |
after_bundle do | |
say 'Install Toastr from show flash messages', :yellow | |
run 'yarn add toastr' | |
append_file 'app/assets/stylesheets/application.bootstrap.scss' do | |
<<~CODE | |
@import 'toastr/toastr'; | |
CODE | |
end | |
append_file 'app/javascript/application.js' do | |
<<~CODE | |
import './custom/flash_messages' | |
CODE | |
end | |
git :init | |
git add: '.' | |
git commit: "-a -m 'Initial commit'" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment