Skip to content

Instantly share code, notes, and snippets.

@cblunt
Last active July 18, 2016 04:21
Show Gist options
  • Save cblunt/1042832 to your computer and use it in GitHub Desktop.
Save cblunt/1042832 to your computer and use it in GitHub Desktop.
Rails 4 App Template
# Creates a new Rails 4 application configured with
# Slim, PostgreSQL, TestUnit (minitest), FactoryGirl, SimpleCov, Capybara, Capistrano ...
#
# Based on template generated at http://railswizard.org/
# USAGE
# $ rails new APP_NAME -JTm rails_app_template.rb
# Will be specified by default Gemfile
# gem 'rails', '4.2.0'
# Use postgresql as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
gem 'slim-rails'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use Unicorn as the app server
gem 'unicorn'
# Simple form for forms!
gem 'simple_form', '~> 3.1.0'
# Bourbon and Neat SASS framework
gem 'bourbon'
gem 'neat'
gem 'factory_girl', group: [:development, :test]
gem 'minitest-rails'
gem 'minitest-rails-capybara', group: :test
gem 'minitest-rg', group: :test
gem 'minitest-documentation', group: :test
gem 'simplecov', group: :test, require: false
gem 'capistrano', require: false
gem 'capistrano-maintenance', require: false
gem 'capistrano-rbenv', require: false
gem 'capistrano-bundler', require: false
gem 'capistrano-rails', require: false
gem 'capistrano-pending', require: false
def say_recipe(name); say "\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
def say_wizard(text); say "\033[36m" + "wizard".rjust(10) + "\033[0m" + " #{text}" end
# >-----------------------------[ Custom Code ]-------------------------------<
remove_file '.gitignore'
file '.gitignore', <<-CODE.gsub(/^ {2}/, '')
.DS_Store
.bundle
.sass-cache
.env
coverage
coverage/
coverage/**/*
db/*.sqlite3
log
mkmf.log
public/stylesheets/compiled/*
public/system/*
public/uploads
rdoc
tmp
uploads
CODE
# >-----------------------------[ Run Bundler ]-------------------------------<
say_wizard "Running Bundler install. This will take a while."
run 'bundle --local'
git :init
git add: '.'
git commit: "-aqm 'Initial commit'"
# >-----------------------------[ Install SimpleCov ]-------------------------------<
say_wizard "Installing SimpleCov..."
inject_into_file 'test/test_helper.rb', before: "ENV['RAILS_ENV'] ||= 'test'" do
<<-RUBY
require 'simplecov'
SimpleCov.start
RUBY
end
inject_into_file 'test/test_helper.rb', after: "require 'rails/test_help'" do
<<-RUBY
require "minitest/rails/capybara"
RUBY
end
git add: '.'
git commit: "-aqm 'Added SimpleCov and capybara'"
rakefile 'test_features.rake' do
<<-RAKE
Rails::TestTask.new("test:features" => "test:prepare") do |t|
t.pattern = "test/features/**/*_test.rb"
end
Rake::Task["test:run"].enhance ["test:features"]
RAKE
end
# >-----------------------------[ Application Config ]-------------------------------<
say_wizard 'Adding password_confirmation to filter parameters...'
gsub_file 'config/application.rb', /:password\]/, ':password, :password_confirmation]'
say_wizard 'Adding app/extras/ to autoload_paths...'
gsub_file 'config/application.rb', /# config.autoload_paths/, 'config.autoload_paths'
git add: '.'
git commit: "-aqm 'Updated application config'"
# >-----------------------------[ Cleanup ]-------------------------------<
say_wizard "Creating slim layout..."
layout = <<-SLIM
doctype html
html
head
title #{app_name.humanize}
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tag
body
= yield
SLIM
remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.slim", layout
create_file "log/.gitkeep"
create_file "tmp/.gitkeep"
# >-----------------------------[ Install SimpleForm ]-------------------------------<
generate :"simple_form:install"
# >-----------------------------[ Cleanup ]-------------------------------<
say_wizard "Cleaning up repository..."
remove_file "README"
# remove public files
inside "public" do
remove_file "favicon.ico"
remove_file "robots.txt"
end
git add: '.'
git commit: "-aqm 'Removed unnecessary files left over from initial app generation.'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment