initial commit for lite

trunk
Thomas Riboulet 2 years ago
parent 215a87d00f
commit 30fc23f900

@ -1,53 +0,0 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "<%= RUBY_VERSION %>"
gem "active_type"
<%= gemfile_entry "bcrypt", force: true -%>
<%= gemfile_entry "bootsnap" -%>
<%= gemfile_entry "cssbundling-rails" unless install_vite? -%>
<%= gemfile_entry "importmap-rails" unless install_vite? -%>
<%= gemfile_entry "jsbundling-rails" unless install_vite? -%>
<%= gemfile_entry "pg" -%>
gem "pgcli-rails"
<%= gemfile_entry "puma" -%>
gem "rack-canonical-host"
gem "rails", "~> <%= Rails.version[/\d+\.\d+\.\d+/] %>"
<%= gemfile_entry "sprockets-rails" -%>
<%= gemfile_entry "stimulus-rails" -%>
<%= gemfile_entry "turbo-rails" -%>
<%= %Q{gem "vite_rails"\n} if install_vite? -%>
group :production do
gem "postmark-rails"
gem "sidekiq"
end
group :development do
gem "amazing_print"
gem "annotate"
gem "brakeman", require: false
gem "bundler-audit", require: false
gem "letter_opener"
gem "rubocop", require: false
gem "rubocop-minitest", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
<%= gemfile_entry "web-console" -%>
end
group :development, :test do
gem "byebug"
gem "dotenv-rails"
gem "launchy"
end
group :test do
<%= gemfile_entry "capybara" -%>
gem "minitest-ci", require: false
<%= gemfile_entry "selenium-webdriver" -%>
gem "shoulda-context"
gem "shoulda-matchers"
<%= gemfile_entry "webdrivers" -%>
end

@ -1,6 +0,0 @@
@import "@picocss/pico";
// Uncomment this to disable Pico's responsive sizing and instead respect the user's browser font size setting
// :root {
// --font-size: revert;
// }

@ -1,50 +0,0 @@
copy_file "app/controllers/home_controller.rb"
copy_file "app/controllers/concerns/basic_auth.rb"
copy_file "app/helpers/layout_helper.rb"
insert_into_file "app/controllers/application_controller.rb", after: /^class ApplicationController.*\n/ do
<<-RUBY
include BasicAuth
RUBY
end
File.rename "app/views/layouts/application.html.erb", "app/views/layouts/base.html.erb"
prepend_to_file "app/views/layouts/base.html.erb", <<~ERB
<%# The "base" layout contains boilerplate common to *all* views. %>
ERB
insert_into_file "app/views/layouts/base.html.erb", <<-ERB, after: "<head>"
<!-- #{app_const_base.titleize} <%= Rails.application.config.version %> (<%= l(Rails.application.config.version_time) %>) -->
ERB
gsub_file "app/views/layouts/base.html.erb", %r{^\s*<title>.*</title>}, <<-ERB
<title>
<%= strip_tags(yield(:title)) + " " if content_for?(:title) %>
#{app_const_base.titleize}
</title>
<%# Specifies the default name of home screen bookmark in iOS %>
<meta name="apple-mobile-web-app-title" content="#{app_const_base.titleize}">
ERB
insert_into_file "app/views/layouts/base.html.erb", <<-ERB.rstrip, before: %r{^\s*</head>}
<%= yield(:head) %>
ERB
if install_vite?
gsub_file "app/views/layouts/base.html.erb", /^.*<%= stylesheet_link_tag.*$/, ""
gsub_file "app/views/layouts/base.html.erb",
/vite_javascript_tag 'application' %>/,
'vite_javascript_tag "application", "data-turbo-track": "reload" %>'
else
insert_into_file "app/views/layouts/base.html.erb", <<-ERB, before: /^.*<%= stylesheet_link_tag.*$/
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.min.css">
ERB
end
copy_file "app/views/layouts/application.html.erb"
copy_file "app/views/shared/_flash.html.erb"
copy_file "app/views/home/index.html.erb"

@ -1,2 +0,0 @@
<% provide(:title, "Home") %>
<p>Find me in app/views/home/index.html.erb</p>

@ -1,10 +0,0 @@
<%# The "application" layout is the default layout. It extends "base" %>
<%# to include things like header, footer, and alerts that are common %>
<%# to most (but not all) views. %>
<main class="container">
<%= render("shared/flash") %>
<%= yield %>
</main>
<% parent_layout "base" %>

@ -1,9 +0,0 @@
<%# Notice %>
<% if flash[:notice].present? %>
<div class="alert alert-success"><%= flash[:notice] %></div>
<% end %>
<%# Alert %>
<% if flash[:alert].present? %>
<div class="alert alert-danger"><%= flash[:alert] %></div>
<% end %>

@ -1,100 +0,0 @@
version: 2.1
orbs:
browser-tools: circleci/browser-tools@1.2.5
node: circleci/node@5.0.2
ruby: circleci/ruby@1.6.0
executors:
ruby:
docker:
- image: cimg/ruby:<%= RUBY_VERSION %>-browsers
environment:
PGHOST: 127.0.0.1
PGUSER: postgres
PGPASS: postgres
RAILS_ENV: test
- image: cimg/postgres:14.2
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
commands:
install_node_dependencies:
steps:
- node/install:
install-yarn: true
- node/install-packages:
pkg-manager: yarn
set_up_database:
steps:
- run:
name: Set Up Database
command: bundle exec rake db:create db:schema:load
jobs:
static_analysis:
executor: ruby
steps:
- checkout
- ruby/install-deps
- install_node_dependencies
- run:
name: Run Overcommit
command: |
gem install overcommit --no-document
git config --local user.name "Circle CI"
git config --local user.email ci@example.com
overcommit --sign
overcommit --run
security_audits:
executor: ruby
steps:
- checkout
- ruby/install-deps
- run:
name: Brakeman
command: bundle exec brakeman --exit-on-warn --no-progress --color --output /dev/stdout
- run:
name: Bundle Audit
command: bundle exec bundle-audit check --update -v
test:
executor: ruby
steps:
- checkout
- ruby/install-deps
- set_up_database
- run:
name: Run Tests
command: bundle exec rake test TESTOPTS="--ci-dir=./reports"
- store_test_results:
path: ./reports
test_system:
executor: ruby
steps:
- browser-tools/install-chrome
- browser-tools/install-chromedriver
- checkout
- ruby/install-deps
- install_node_dependencies
- set_up_database
- run:
name: Run System Tests
command: bundle exec rake test:system TESTOPTS="--ci-dir=./reports"
- store_test_results:
path: ./reports
- store_artifacts:
path: ./tmp/screenshots
destination: screenshots
workflows:
version: 2
commit-workflow:
jobs:
- static_analysis
- security_audits
- test
- test_system

@ -1 +0,0 @@
template "circleci/config.yml.tt", ".circleci/config.yml"

@ -0,0 +1,53 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "<%= RUBY_VERSION %>"
<%= gemfile_entry "active_type" -%> # make any class quack like ActiveRecord
<%= gemfile_entry "bcrypt", force: true -%>
<%= gemfile_entry "bootsnap" -%>
<%= gemfile_entry "cssbundling-rails" -%>
<%= gemfile_entry "importmap-rails" -%>
<%= gemfile_entry "jsbundling-rails" -%>
<%= gemfile_entry "pg" -%>
gem "pgcli-rails"
<%= gemfile_entry "puma" -%>
gem "rack-canonical-host"
gem "rails", "~> <%= Rails.version[/\d+\.\d+\.\d+/] %>"
<%= gemfile_entry "sprockets-rails" -%>
<%= gemfile_entry "stimulus-rails" -%>
<%= gemfile_entry "turbo-rails" -%>
gem "bulma-rails" # good compromise CSS framework https://github.com/joshuajansen/bulma-rails https://bulma.io
gem "haml-rails", "~> 2.0" # haml instead of erb for layouts, views and partials
group :production do
gem "postmark-rails" # best email service https://postmarkapp.com/
gem "sidekiq" # background jobs
end
group :development do
gem "amazing_print"
gem "annotate" # model annotations https://github.com/ctran/annotate_models
gem "brakeman", require: false
gem "bundler-audit", require: false # security checks
gem "flay", require: false # structural similarities analyzer https://github.com/seattlerb/flay
gem "letter_opener" # don't send emails when working locally display them https://github.com/ryanb/letter_opener
gem "rubocop", require: false
gem "rubocop-rspec", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
<%= gemfile_entry "web-console" -%> # web debug
end
group :development, :test do
gem "byebug" # console debug https://github.com/deivid-rodriguez/byebug#byebugs-commands
gem "dotenv-rails"
gem "launchy" # hepler for testing https://github.com/copiousfreetime/launchy
end
group :test do
<%= gemfile_entry "capybara" -%>
<%= gemfile_entry "selenium-webdriver" -%>
gem "rspec-rails"
<%= gemfile_entry "webdrivers" -%>
end

@ -1,7 +1,5 @@
# mattbrictson/rails-template
[![Circle](https://circleci.com/gh/mattbrictson/rails-template/tree/main.svg?style=shield)](https://app.circleci.com/pipelines/github/mattbrictson/rails-template?branch=main)
## Description
This is the application template that I recommend for Rails 7 projects. I've assembled this template over the years to include best-practices, tweaks, documentation, and personal preferences, while still generally adhering to the "Rails way".
@ -96,7 +94,7 @@ If you don't specify `--javascript vite`, then this template will use the standa
* Security
* [brakeman][] and [bundler-audit][] detect security vulnerabilities
* Testing
* [shoulda][] shortcuts for common ActiveRecord tests
* [rspec][] shortcuts for common ActiveRecord tests
#### Postmark
@ -123,13 +121,11 @@ Rails generators are very lightly documented; what youll find is that most of
[annotate]:https://github.com/ctran/annotate_models
[amazing_print]:https://github.com/amazing-print/amazing_print
[rubocop]:https://github.com/bbatsov/rubocop
[pico]:https://picocss.com
[pico]:https://bulma.io
[Postmark]:http://postmarkapp.com
[postmark-rails]:http://www.rubydoc.info/gems/postmark-rails/0.12.0
[brakeman]:https://github.com/presidentbeef/brakeman
[bundler-audit]:https://github.com/rubysec/bundler-audit
[shoulda]:https://github.com/thoughtbot/shoulda
[application templates]:http://guides.rubyonrails.org/generators.html#application-templates
[template.rb]: template.rb
[thor]: https://github.com/erikhuda/thor
[vite]: https://vite-ruby.netlify.app

@ -10,12 +10,11 @@ This README describes the purpose of this repository and how to set up a develop
This project requires:
* Ruby <%= RUBY_VERSION %>, preferably managed using [rbenv][]
* PostgreSQL must be installed and accepting connections
* Ruby <%= RUBY_VERSION %>, preferably managed using [asdf][https://asdf-vm.com/]
* [Docker](https://docs.docker.com/get-docker/) must be installed and running
* Docker Compose must be installed (within docker or not)
On a Mac, you can obtain all of the above packages using [Homebrew][].
If you need help setting up a Ruby development environment, check out this [Rails OS X Setup Guide](https://mattbrictson.com/rails-osx-setup-guide).
If you need help setting up a Ruby development environment, check out this [Ruby Devstation OS X Setup script](https://git.imfiny.com/OpenSource/setup).
## Getting started
@ -30,8 +29,9 @@ Run the `bin/setup` script. This script will:
### Run it!
1. Run `bin/rake` to run all tests and lint checks.
2. Start the app with `yarn start`
1. Start Redis and PostgreSQL databases as containers `docker-compose up -d`
2. Run `bin/rake` to run all tests and lint checks.
3. Start the app with `yarn start`
Access the app at <http://localhost:3000/>.

@ -0,0 +1,24 @@
copy_file "app/controllers/home_controller.rb"
copy_file "app/controllers/concerns/basic_auth.rb"
copy_file "app/helpers/layout_helper.rb"
insert_into_file "app/controllers/application_controller.rb", after: /^class ApplicationController.*\n/ do
<<-RUBY
include BasicAuth
RUBY
end
File.rename "app/views/layouts/application.html.erb", "app/views/layouts/application.html.erb.old"
run_with_clean_bundler_env "rails generate haml:application_layout convert"
copy_file "app/views/layouts/application.haml"
gsub_file "app/views/layouts/application.haml", "%title", <<-HAML
%title
= strip_tags(yield(:title)) + " " if content_for?(:title)
#{app_const_base.titleize}
%meta{:content => "#{app_const_base.titleize}", :name => "apple-mobile-web-app-title"}
HAML
copy_file "app/views/shared/_flash.haml"
copy_file "app/views/home/index.haml"

@ -0,0 +1,2 @@
- provide(:title, "Home")
%p Find me in app/views/home/index.haml

@ -0,0 +1,10 @@
!!!
%html
%head
%title
%body
%section.section
.container
= render("shared/flash")
= yield

@ -0,0 +1,6 @@
-# Notice
- if flash[:notice].present?
.alert.alert-success= flash[:notice]
-# Alert
- if flash[:alert].present?
.alert.alert-danger= flash[:alert]

@ -2,6 +2,10 @@ default: &default
adapter: postgresql
encoding: unicode
pool: <%%= [5, *ENV.values_at("RAILS_MAX_THREADS", "SIDEKIQ_CONCURRENCY")].map(&:to_i).max %>
host: 0.0.0.0
port: 5432
username: postgres
password: postgres
development:
<<: *default

@ -0,0 +1,18 @@
version: "3.7"
services:
redis:
image: redis:6.2
ports:
- "6379:6379"
postgres:
image: postgres:13.2
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
volumes:
- data-postgres:/var/lib/postgresql/data
volumes:
data-postgres:
driver: local

@ -1,5 +1,5 @@
require:
- rubocop-minitest
- rubocop-rspec
- rubocop-performance
- rubocop-rails
@ -28,27 +28,27 @@ Layout/LineLength:
- "config/initializers/content_security_policy.rb"
Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space
EnforcedStyle: space
Metrics/AbcSize:
Max: 20
Exclude:
- "test/**/*"
- "rspec/**/*"
Metrics/BlockLength:
Exclude:
- "config/**/*"
- "test/**/*"
- "rspec/**/*"
Metrics/ClassLength:
Exclude:
- "test/**/*"
- "rspec/**/*"
Metrics/MethodLength:
Max: 18
Exclude:
- "db/migrate/*"
- "test/**/*"
- "rspec/**/*"
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: optional
@ -76,19 +76,19 @@ Style/BarePercentLiterals:
EnforcedStyle: percent_q
Style/ClassAndModuleChildren:
Enabled: false
Enabled: nested
Style/Documentation:
Enabled: false
Enabled: true
Style/DoubleNegation:
Enabled: false
Style/EmptyMethod:
Enabled: false
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: false
Enabled: true
Style/NumericPredicate:
Enabled: false

@ -0,0 +1,90 @@
# .semaphore/semaphore.yml
version: v1.0
name: Rails project
agent:
machine:
type: e1-standard-2
os_image: ubuntu2004
blocks:
- name: Setup
dependencies: []
task:
jobs:
- name: bundle
commands:
- sem-version ruby <%= RUBY_VERSION[/\d+\.\d+/] %>
- sem-version node 16.15.0
- checkout
- cache restore
- bundle install
- cache store
- name: Code scanning
dependencies:
- Setup
task:
jobs:
- name: check style + security
commands:
- sem-version ruby 2.7.5
- sem-version node 16.15.0
- checkout
- cache restore
- bundle install
- cache store
- bundle exec rubocop
- bundle exec brakeman
- bundle exec flay
- name: Unit tests
dependencies:
- Code scanning
task:
prologue:
commands:
- sem-version ruby 2.7.5
- sem-version node 16.15.0
- checkout
- cache restore
- bundle install
- cache store
- sem-service start postgres
- 'bundle exec rake db:setup'
jobs:
- name: RSpec - model tests
commands:
- bundle exec rspec spec/models
- name: RSpec - controller tests
commands:
- bundle exec rspec spec/controllers
epilogue:
always:
commands:
- "[[ -f junit.xml ]] && test-results publish --name \"🧪 Unit tests\" junit.xml"
- name: Integration tests
dependencies:
- Unit tests
task:
prologue:
commands:
- sem-version ruby 2.7.5
- sem-version node 16.15.0
- checkout
- cache restore
- bundle install
- cache store
jobs:
- name: RSpec - feature specs
commands:
- sem-service start postgres
- 'bundle exec rake db:setup'
- bundle exec rspec spec/features
epilogue:
always:
commands:
- "[[ -f junit.xml ]] && test-results publish --name \"🏗️ Integration tests\" junit.xml"
after_pipeline:
task:
jobs:
- name: Publish Results
commands:
- test-results gen-pipeline-report

@ -0,0 +1 @@
template "semaphore/semaphore.yml.tt", ".semaphore/semaphore.yml"

@ -8,13 +8,6 @@ def apply_template!
assert_postgresql
add_template_repository_to_source_path
if install_vite?
self.options = options.merge(
css: nil,
skip_asset_pipeline: true
)
end
template "Gemfile.tt", force: true
template "README.md.tt", force: true
@ -27,11 +20,12 @@ def apply_template!
copy_file "Procfile"
copy_file "package.json"
copy_file "docker-compose.yml"
apply "Rakefile.rb"
apply "config.ru.rb"
apply "bin/template.rb"
apply "circleci/template.rb"
apply "semaphore/template.rb"
apply "config/template.rb"
apply "lib/template.rb"
apply "test/template.rb"
@ -46,13 +40,9 @@ def apply_template!
/.env.development
/.env.*local
IGNORE
if install_vite?
File.rename("app/javascript", "app/frontend") if File.exist?("app/javascript")
run_with_clean_bundler_env "bundle exec vite install"
run "yarn add sass @picocss/pico"
apply "app/frontend/template.rb"
end
run_with_clean_bundler_env "rails generate rspec:install"
append_to_file "spec/spec_helper.rb", "require 'capybara_helper'"
append_to_file "spec/spec_helper.rb", "require 'mailer_helper'"
apply "app/template.rb"
@ -132,8 +122,8 @@ def assert_valid_options
skip_bundle: false,
skip_git: false,
skip_system_test: false,
skip_test: false,
skip_test_unit: false,
skip_test: true,
skip_test_unit: true,
edge: false
}
valid_options.each do |key, expected|
@ -213,6 +203,7 @@ end
def create_database_and_initial_migration
return if Dir["db/migrate/**/*.rb"].any?
run "docker-compose up -d"
run_with_clean_bundler_env "bin/rails db:create"
run_with_clean_bundler_env "bin/rails generate migration initial_migration"
end
@ -223,7 +214,6 @@ def add_yarn_start_script
run_with_clean_bundler_env "yarn add --dev concurrently"
procs = ["'bin/rails s -b 0.0.0.0'"]
procs << "'bin/vite dev'" if File.exist?("bin/vite")
procs << "bin/webpack-dev-server" if File.exist?("bin/webpack-dev-server")
add_package_json_script(start: "concurrently --raw --kill-others-on-fail #{procs.join(" ")}")
@ -246,8 +236,8 @@ def add_yarn_lint_and_run_fix
add_package_json_script("lint": "npm-run-all -c lint:*")
add_package_json_script("lint:js": "eslint 'app/{components,frontend,javascript}/**/*.{js,jsx}'")
add_package_json_script("lint:css": "stylelint 'app/{components,frontend,assets/stylesheets}/**/*.{css,scss}'")
run_with_clean_bundler_env "yarn lint:js --fix"
run_with_clean_bundler_env "yarn lint:css --fix"
#run_with_clean_bundler_env "yarn lint:js --fix"
#run_with_clean_bundler_env "yarn lint:css --fix"
end
def add_package_json_script(scripts)
@ -256,7 +246,4 @@ def add_package_json_script(scripts)
end
end
def install_vite?
options[:javascript] == "vite"
end
apply_template!

@ -0,0 +1,18 @@
copy_file "test/spec/capybara_helper.rb"
copy_file "test/spec/mailer_helper.rb"
empty_directory_with_keep_file "spec/mailers"
empty_directory_with_keep_file "spec/unit"
empty_directory_with_keep_file "spec/requests"
# gsub_file "test/application_system_test_case.rb", /^ driven_by :selenium.*$/, <<~RUBY
# driven_by :selenium,
# using: (ENV["DISABLE_HEADLESS_CHROME"].present? ? :chrome : :headless_chrome),
# screen_size: [1400, 1400] do |options|
# options.add_argument("no-sandbox")
# end
# def setup
# Capybara.server = :puma, { Silent: true }
# super
# end
# RUBY

@ -1,5 +1,3 @@
# This has to come first
require_relative "./support/rails"
# Load everything else from test/support
Dir[File.expand_path("support/**/*.rb", __dir__)].sort.each { |rb| require(rb) }

@ -1,2 +0,0 @@
# Generate XML test reports that can be parsed by CircleCI
require "minitest/ci" if ENV["CIRCLECI"]

@ -1,11 +0,0 @@
ENV["RAILS_ENV"] ||= "test"
require_relative "../../config/environment"
require "rails/test_help"
class ActiveSupport::TestCase
# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml for all tests in alpha order.
fixtures :all
end

@ -1,6 +0,0 @@
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :minitest
with.library :rails
end
end

@ -1,24 +0,0 @@
copy_file "test/test_helper.rb", force: true
copy_file "test/support/capybara.rb"
copy_file "test/support/circleci.rb"
copy_file "test/support/mailer.rb"
copy_file "test/support/rails.rb"
copy_file "test/support/shoulda_matchers.rb"
copy_file "test/system/layout_helper_test.rb"
empty_directory_with_keep_file "test/mailers"
empty_directory_with_keep_file "test/unit"
empty_directory_with_keep_file "test/unit/lib"
empty_directory_with_keep_file "test/unit/lib/tasks"
gsub_file "test/application_system_test_case.rb", /^ driven_by :selenium.*$/, <<~RUBY
driven_by :selenium,
using: (ENV["DISABLE_HEADLESS_CHROME"].present? ? :chrome : :headless_chrome),
screen_size: [1400, 1400] do |options|
options.add_argument("no-sandbox")
end
def setup
Capybara.server = :puma, { Silent: true }
super
end
RUBY
Loading…
Cancel
Save