├── .rubocop.yml ├── README.md ├── LICENSE ├── minimal.rb └── devise.rb /.rubocop.yml: -------------------------------------------------------------------------------- 1 | AllCops: 2 | NewCops: enable 3 | Exclude: 4 | - 'bin/**/*' 5 | - 'db/**/*' 6 | - 'config/**/*' 7 | - 'node_modules/**/*' 8 | - 'script/**/*' 9 | - 'support/**/*' 10 | - 'tmp/**/*' 11 | - 'test/**/*' 12 | 13 | Style/ConditionalAssignment: 14 | Enabled: false 15 | Style/StringLiterals: 16 | Enabled: false 17 | Style/RedundantReturn: 18 | Enabled: false 19 | Style/Documentation: 20 | Enabled: false 21 | Style/WordArray: 22 | Enabled: false 23 | Metrics/AbcSize: 24 | Enabled: false 25 | Style/MutableConstant: 26 | Enabled: false 27 | Style/SignalException: 28 | Enabled: false 29 | Metrics/CyclomaticComplexity: 30 | Enabled: false 31 | Style/MissingRespondToMissing: 32 | Enabled: false 33 | Lint/MissingSuper: 34 | Enabled: false 35 | Style/FrozenStringLiteralComment: 36 | Enabled: false 37 | Layout/LineLength: 38 | Max: 120 39 | Style/EmptyMethod: 40 | Enabled: false 41 | Bundler/OrderedGems: 42 | Enabled: false 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails Templates 2 | 3 | Quickly generate a rails app with the default [Wagon](https://www.lewagon.com) configuration 4 | using [Rails Templates](http://guides.rubyonrails.org/rails_application_templates.html). 5 | 6 | ⚠️ The following templates have been made for Rails 7. If you use Rails 6, please refer to the [`no-update` branch templates](https://github.com/lewagon/rails-templates/tree/no-update) 7 | 8 | ## Minimal 9 | 10 | Get a minimal rails app ready to be deployed on Heroku with Bootstrap, Simple form and debugging gems. 11 | 12 | ```bash 13 | rails new \ 14 | -d postgresql \ 15 | -m https://raw.githubusercontent.com/lewagon/rails-templates/master/minimal.rb \ 16 | CHANGE_THIS_TO_YOUR_RAILS_APP_NAME 17 | ``` 18 | 19 | ## Devise 20 | 21 | Same as minimal **plus** a Devise install with a generated `User` model. 22 | 23 | ```bash 24 | rails new \ 25 | -d postgresql \ 26 | -m https://raw.githubusercontent.com/lewagon/rails-templates/master/devise.rb \ 27 | CHANGE_THIS_TO_YOUR_RAILS_APP_NAME 28 | ``` 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2017 Le Wagon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /minimal.rb: -------------------------------------------------------------------------------- 1 | run "if uname | grep -q 'Darwin'; then pgrep spring | xargs kill -9; fi" 2 | 3 | # Gemfile 4 | ######################################## 5 | inject_into_file "Gemfile", before: "group :development, :test do" do 6 | <<~RUBY 7 | gem "bootstrap", "~> 5.3" 8 | gem "autoprefixer-rails" 9 | gem "font-awesome-sass", "~> 6.1" 10 | gem "simple_form", github: "heartcombo/simple_form" 11 | gem "sassc-rails" 12 | 13 | RUBY 14 | end 15 | 16 | inject_into_file "Gemfile", after: "group :development, :test do" do 17 | "\n gem \"dotenv-rails\"" 18 | end 19 | 20 | # Assets 21 | ######################################## 22 | run "rm -rf app/assets/stylesheets" 23 | run "rm -rf vendor" 24 | run "curl -L https://github.com/lewagon/rails-stylesheets/archive/master.zip > stylesheets.zip" 25 | run "unzip stylesheets.zip -d app/assets && rm -f stylesheets.zip && rm -f app/assets/rails-stylesheets-master/README.md" 26 | run "mv app/assets/rails-stylesheets-master app/assets/stylesheets" 27 | 28 | # Layout 29 | ######################################## 30 | 31 | gsub_file( 32 | "app/views/layouts/application.html.erb", 33 | '', 34 | '' 35 | ) 36 | 37 | # README 38 | ######################################## 39 | markdown_file_content = <<~MARKDOWN 40 | Rails app generated with [lewagon/rails-templates](https://github.com/lewagon/rails-templates), created by the [Le Wagon coding bootcamp](https://www.lewagon.com) team. 41 | MARKDOWN 42 | file "README.md", markdown_file_content, force: true 43 | 44 | # Generators 45 | ######################################## 46 | generators = <<~RUBY 47 | config.generators do |generate| 48 | generate.assets false 49 | generate.helper false 50 | generate.test_framework :test_unit, fixture: false 51 | end 52 | 53 | RUBY 54 | 55 | environment generators 56 | 57 | # General Config 58 | ######################################## 59 | general_config = <<~RUBY 60 | config.action_controller.raise_on_missing_callback_actions = false if Rails.version >= "7.1.0" 61 | RUBY 62 | 63 | environment general_config 64 | 65 | ######################################## 66 | # After bundle 67 | ######################################## 68 | after_bundle do 69 | # Generators: db + simple form + pages controller 70 | ######################################## 71 | rails_command "db:drop db:create db:migrate" 72 | generate("simple_form:install", "--bootstrap") 73 | generate(:controller, "pages", "home", "--skip-routes", "--no-test-framework") 74 | 75 | # Routes 76 | ######################################## 77 | route 'root to: "pages#home"' 78 | 79 | # Gitignore 80 | ######################################## 81 | append_file ".gitignore", <<~TXT 82 | 83 | # Ignore .env file containing credentials. 84 | .env* 85 | 86 | # Ignore Mac and Linux file system files 87 | *.swp 88 | .DS_Store 89 | TXT 90 | 91 | # Bootstrap & Popper 92 | ######################################## 93 | append_file "config/importmap.rb", <<~RUBY 94 | pin "bootstrap", to: "bootstrap.min.js", preload: true 95 | pin "@popperjs/core", to: "popper.js", preload: true 96 | RUBY 97 | 98 | append_file "config/initializers/assets.rb", <<~RUBY 99 | Rails.application.config.assets.precompile += %w(bootstrap.min.js popper.js) 100 | RUBY 101 | 102 | append_file "app/javascript/application.js", <<~JS 103 | import "@popperjs/core" 104 | import "bootstrap" 105 | JS 106 | 107 | append_file "app/assets/config/manifest.js", <<~JS 108 | //= link popper.js 109 | //= link bootstrap.min.js 110 | JS 111 | 112 | # Heroku 113 | run "bundle lock --add-platform x86_64-linux" 114 | 115 | # Dotenv 116 | ######################################## 117 | run "touch '.env'" 118 | 119 | # Rubocop 120 | ######################################## 121 | run "curl -L https://raw.githubusercontent.com/lewagon/rails-templates/master/.rubocop.yml > .rubocop.yml" 122 | 123 | # Git 124 | ######################################## 125 | git :init 126 | git add: "." 127 | git commit: "-m 'Initial commit with minimal template from https://github.com/lewagon/rails-templates'" 128 | end 129 | -------------------------------------------------------------------------------- /devise.rb: -------------------------------------------------------------------------------- 1 | run "if uname | grep -q 'Darwin'; then pgrep spring | xargs kill -9; fi" 2 | 3 | # Gemfile 4 | ######################################## 5 | inject_into_file "Gemfile", before: "group :development, :test do" do 6 | <<~RUBY 7 | gem "bootstrap", "~> 5.3" 8 | gem "devise" 9 | gem "autoprefixer-rails" 10 | gem "font-awesome-sass", "~> 6.1" 11 | gem "simple_form", github: "heartcombo/simple_form" 12 | gem "sassc-rails" 13 | 14 | RUBY 15 | end 16 | 17 | inject_into_file "Gemfile", after: "group :development, :test do" do 18 | "\n gem \"dotenv-rails\"" 19 | end 20 | 21 | # Assets 22 | ######################################## 23 | run "rm -rf app/assets/stylesheets" 24 | run "rm -rf vendor" 25 | run "curl -L https://github.com/lewagon/rails-stylesheets/archive/master.zip > stylesheets.zip" 26 | run "unzip stylesheets.zip -d app/assets && rm -f stylesheets.zip && rm -f app/assets/rails-stylesheets-master/README.md" 27 | run "mv app/assets/rails-stylesheets-master app/assets/stylesheets" 28 | 29 | # Layout 30 | ######################################## 31 | 32 | gsub_file( 33 | "app/views/layouts/application.html.erb", 34 | '', 35 | '' 36 | ) 37 | 38 | # Flashes 39 | ######################################## 40 | file "app/views/shared/_flashes.html.erb", <<~HTML 41 | <% if notice %> 42 | 47 | <% end %> 48 | <% if alert %> 49 | 54 | <% end %> 55 | HTML 56 | 57 | run "curl -L https://raw.githubusercontent.com/lewagon/awesome-navbars/master/templates/_navbar_wagon.html.erb > app/views/shared/_navbar.html.erb" 58 | 59 | inject_into_file "app/views/layouts/application.html.erb", after: "" do 60 | <<~HTML 61 | <%= render "shared/navbar" %> 62 | <%= render "shared/flashes" %> 63 | HTML 64 | end 65 | 66 | # README 67 | ######################################## 68 | markdown_file_content = <<~MARKDOWN 69 | Rails app generated with [lewagon/rails-templates](https://github.com/lewagon/rails-templates), created by the [Le Wagon coding bootcamp](https://www.lewagon.com) team. 70 | MARKDOWN 71 | file "README.md", markdown_file_content, force: true 72 | 73 | # Generators 74 | ######################################## 75 | generators = <<~RUBY 76 | config.generators do |generate| 77 | generate.assets false 78 | generate.helper false 79 | generate.test_framework :test_unit, fixture: false 80 | end 81 | RUBY 82 | 83 | environment generators 84 | 85 | # General Config 86 | ######################################## 87 | general_config = <<~RUBY 88 | config.action_controller.raise_on_missing_callback_actions = false if Rails.version >= "7.1.0" 89 | RUBY 90 | 91 | environment general_config 92 | 93 | ######################################## 94 | # After bundle 95 | ######################################## 96 | after_bundle do 97 | # Generators: db + simple form + pages controller 98 | ######################################## 99 | rails_command "db:drop db:create db:migrate" 100 | generate("simple_form:install", "--bootstrap") 101 | generate(:controller, "pages", "home", "--skip-routes", "--no-test-framework") 102 | 103 | # Routes 104 | ######################################## 105 | route 'root to: "pages#home"' 106 | 107 | # Gitignore 108 | ######################################## 109 | append_file ".gitignore", <<~TXT 110 | # Ignore .env file containing credentials. 111 | .env* 112 | 113 | # Ignore Mac and Linux file system files 114 | *.swp 115 | .DS_Store 116 | TXT 117 | 118 | # Devise install + user 119 | ######################################## 120 | generate("devise:install") 121 | generate("devise", "User") 122 | 123 | # Application controller 124 | ######################################## 125 | run "rm app/controllers/application_controller.rb" 126 | file "app/controllers/application_controller.rb", <<~RUBY 127 | class ApplicationController < ActionController::Base 128 | before_action :authenticate_user! 129 | end 130 | RUBY 131 | 132 | # migrate + devise views 133 | ######################################## 134 | rails_command "db:migrate" 135 | generate("devise:views") 136 | 137 | link_to = <<~HTML 138 |

Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %>

139 | HTML 140 | button_to = <<~HTML 141 |
142 |
Unhappy?
143 | <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete, class: "btn btn-link" %> 144 |
145 | HTML 146 | gsub_file("app/views/devise/registrations/edit.html.erb", link_to, button_to) 147 | 148 | # Pages Controller 149 | ######################################## 150 | run "rm app/controllers/pages_controller.rb" 151 | file "app/controllers/pages_controller.rb", <<~RUBY 152 | class PagesController < ApplicationController 153 | skip_before_action :authenticate_user!, only: [ :home ] 154 | 155 | def home 156 | end 157 | end 158 | RUBY 159 | 160 | # Environments 161 | ######################################## 162 | environment 'config.action_mailer.default_url_options = { host: "http://localhost:3000" }', env: "development" 163 | environment 'config.action_mailer.default_url_options = { host: "http://TODO_PUT_YOUR_DOMAIN_HERE" }', env: "production" 164 | 165 | # Bootstrap & Popper 166 | ######################################## 167 | append_file "config/importmap.rb", <<~RUBY 168 | pin "bootstrap", to: "bootstrap.min.js", preload: true 169 | pin "@popperjs/core", to: "popper.js", preload: true 170 | RUBY 171 | 172 | append_file "config/initializers/assets.rb", <<~RUBY 173 | Rails.application.config.assets.precompile += %w(bootstrap.min.js popper.js) 174 | RUBY 175 | 176 | append_file "app/javascript/application.js", <<~JS 177 | import "@popperjs/core" 178 | import "bootstrap" 179 | JS 180 | 181 | append_file "app/assets/config/manifest.js", <<~JS 182 | //= link popper.js 183 | //= link bootstrap.min.js 184 | JS 185 | 186 | # Heroku 187 | ######################################## 188 | run "bundle lock --add-platform x86_64-linux" 189 | 190 | # Dotenv 191 | ######################################## 192 | run "touch '.env'" 193 | 194 | # Rubocop 195 | ######################################## 196 | run "curl -L https://raw.githubusercontent.com/lewagon/rails-templates/master/.rubocop.yml > .rubocop.yml" 197 | 198 | # Git 199 | ######################################## 200 | git :init 201 | git add: "." 202 | git commit: "-m 'Initial commit with devise template from https://github.com/lewagon/rails-templates'" 203 | end 204 | --------------------------------------------------------------------------------