Last active
October 4, 2017 18:24
-
-
Save fijimunkii/7603564 to your computer and use it in GitHub Desktop.
rails: 3.2.14 generator
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
# README | |
# pass in this file when creating a rails project | |
# | |
# for example: | |
# rails _3.2.14_ new awesome_app -T -d postgresql -m ~/.kickhash_template.rb | |
remove_file "README.rdoc" | |
create_file "README.md", "TODO" | |
gem_group :development, :test do | |
gem 'rspec-rails' | |
gem 'guard-rspec' | |
gem 'cucumber-rails', :require => false | |
gem 'guard-cucumber', :require => false | |
gem 'coveralls', :require => false | |
gem 'capybara' | |
gem 'database_cleaner' | |
gem 'capybara-webkit' | |
gem 'selenium-webdriver' | |
gem 'jasmine' | |
gem 'pry-rails' | |
end | |
gem_group :development do | |
gem 'annotate' | |
gem 'quiet_assets' | |
gem 'binding_of_caller' | |
gem 'meta_request' | |
gem 'rails-erd' | |
gem 'better_errors' | |
gem 'terminal-notifier-guard' | |
gem 'awesome_print' | |
gem 'coffee-rails-source-maps' | |
end | |
gem 'simplecov', :require => false, :group => :test | |
gem 'thin' if yes? "Do you want to use Thin?" | |
gem 'haml-rails' if yes? "Do you want to use Haml" | |
# Rspec | |
run "bundle --quiet" | |
generate "rspec:install --quiet" | |
generate "cucumber:install --quiet" | |
generate "jasmine:install --quiet" | |
run "bundle exec guard init" | |
# Removing test directory | |
run "rm -rf test" | |
insert_into_file 'config/application.rb', :after => "require 'rails/all'\n" do | |
"if Rails.env.test? | |
require 'simplecov' | |
SimpleCov.start | |
end" | |
end | |
create_file ".coveralls.yml" | |
append_to_file ".coveralls.yml" do <<-COVERALLS_CONFIG | |
service_name: travis-ci | |
COVERALLS_CONFIG | |
end | |
prepend_to_file 'spec/spec_helper.rb' do <<-COVERALLS_CONFIG | |
require 'coveralls' | |
Coverall.wear_merged! | |
COVERALLS_CONFIG | |
end | |
insert_into_file 'spec/spec_helper.rb', :after => "require 'rspec/autorun'\n" do | |
"require 'capybara/rails'" | |
end | |
create_file "spec/support/database_cleaner.rb" | |
append_to_file "spec/support/database_cleaner.rb" do <<-DATABASE_CLEANER_CONFIG | |
Capybara.javascript_driver = :webkit # Selenium works, but not as well | |
RSpec.configure do |config| | |
config.use_transactional_fixtures = false | |
# Use transactions by default | |
config.before :each do | |
DatabaseCleaner.strategy = :truncation | |
end | |
# Switch to truncation for javascript tests, but *only clean used tables* | |
config.before :each, :js => true do | |
DatabaseCleaner.strategy = :truncation, {:pre_count => true} | |
end | |
config.before :each do | |
DatabaseCleaner.start | |
end | |
config.after :each do | |
DatabaseCleaner.clean | |
end | |
end | |
DATABASE_CLEANER_CONFIG | |
end | |
remove_file "config/database.yml" | |
create_file "config/database.yml" do <<-DATABASE_YML | |
development: | |
adapter: postgresql | |
encoding: unicode | |
database: <%= File.basename(Rails.root) %>_development | |
pool: 5 | |
host: localhost | |
username: <%= ENV['PG_USERNAME'] %> | |
password: | |
test: | |
adapter: postgresql | |
encoding: unicode | |
database: <%= File.basename(Rails.root) %>_test | |
pool: 5 | |
host: localhost | |
username: <%= ENV['PG_USERNAME'] %> | |
password: | |
DATABASE_YML | |
end | |
create_file ".travis.yml" do <<-TRAVIS | |
language: ruby | |
rvm: | |
- 1.9.3 | |
before_script: | |
- "sh -e /etc/init.d/xvfb start" | |
- "export DISPLAY=:99.0" | |
- "export JASMINE_SPEC_FORMAT=documentation" | |
script: | |
- "bundle exec rake travis:run" | |
env: | |
- PG_USERNAME='postgres' | |
TRAVIS | |
end | |
if yes? "Do you want a welcome controller?" | |
generate :controller, "welcome index --no-helper --no-assets --no-controller-specs --no-view-specs" | |
route "root to: 'welcome#index'" | |
remove_file "public/index.html" | |
end | |
# Remove requires trees | |
gsub_file "app/assets/javascripts/application.js", /^\/\/= require_tree .$/, "" | |
gsub_file "app/assets/stylesheets/application.css", /^*= require_tree .$/, "" | |
if yes? "Install Backbone?" | |
{ | |
json2: "https://rawgithub.com/douglascrockford/JSON-js/master/json2.js", | |
handlebars: "http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-latest.js", | |
underscore: "https://rawgithub.com/jashkenas/underscore/master/underscore.js", | |
backbone: "https://rawgithub.com/jashkenas/backbone/master/backbone.js" | |
} | |
.each do |file_name, source| | |
get source, "vendor/assets/javascripts/#{file_name}.js" | |
append_to_file "app/assets/javascripts/application.js", "//= require #{file_name}\n" | |
end | |
gem "handlebars_assets", :group => :assets | |
run "bundle --quiet" | |
append_to_file "app/assets/javascripts/application.js", "//\n//= require setup\n//= require routes\n//= require_tree ./templates\n//= require_tree ./models\n//= require_tree ./collections\n//= require_tree ./views\n//\n//= require app" | |
empty_directory "app/assets/javascripts/templates/" | |
empty_directory "app/assets/javascripts/models/" | |
empty_directory "app/assets/javascripts/collections/" | |
empty_directory "app/assets/javascripts/views/" | |
create_file "app/assets/javascripts/templates/.gitkeep" | |
create_file "app/assets/javascripts/models/.gitkeep" | |
create_file "app/assets/javascripts/collections/.gitkeep" | |
create_file "app/assets/javascripts/views/.gitkeep" | |
create_file "app/assets/javascripts/routes.js" do <<-ROUTES | |
App.Router = Backbone.Router.extend({ | |
routes: { | |
"" : "index" | |
}, | |
initialize: function(){ | |
Backbone.history.start(); | |
}, | |
index: function(){ | |
console.log('index'); | |
} | |
}); | |
ROUTES | |
end | |
create_file "app/assets/javascripts/app.js" do <<-APP | |
$(document).ready(function(){ | |
App.router = new App.Router(); | |
}); | |
APP | |
end | |
create_file "app/assets/javascripts/setup.js" do <<-SETUP | |
// Include CSRF Token with every ajax request | |
$(document).ajaxSend(function (e, xhr, options) { | |
var token = $("meta[name='csrf-token']").attr("content"); | |
xhr.setRequestHeader("X-CSRF-Token", token); | |
}); | |
// Backbone Namespacing | |
window.App = { | |
Models : {}, | |
Collections : {}, | |
Views : {} | |
}; | |
SETUP | |
end | |
end | |
if yes? "Install Devise?" | |
if yes? "Are you sure?" | |
gem "devise" | |
run "bundle --quiet" | |
generate "devise:install --quiet" | |
model_name = ask "What would you like the user model to be called? [user]" | |
model_name = "user" if model_name.blank? | |
generate "devise --quiet", model_name | |
end | |
end | |
["rake db:create", "rake db:migrate", "RAILS_ENV=test rake db:migrate"].each do |cmd| | |
run cmd | |
end | |
if yes? "Apply heroku fix?" | |
insert_into_file 'config/application.rb', :after => "config.assets.enabled = true\n" do | |
" | |
# Fix for heroku | |
config.assets.initialize_on_precompile = false | |
" | |
end | |
comment_lines('config/environments/production.rb', /config.assets.compile/) | |
insert_into_file 'config/environments/production.rb', :after => "config.assets.compile = false\n" do | |
" | |
# Fix for heroku | |
config.assets.compile = true | |
" | |
end | |
end | |
if yes? "git init?" | |
git :init | |
git add: ".", commit: "-m 'new rails project'" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment