Skip to content

Instantly share code, notes, and snippets.

@reyesyang
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reyesyang/82d3147df67d17c38ef9 to your computer and use it in GitHub Desktop.
Save reyesyang/82d3147df67d17c38ef9 to your computer and use it in GitHub Desktop.
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