├── .foreman ├── Procfile.dev ├── README.md ├── app ├── javascript │ ├── images │ │ └── .keep │ ├── scripts │ │ ├── application.js │ │ └── index.js │ └── styles │ │ ├── application.scss │ │ └── index.js └── views │ └── pages │ └── home.html.erb ├── basic.rb ├── postcss.config.js └── tailwind.rb /.foreman: -------------------------------------------------------------------------------- 1 | procfile: Procfile.dev 2 | -------------------------------------------------------------------------------- /Procfile.dev: -------------------------------------------------------------------------------- 1 | web: bin/rails server -p 3000 2 | webpacker: bin/webpack-dev-server 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails Application Templates 2 | 3 | ## 新增專案可省略選項 4 | 5 | - `--skip-test-unit` 6 | - `--skip-sprockets` 7 | - `--skip-turbolinks` 8 | - `--skip-action-cable` 9 | - `--skip-active-storage` 10 | - `--skip-action-text` 11 | - `--skip-action-mailbox` 12 | - `--skip-action-mailer` 13 | 14 | 範例: 15 | 16 | $ rails new my_project -m TEMPLATE_PATH --skip-turbolinks --skip-active-storage 17 | 18 | ### `basic` 基本版 19 | 20 | - 連結 21 | - 安裝 gem 22 | - [rspec-rails](https://github.com/rspec/rspec-rails) 23 | - [factory-bot-rails](https://github.com/thoughtbot/factory_bot_rails) 24 | - [faker](https://github.com/faker-ruby/faker) 25 | - [hirb-unicode](https://rubygems.org/gems/hirb-unicode) 26 | - [foreman](https://github.com/ddollar/foreman) 27 | 28 | - 建立 29 | - `PagesController` 及 `index.html.erb` 30 | - 設定首頁到 `pages#index` 31 | 32 | ### `tailwind` 版 33 | 34 | - 連結 35 | - 安裝 Gem 36 | - 同 `basic` 基本版 37 | - 安裝 [Tailwind CSS](https://tailwindcss.com) 38 | - 安裝 [Purgecss](https://www.purgecss.com/) 移除不必要的 CSS 定義 39 | - 把 `app/javascript` 目錄換成 `app/frontend` 40 | 41 | by eddie@5xruby.tw 42 | 43 | -------------------------------------------------------------------------------- /app/javascript/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaochenlong/rails-template/bbf7ae14c6a72c0fd517b71737f1bcf8df943702/app/javascript/images/.keep -------------------------------------------------------------------------------- /app/javascript/scripts/application.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaochenlong/rails-template/bbf7ae14c6a72c0fd517b71737f1bcf8df943702/app/javascript/scripts/application.js -------------------------------------------------------------------------------- /app/javascript/scripts/index.js: -------------------------------------------------------------------------------- 1 | import './application' 2 | 3 | -------------------------------------------------------------------------------- /app/javascript/styles/application.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaochenlong/rails-template/bbf7ae14c6a72c0fd517b71737f1bcf8df943702/app/javascript/styles/application.scss -------------------------------------------------------------------------------- /app/javascript/styles/index.js: -------------------------------------------------------------------------------- 1 | import "tailwindcss/base"; 2 | import "tailwindcss/components"; 3 | import "./application"; 4 | import "tailwindcss/utilities"; 5 | 6 | -------------------------------------------------------------------------------- /app/views/pages/home.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

Hello, Yu :)

3 |
4 | 5 | -------------------------------------------------------------------------------- /basic.rb: -------------------------------------------------------------------------------- 1 | require 'fileutils' 2 | require "tmpdir" 3 | 4 | SOURCE_REPO = "https://github.com/kaochenlong/rails-template.git" 5 | 6 | def set_source_path 7 | if __FILE__ =~ %r{\Ahttps?://} 8 | tempdir = Dir.mktmpdir("rails-template-") 9 | source_paths.unshift(tempdir) 10 | at_exit { remove_dir(tempdir) } 11 | git clone: "--quiet #{SOURCE_REPO} #{tempdir}" 12 | else 13 | source_paths.unshift(File.dirname(__FILE__)) 14 | end 15 | end 16 | 17 | def copy_procfile 18 | copy_file 'Procfile.dev' 19 | copy_file '.foreman' 20 | end 21 | 22 | set_source_path 23 | 24 | gem_group :development, :test do 25 | gem 'foreman', '~> 0.87.1' 26 | gem 'hirb-unicode', '~> 0.0.5' 27 | gem 'rspec-rails', '~> 4.0' 28 | gem 'factory_bot_rails', '~> 5.1', '>= 5.1.1' 29 | gem 'faker', '~> 2.11' 30 | gem 'pry-rails', '~> 0.3.9' 31 | end 32 | 33 | after_bundle do 34 | application do <<-RUBY 35 | config.generators do |g| 36 | g.assets false 37 | g.helper false 38 | end 39 | RUBY 40 | end 41 | 42 | copy_procfile 43 | 44 | route "root 'pages#home'" 45 | 46 | run "spring stop" 47 | 48 | generate :controller, "pages" 49 | 50 | copy_file 'app/views/pages/home.html.erb' 51 | 52 | generate "rspec:install" 53 | remove_dir "test" 54 | 55 | git :init 56 | git add: '.' 57 | git commit: "-a -m 'Initial commit'" 58 | end 59 | 60 | puts "Everything seems good, Awesome!" 61 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | let environment = { 2 | plugins: [ 3 | require('postcss-import'), 4 | require('tailwindcss'), 5 | require('autoprefixer'), 6 | require('postcss-flexbugs-fixes'), 7 | require('postcss-preset-env')({ 8 | autoprefixer: { 9 | flexbox: 'no-2009' 10 | }, 11 | stage: 3 12 | }) 13 | ] 14 | } 15 | 16 | if (process.env.RAILS_ENV === "production") { 17 | environment.plugins.push( 18 | require('@fullhuman/postcss-purgecss')({ 19 | content: [ 20 | './app/**/*.html.erb', 21 | './app/**/*.html.slim', 22 | './app/**/*.html.haml', 23 | './app/**/*.rb', 24 | './app/**/*.js', 25 | './app/**/*.vue', 26 | './app/**/*.jsx', 27 | './app/**/*.scss' 28 | ], 29 | defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || [] 30 | }) 31 | ) 32 | } 33 | 34 | module.exports = environment 35 | -------------------------------------------------------------------------------- /tailwind.rb: -------------------------------------------------------------------------------- 1 | require "fileutils" 2 | require "tmpdir" 3 | 4 | SOURCE_REPO = "https://github.com/kaochenlong/rails-template.git" 5 | 6 | def set_source_path 7 | if __FILE__ =~ %r{\Ahttps?://} 8 | tempdir = Dir.mktmpdir("rails-template-") 9 | source_paths.unshift(tempdir) 10 | at_exit { remove_dir(tempdir) } 11 | git clone: "--quiet #{SOURCE_REPO} #{tempdir}" 12 | else 13 | source_paths.unshift(File.dirname(__FILE__)) 14 | end 15 | end 16 | 17 | def copy_procfile 18 | copy_file "Procfile.dev" 19 | copy_file ".foreman" 20 | end 21 | 22 | set_source_path 23 | 24 | gem_group :development, :test do 25 | gem 'foreman', '~> 0.87.1' 26 | gem 'hirb-unicode', '~> 0.0.5' 27 | gem 'rspec-rails', '~> 4.0' 28 | gem 'factory_bot_rails', '~> 5.1', '>= 5.1.1' 29 | gem 'faker', '~> 2.11' 30 | gem 'pry-rails', '~> 0.3.9' 31 | end 32 | 33 | after_bundle do 34 | application do <<-RUBY 35 | config.generators do |g| 36 | g.assets false 37 | g.helper false 38 | end 39 | RUBY 40 | end 41 | 42 | copy_procfile 43 | 44 | route "root 'pages#home'" 45 | 46 | run "spring stop" 47 | 48 | generate :controller, "pages" 49 | 50 | copy_file "app/views/pages/home.html.erb" 51 | 52 | generate "rspec:install" 53 | 54 | remove_dir "test" 55 | 56 | # frontend packages 57 | run "yarn add tailwindcss@1.3.5" 58 | run "yarn add @fullhuman/postcss-purgecss" 59 | 60 | inject_into_file 'app/javascript/packs/application.js', after: "// const imagePath = (name) => images(name, true)" do 61 | "\n\nimport 'scripts'\nimport 'styles'\n" 62 | end 63 | 64 | # inject_into_file 'postcss.config.js', after: "require('postcss-import')," do 65 | # "\n require('tailwindcss'),\n require('autoprefixer')," 66 | # end 67 | 68 | copy_file "postcss.config.js", force: true 69 | 70 | copy_file "app/javascript/scripts/index.js" 71 | copy_file "app/javascript/scripts/application.js" 72 | copy_file "app/javascript/styles/index.js" 73 | copy_file "app/javascript/styles/application.scss" 74 | 75 | # images 76 | gsub_file "app/javascript/packs/application.js", "// const images", "const images" 77 | gsub_file "app/javascript/packs/application.js", "// const imagePath", "const imagePath" 78 | copy_file "app/javascript/images/.keep" 79 | 80 | # rename app/javascript folder to app/frontend 81 | gsub_file "config/webpacker.yml", /source_path\: app\/javascript/, "source_path: app\/frontend" 82 | run "mv app/javascript app/frontend" 83 | 84 | git :init 85 | git add: '.' 86 | git commit: "-a -m 'Initial commit'" 87 | 88 | puts "Everything seems LGTM, Awesome!" 89 | end 90 | 91 | --------------------------------------------------------------------------------