Last active
October 12, 2015 03:38
-
-
Save patricksrobertson/3965605 to your computer and use it in GitHub Desktop.
Temporary Rails template
This file contains hidden or 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
# ZOMG RAILS TEMPLATE | |
def replace_line(path, options = {}) | |
lines = File.open(path).readlines | |
lines.map! do |line| | |
if line.match(options[:match]) | |
line = "#{options[:with].rstrip}\n" | |
end | |
line | |
end | |
run "rm #{path}" | |
File.open(path, 'w+') { |file| file << lines.join } | |
end | |
def rvm(command) | |
run "zsh -l -c \"rvm #{command}\"" | |
end | |
file 'Gemfile', <<-GEMFILE, :force => true | |
source 'https://rubygems.org' | |
gem 'rails', '3.2.13' | |
gem 'thin' | |
gem 'pg' | |
gem 'haml-rails' | |
gem 'simple_form' | |
group :assets do | |
gem 'sass-rails', '~> 3.2.3' | |
gem 'coffee-rails', '~> 3.2.1' | |
gem 'uglifier', '>= 1.0.3' | |
end | |
group :development, :test do | |
gem 'rspec-rails' | |
end | |
group :test do | |
gem 'capybara' | |
gem 'poltergeist' | |
gem 'database_cleaner' | |
gem 'launchy' | |
gem 'timecop' | |
gem 'factory_girl_rails' | |
gem 'bourne' | |
gem 'headless' | |
end | |
GEMFILE | |
# Remove test directory | |
FileUtils.rm_rf('test') | |
# Database | |
file 'config/database.example.yml', <<-DATABASE, :force => true | |
development: | |
adapter: postgresql | |
database: #{app_name}_development | |
encoding: utf8 | |
min_messages: warning | |
test: | |
adapter: postgresql | |
database: #{app_name}_test | |
encoding: utf8 | |
min_messages: warning | |
DATABASE | |
run 'cp config/database.example.yml config/database.yml' | |
run 'bundle exec rake db:create db:migrate db:test:prepare' | |
# RSpec | |
generate('rspec:install') | |
file '.rspec', <<-RSPEC, force: true | |
--color | |
RSPEC | |
inside('spec') do | |
run 'mkdir support' | |
run 'mkdir config' | |
run 'mkdir -p acceptance/step_helpers' | |
FileUtils.touch('acceptance/step_helpers/.gitkeep') | |
insert_into_file 'spec_helper.rb', :before => %{Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}\n} do | |
"Dir[Rails.root.join('spec/config/**/*.rb')].each {|f| require f}\n" + | |
"Dir[Rails.root.join('spec/acceptance/step_helpers/**/*.rb')].each {|f| require f}\n" | |
end | |
replace_line('spec_helper.rb', :match => /config.use_transactional_fixtures = true/, :with => ' config.use_transactional_fixtures = false') | |
end | |
inside('spec/config') do | |
file 'rspec.rb', <<-FILE | |
RSpec.configure do |config| | |
config.treat_symbols_as_metadata_keys_with_true_values = true | |
end | |
FILE | |
file 'database_cleaner.rb', <<-FILE | |
require 'database_cleaner' | |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean | |
DatabaseCleaner.strategy = :deletion | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end | |
FILE | |
file 'timecop.rb', <<-FILE | |
require 'timecop' | |
RSpec.configure do |config| | |
config.before(:suite) do | |
Timecop.travel(DateTime.new(2012, 1, 1, 6, 30, 0, 0)) | |
end | |
config.after(:suite) do | |
Timecop.return | |
end | |
end | |
FILE | |
file 'capybara.rb', <<-FILE | |
require 'capybara/rspec' | |
FILE | |
file 'poltergeist.rb', <<-FILE | |
require 'capybara/poltergeist' | |
RSpec.configure do |config| | |
config.before(:suite) do | |
Capybara.javascript_driver = :poltergeist | |
end | |
end | |
FILE | |
file 'headless.rb', <<-FILE | |
require 'headless' | |
$headless = Headless.new | |
$headless.start | |
at_exit do | |
$headless.destroy | |
end | |
FILE | |
file 'bourne.rb', <<-FILE | |
RSpec.configure do |config| | |
config.mock_with :mocha | |
end | |
FILE | |
end | |
# Views | |
inside('app/views') do | |
run 'rm layouts/application.html.erb' | |
file 'layouts/application.html.haml', <<-VIEW | |
!!!5 | |
%html | |
%head | |
%title #{app_name.titleize} | |
= stylesheet_link_tag :application, :media => :all | |
= javascript_include_tag :application | |
= csrf_meta_tags | |
%link{:rel => 'author', :type => 'text/plain', :href => '/humans.txt'} | |
%meta{'http-equiv' => 'X-UA-Compatible', :content => 'chrome=1'} | |
= yield :head | |
%body | |
%section#main | |
= yield | |
VIEW | |
end | |
inside('config/initializers') do | |
file 'generators.rb', <<-GENERATORS | |
Rails.application.config.generators do |g| | |
g.test_framework :rspec, | |
view_specs: false, | |
fixture: false, | |
controller_specs: false, | |
routing_specs: false | |
g.integration_tool = :rspec | |
g.performance_tool = :rspec | |
g.fixture_replacement = :factory_girl | |
g.stylesheets = false | |
g.helper = false | |
g.assets = false | |
g.template_engine :haml | |
end | |
GENERATORS | |
end | |
file 'config/routes.rb', <<-ROUTES, :force => true | |
#{app_name.classify}::Application.routes.draw do | |
end | |
ROUTES | |
# Assets | |
inside('app/assets/stylesheets') do | |
run 'rm application.css' | |
file 'application.css.sass', <<-FILE | |
/* | |
* This is a manifest file that'll be compiled into application.css, which will include all the files | |
* listed below. | |
* | |
* Any CSS and SCSS file within this directory, lib/assets/stylesheets/application, vendor/assets/stylesheets/application, | |
* or vendor/assets/stylesheets/application of plugins, if any, can be referenced here using a relative path. | |
* | |
* You're free to add application-wide styles to this file and they'll appear at the top of the | |
* compiled file, but it's generally better to create a new file per style scope. | |
* | |
*= require_self | |
*= require_tree ./application | |
*/ | |
FILE | |
run 'mkdir application' | |
file 'application/index.css.sass', <<-FILE | |
/* | |
* Index for application.css.sass | |
*/ | |
FILE | |
end | |
inside('app/assets/javascripts') do | |
javascript = File.open('application.js').readlines | |
File.open('application.js.coffee', 'w+') { |f| f << javascript.map { |line| line.gsub(/^\/\//, '#') }.join } | |
run 'rm application.js' | |
end | |
# Initializers | |
generate('simple_form:install') | |
replace_line('config/initializers/simple_form.rb', :match => /config.label_text/, :with => " config.label_text = lambda { |label, required| label }") | |
run 'rm public/index.html' | |
run 'rm README.rdoc' | |
file 'public/humans.txt', <<-FILE | |
/* TEAM */ | |
This app was built by IoraHealth | |
Web: http://iorahealth.com | |
Twitter: @IoraEngineering | |
Email: [email protected] | |
Location: Cambridge, MA | |
/* SITE */ | |
Standards: HTML5, CSS3 | |
Components: Ruby on Rails | |
Software: OSX, Scientific Linux | |
Frameworks: Ruby on Rails, jQuery, Backbone | |
FILE | |
file 'README.md', <<-README | |
# #{app_name.titleize} # | |
## Getting set up ## | |
Install the app: | |
``` | |
bundle install | |
``` | |
Configure, create, migrate, and seed the database | |
``` | |
cp config/database.yml/example config/database.yml | |
mvim config/database.yml | |
bundle exec rake db:create db:migrate db:test:prepare | |
``` | |
README | |
# Git Ignore | |
file '.gitignore', <<-GITIGNORE, :force => true | |
.bundle | |
.DS_Store | |
.sass-cache/* | |
*.swp | |
*.swo | |
**/.DS_STORE | |
bin/* | |
binstubs/* | |
bundler_stubs/* | |
config/database.yml | |
coverage/* | |
db/*.sqlite3 | |
db/structure.sql | |
log/*.log | |
log/*.pid | |
public/system/* | |
public/stylesheets/compiled/* | |
public/assets/* | |
public/uploads/* | |
tmp/* | |
GITIGNORE | |
git :init | |
git add: '.' | |
git commit: "-a -m 'Initial Project commit.'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment