-
-
Save matt-morris/b6246fa17960f530c1bd to your computer and use it in GitHub Desktop.
Rails application template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails 4 Application Template | |
# Usage: rails new [app_name] -m [boost_template.rb] -d postgresql | |
# Remove normal files we don't want | |
remove_file "README.rdoc" | |
remove_file "public/index.html" | |
remove_file "app/assets/images/rails.png" | |
# Copy database.yml to sample | |
inside "config" do | |
run "cp database.yml database.yml.sample" | |
end | |
# Write our config/database.yml | |
if options[:database].to_s == "postgresql" | |
remove_file "config/database.yml" | |
create_file "config/database.yml", <<-EOF | |
# PostgreSQL. Versions 7.4 and 8.x are supported. | |
# | |
# Install the pg driver: | |
# gem install pg | |
# On Mac OS X with macports: | |
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config | |
# On Windows: | |
# gem install pg | |
# Choose the win32 build. | |
# Install PostgreSQL and put its /bin directory on your path. | |
# | |
# Configure Using Gemfile | |
# gem 'pg' | |
# | |
login: &login | |
adapter: postgresql | |
encoding: unicode | |
username: #{ENV['DB_USER']} | |
timeout: 5000 | |
pool: 5 | |
development: | |
<<: *login | |
database: #{app_name}_development | |
min_messages: warning | |
# Warning: The database defined as "test" will be erased and | |
# re-generated from your development database when you run "rake". | |
# Do not set this db to the same as development or production. | |
test: | |
<<: *login | |
database: #{app_name}_test | |
min_messages: warning | |
production: | |
<<: *login | |
database: #{app_name}_production | |
EOF | |
end | |
# Disable generation of helpers, javascripts, css, and view specs | |
insert_into_file "config/application.rb", :after => "class Application < Rails::Application\n" do | |
<<-EOF | |
# Disable generation of helpers, javascripts, css, and view specs | |
config.generators do |generate| | |
generate.helper false | |
generate.assets false | |
generate.view_specs false | |
generate.factory_girl false | |
end | |
EOF | |
end | |
# Configure development action mailer | |
insert_into_file "config/environments/development.rb", :after => "config.action_mailer.raise_delivery_errors = false\n" do | |
<<-EOF | |
config.action_mailer.delivery_method = :letter_opener | |
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } | |
EOF | |
end | |
# Configure our .gitignore file | |
insert_into_file ".gitignore", "/vendor/bundle\n", after: "/.bundle\n" | |
insert_into_file ".gitignore", "/db/*.sql\n/db/*.xml\n", after: "/db/*.sqlite3\n" | |
insert_into_file ".gitignore", "/log/*.log.*\n", after: "/log/*.log\n" | |
insert_into_file ".gitignore", "/doc/*\n/.sass-cache\n", after: "/tmp\n" | |
append_to_file ".gitignore", <<-EOF | |
# Local Ignores | |
/config/database.yml | |
.env | |
EOF | |
# Configure our Gemfile | |
append_to_file "Gemfile", <<-EOF | |
gem 'dotenv-rails', group: [:test, :development] | |
gem 'configatron' | |
gem 'activeadmin', github: "gregbell/active_admin" | |
gem 'kaminari' | |
gem 'draper', '~> 1.3' | |
gem 'countries' | |
gem 'country_select' | |
gem 'devise' | |
# Asset related gems | |
gem 'slim-rails' | |
gem 'bootstrap-sass' | |
gem 'autoprefixer-rails' | |
gem 'rollbar' | |
EOF | |
gem_group :development do | |
gem "capistrano" | |
gem "rails-erd" | |
gem "pry-rails" | |
gem 'pry-debugger' | |
gem 'pry-rescue' | |
gem 'pry-stack_explorer' | |
gem "better_errors", platforms: [:ruby_19, :ruby_20, :rbx] | |
gem "binding_of_caller", platforms: [:ruby_19, :ruby_20, :rbx] | |
gem "meta_request" | |
gem 'letter_opener' | |
gem 'quiet_assets' | |
gem 'thin' | |
end | |
gem_group :test, :development do | |
gem 'rspec-rails' | |
gem 'capybara' | |
gem 'factory_girl_rails' | |
end | |
gem_group :test do | |
gem 'shoulda' | |
gem 'database_cleaner' | |
gem 'ffaker', require: false | |
gem 'selenium-webdriver' | |
end | |
gem_group :production do | |
gem 'newrelic_rpm' | |
end | |
# Clean the Gemfile | |
gsub_file "Gemfile", <<-EOF, "" | |
# Use ActiveModel has_secure_password | |
# gem 'bcrypt-ruby', '~> 3.0.0' | |
# Use unicorn as the app server | |
# gem 'unicorn' | |
# Use Capistrano for deployment | |
# gem 'capistrano', group: :development | |
# Use debugger | |
# gem 'debugger', group: [:development, :test] | |
EOF | |
gsub_file "Gemfile", /\"/, "'" | |
run "bundle install" | |
# Run gem generators / create files | |
create_file ".env" | |
run "rails generate configatron:install" | |
run "rails generate active_admin:install" | |
run "rails g kaminari:config" | |
run "rails generate rspec:install" | |
run "rails generate devise User" | |
run "rake db:create:all" | |
# Setup asset javascripts and stylesheets | |
inside "app/assets/stylesheets" do | |
run "mv application.css application.css.scss" | |
end | |
gsub_file 'app/assets/stylesheets/application.css.scss', /\*= require_tree .\n/, "" | |
append_to_file "app/assets/stylesheets/application.css.scss", <<-EOF | |
@import "bootstrap-sprockets"; | |
@import "bootstrap"; | |
EOF | |
gsub_file 'app/assets/javascripts/application.js', /\/\/= require_tree .\n/, "" | |
insert_into_file "app/assets/javascripts/application.js", :after => "//= require jquery\n" do | |
<<-EOF | |
//= require bootstrap-sprockets | |
EOF | |
end | |
# Setup testing | |
insert_into_file "spec/spec_helper.rb", :after => "require 'rspec/autorun'\n" do | |
<<-EOF | |
require 'capybara/rspec' | |
require 'capybara/rails' | |
EOF | |
end | |
insert_into_file "spec/rails_helper.rb", :after => "RSpec.configure do |config|\n" do | |
<<-EOF | |
config.render_views | |
config.include FactoryGirl::Syntax::Methods | |
config.include Devise::TestHelpers, :type => :controller | |
EOF | |
end | |
create_file "spec/support/database_cleaner.rb", <<-EOF | |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.strategy = :transaction | |
end | |
config.before(:each, :js => true) do | |
DatabaseCleaner.strategy = :truncation | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end | |
EOF | |
# Remove warnings when running Rspec | |
gsub_file('.rspec', /--warnings/, '') | |
git :init | |
git add: "." | |
git commit: "-m 'Initial commit of rails application'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment