Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails project template
# rails new . -d mysql --skip-test-unit
# rails new . --skip-active-record --skip-test-unit
# Edit Gemfile
if yes?('Replace gem source "https://rubygems.org/" with Taobao mirror "https://ruby.taobao.org/"?(y/n)')
gsub_file 'Gemfile', 'rubygems.org', 'ruby.taobao.org'
end
use_mongodb = yes?('Use MongoDB?(y/n)')
gem 'jquery-turbolinks'
gem 'rails-i18n', github: 'svenfuchs/rails-i18n'
gem "mongoid", "~> 4.0.0" if use_mongodb
gem_group :development do
gem 'quiet_assets'
gem 'spring-commands-rspec'
gem 'capistrano', '~> 3.4.0'
end
gem_group :development, :test do
gem 'pry-rails'
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
end
gem_group :test do
if use_mongodb
gem 'database_cleaner'
gem 'mongoid-rspec', '~> 2.1.0'
else
gem 'shoulda-matchers', require: false
end
end
after_bundle do
# Set time zone
gsub_file 'config/application.rb', /config\.time_zone\s+=\s+.+/, "config.time_zone = 'Beijing'"
uncomment_lines 'config/application.rb', /config\.time_zone/
# Set i18n load_path
gsub_file 'config/application.rb', /config\.i18n\.load_path\s+\+=\s+.+/, "config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]"
uncomment_lines 'config/application.rb', /config\.i18n\.load_path/
# Set default locale
gsub_file 'config/application.rb', /config\.i18n\.default_locale\s+=\s+.+/, "config.i18n.default_locale = :'zh-CN'"
uncomment_lines 'config/application.rb', /config\.i18n\.default_locale/
# Spring binstub
run 'bin/spring binstub --all'
# Install Rspec
generate "rspec:install"
uncomment_lines 'spec/rails_helper.rb', /Dir\[Rails\.root\.join\('spec\/support\/\*\*\/\*\.rb'\)\]/
gsub_file 'spec/spec_helper.rb', '=begin', ''
gsub_file 'spec/spec_helper.rb', /\s+=end/, ''
# Config FactoryGirl
empty_directory 'spec/support'
create_file 'spec/support/factory_girl.rb' do
"RSpec.configure do |config|\n" +
" config.include FactoryGirl::Syntax::Methods\n" +
"end"
end
if use_mongodb
# Install and config Mongoid
generate "mongoid:config"
[
/require\s+['"]rails['"]/,
/require\s+['"]active_model\/railtie['"]/,
].each do |line|
comment_lines 'config/application.rb', line
end
%w(development production test).each do |enviroment|
comment_lines "config/environments/#{enviroment}.rb", /config\.active_record/
end
# Config DatebaseCleaner
create_file 'spec/support/database_cleaner.rb' do
"RSpec.configure do |config|\n" +
" config.before(:suite) do\n" +
" DatabaseCleaner.strategy = :truncation\n" +
" end\n" +
"\n" +
" config.around(:each) do |example|\n" +
" DatabaseCleaner.cleaning do\n"+
" example.run\n"+
" end\n" +
" end\n" +
"end"
end
create_file 'spec/support/mongoid.rb' do
"RSpec.configure do |config|\n" +
" config.include Mongoid::Matchers, type: :model\n" +
"end"
end
else
insert_into_file 'spec/rails_helper.rb', after: /Add additional requires below this line. Rails is not loaded until this point!\s+/ do
"require 'shoulda/matchers'\n"
end
end
# Config Capistrano
run "cap install"
# First commit after bundle
git :init
git add: "."
git commit: %Q{ -m 'Initial commit' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment