Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darwintantuco/alpha
Opinionated rails application template
https://github.com/darwintantuco/alpha
rails rails-template
Last synced: 18 days ago
JSON representation
Opinionated rails application template
- Host: GitHub
- URL: https://github.com/darwintantuco/alpha
- Owner: darwintantuco
- License: mit
- Created: 2019-01-15T04:49:43.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-11-20T01:03:09.000Z (almost 4 years ago)
- Last Synced: 2024-10-09T19:01:49.774Z (30 days ago)
- Topics: rails, rails-template
- Language: Ruby
- Homepage:
- Size: 249 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# alpha
![Ruby CI](https://github.com/darwintantuco/alpha/workflows/Ruby%20CI/badge.svg)
Setting up a rails project takes at least one day to configure. This is my attempt to make it as fast as possible.
All files generated by rails are preserved.
Changes are made by inserting code snippets to generated files.
Each change is separated by different commits to easily track any changes made.
## tl;dr
- Working react component using [remount](https://github.com/rstacruz/remount)
- Essential packages
- [sanitize.css](https://github.com/csstools/sanitize.css)
- [modularscale-sass](https://github.com/modularscale/modularscale-sass)
- [hamlit](https://github.com/k0kubun/hamlit) as templating language
- Rspec test suite
- Includes rspec and other gems useful in testing.
- Preconfigured with headless chromedriver
- Working rspec examples with js enabled
- Javascript test suite
- [jest](https://github.com/facebook/jest)
- [react-testing-library](https://github.com/testing-library/react-testing-library)
- Preconfigured linters
- [rubocop](https://github.com/rubocop-hq/rubocop)
- [prettier](https://github.com/prettier/prettier)
- [eslint](https://github.com/eslint/eslint)
- [stylelint](https://github.com/stylelint/stylelint)## Getting Started
### Requirements
- ruby >= 2.7.0
- rails >= 6.0.2
- nodejs >= 10.15.1
- yarn >= 1.12.0### Optional
- asdf
### Basic Usage
```
rails new appname -m https://raw.githubusercontent.com/darwintantuco/alpha/master/template.rb
```### Recommended Usage
```
rails new appname \
--database=postgresql \
--skip-test \
--skip-turbolinks \
--skip-coffee \
--asdf \
--typescript \
-m https://raw.githubusercontent.com/darwintantuco/alpha/master/template.rb
```#### Custom Flags
| Flag | Description |
| :----------: | :--------------------------------------------------------------: |
| --asdf | generates `.tool_versions` |
| --typescript | typescript support and sample react components are in typescript |### Webpacker Setup
#### Folder Structure
```
├── app
├── channels
├── assets
├── channels
├── javascript
│ ├── css
│ │ ├── components
│ │ │ └── home-page.scss
│ │ ├── application.scss
│ │ └── vendor.scss
│ ├── images
│ │ ├── application.js
│ │ ├── rails-logo.svg
│ │ └── welcome.jpeg
│ ├── js
│ │ └── application.js
│ ├── packs
│ │ └── application.js
│ └── react
│ ├── components
│ │ ├── __tests__
│ │ └── Greeter.js / Greeter.tsx
│ └── application.js
├── jobs
└── mailers
```### React
Added packages:
- react
- react-dom
- babel-preset-react
- remount### Essential packages
- [sanitize.css](https://github.com/csstools/sanitize.css) as css resets
- [modularscale-sass](https://github.com/modularscale/modularscale-sass)### Rspec Test Suite
- Includes rspec and other gems useful in testing.
- Preconfigured with headless chromedriver
- Working rspec examples with js enabled| Gem | Description |
| :----------------------: | :---------------------------------: |
| rspec-rails | rspec wrapper for rails |
| factory_bot_rails | fixtures |
| rails-controller-testing | helper for rspec controller testing |
| capybara | testing users' interaction |
| selenium-webdriver | default driver for javascript tests |
| chromedriver-helper | use chromedriver |
| database_cleaner | ensure a clean state for testing |
| faker | generate fake data |
| rubocop-rspec | rspec-specific analysis |### Javascript Test Suite
Added packages:
- jest
- babel-jest
- react-testing-library```js
// jest.config.js
module.exports = {
roots: ['app/assets/javascripts', 'app/javascript']
}
```### Preconfigured Linters
Comes with initial config but can be updated to your preference.
#### Rubocop
Added gems:
- rubocop
- rubocop-rspecInitial `rubocop_todo.yml` is generated.
```yaml
# .rubocop.yml
inherit_from: .rubocop_todo.yml
require: rubocop-rspecStyle/FrozenStringLiteralComment:
EnforcedStyle: neverStyle/StringLiterals:
EnforcedStyle: double_quotesStyle/HashSyntax:
EnforcedStyle: ruby19Layout/IndentationConsistency:
EnforcedStyle: indented_internal_methodsLayout/CaseIndentation:
EnforcedStyle: endLayout/BlockAlignment:
Enabled: falseLayout/EndAlignment:
EnforcedStyleAlignWith: start_of_lineAllCops:
Exclude:
- 'vendor/**/*'
- 'node_modules/**/*'
- 'db/migrate/*'
- 'db/schema.rb'
- 'db/seeds.rb'
- 'bin/*'
TargetRubyVersion: 2.7.0
```#### Eslint
Added packages:
- eslint
- babel-eslint
- eslint-config-prettier
- eslint-plugin-react```js
// .eslintrc.js
module.exports = {
plugins: ['react'],
parser: 'babel-eslint',
env: {
jest: true
},
rules: {
'react/prop-types': 0
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'eslint-config-prettier'
],
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2018,
sourceType: 'module'
}
}
```#### Prettier
Added packages:
- prettier
```js
// .prettierrc
{
"semi": false,
"singleQuote": true,
"jsxSingleQuote": true
}
```#### Stylelint
Added packages:
- stylelint
- stylelint-8-point-grid
- stylelint-config-standard
- stylelint-rscss```js
// .stylelintrc
{
"extends": [
"stylelint-config-standard",
"stylelint-rscss/config",
"stylelint-8-point-grid"
],
"rules": {
"plugin/8-point-grid": {
"base": 8,
"allowlist": ["4px", "2px", "1px"]
},
"at-rule-no-unknown": null,
"at-rule-empty-line-before": null
}
}
```### Yarn Scripts
| Command | Description |
| :---------------------: | :-------------------------------------: |
| yarn run test | jest |
| yarn run lint:ruby | rubocop |
| yarn run lint:js | eslint |
| yarn run lint:css | stylelint |
| yarn run prettier:check | prettier |
| yarn run prettier:fix | prettier |
| yarn run lint:ci | rubocop eslint stylelint prettier:check |## Post Install Guide
#### Convert existing erb files to haml
1. Install `html2haml`
```
$ gem install html2haml
```1. Convert erb files to haml (keeps original file)
```
$ find . -name \*.erb -print | sed 'p;s/.erb$/.haml/' | xargs -n2 html2haml
```1. Delete existing erb files
```
$ find . -name \*.erb | xargs git rm
```1. Commit the changes
1. Uninstall `html2haml````
$ gem uninstall html2haml
```#### Consider removing `config/database.yml` in version control / git
1. Add `config/database.yml` to `.gitignore`
```
$ echo config/database.yml >> .gitignore
```1. Rename `config/database.yml` to `config/database.yml.sample`
```
$ git mv config/database.yml config/database.yml.sample
```
1. Commit the changes## License
MIT