Created
May 8, 2011 16:11
-
-
Save gfrivolt/961466 to your computer and use it in GitHub Desktop.
New Rails project 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
# create rvmrc file | |
rvm_gemset_creation = "rvm use 1.9.2@#{app_name} --create" | |
run rvm_gemset_creation | |
create_file ".rvmrc", rvm_gemset_creation | |
# cleanup | |
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore" | |
run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore} | |
run "rm .gitignore" | |
file '.gitignore', <<-FILE | |
.DS_Store | |
.rvmrc | |
.rspec | |
*.swp | |
rdoc | |
coverage | |
log/*.log | |
tmp/**/* | |
config/database.yml | |
db/*.sqlite3 | |
vendor/rails | |
vendor/gems/* | |
vendor/cache | |
public/uploads/* | |
Sporkfile.rb | |
FILE | |
run "rm README" | |
run "rm public/index.html" | |
run "rm public/images/rails.png" | |
run "rm public/favicon.ico" | |
# create rvmrc file | |
rvm_gemset_creation = "rvm use 1.9.2@#{app_name} --create" | |
run rvm_gemset_creation | |
create_file ".rvmrc", rvm_gemset_creation | |
# gems | |
gem 'haml', '>= 3.0.25' | |
gem 'haml-rails', '>= 0.3.4' | |
gem 'jquery-rails', '>= 0.2.7' | |
gem 'compass', '>= 0.10.6' | |
gem 'kaminari' | |
gem 'simple_form' | |
gem 'sqlite3-ruby', :require => 'sqlite3', :groups => ['test', 'development'] | |
gem 'rspec' | |
gem 'rspec-rails', '= 2.5.0', :groups => [:test] | |
gem 'database_cleaner', '~> 0.5.2', :groups => [:test] | |
gem 'factory_girl_rails', :groups => [:test] | |
gem 'factory_girl', '= 1.3.3', :groups => [:test] | |
gem 'ffaker', :groups => [:test] | |
gem 'capybara', :groups => [:test] | |
gem 'launchy', :groups => [:test] | |
gem 'ruby-debug19', :groups => [:test] | |
gem 'cucumber', :groups => [:test] | |
gem 'cucumber-rails', :groups => [:test] | |
gem 'pickle', :groups => [:test] | |
gem 'spork', :groups => [:test] | |
#continuous testing | |
gem 'guard', :groups => [:test] | |
gem 'growl', :groups => [:test] | |
gem 'rb-fsevent', :groups => [:test] | |
gem 'guard-rspec', :groups => [:test] | |
gem 'guard-cucumber', :groups => [:test] | |
gem 'guard-spork', :groups => [:test] | |
gem 'guard-ego', :groups => [:test] | |
gem 'guard-bundler', :groups => [:test] | |
gem 'guard-livereload', :groups => [:test] | |
gem 'guard-compass', :groups => [:test] | |
# Run generators/installers | |
run 'bundle install' | |
generate 'rspec:install' | |
run 'rm -r test' | |
generate 'cucumber:install --rspec --capybara --spork' | |
generate 'pickle --paths --email' | |
run 'spork --bootstrap' | |
generate 'kaminari:views default' | |
generate 'jquery:install --ui' | |
generate 'simple_form:install' | |
run 'guard init' | |
run 'guard init rspec' | |
run 'guard init spork' | |
run 'guard init ego' | |
run 'guard init bundler' | |
run 'guard init cucumber' | |
run 'guard init livereload' | |
run 'guard init compass' | |
# compass | |
compass_sass_dir = "app/stylesheets" | |
compass_css_dir = "public/stylesheets/compiled" | |
compass_command = "compass init rails . --using blueprint/semantic --css-dir=#{compass_css_dir} --sass-dir=#{compass_sass_dir}" | |
run compass_command | |
inject_into_file 'config/application.rb', :after => "config.filter_parameters += [:password]" do | |
<<-CONFIG | |
# Customize generators | |
config.generators do |g| | |
g.stylesheets false | |
g.form_builder :simple_form | |
g.fixture_replacement :factory_girl, :dir => 'spec/factories' | |
end | |
CONFIG | |
end | |
# rspec config | |
run "echo '--format documentation' >> .rspec" | |
run "touch spec/Sporkfile.rb" | |
file 'spec/spec_helper.rb', <<-RSPEC_HELPER | |
require 'rubygems' | |
require 'spork' | |
ENV["RAILS_ENV"] = 'test' | |
Spork.prefork do | |
require File.expand_path("../../config/environment", __FILE__) | |
require 'rspec/rails' | |
if Spork.using_spork? | |
ActiveSupport::Dependencies.clear | |
ActiveRecord::Base.instantiate_observers | |
end | |
RSpec.configure do |c| | |
c.mock_with :rspec | |
end | |
end | |
Spork.each_run do | |
Dir["\#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| load f} | |
Factory.factories.clear | |
Dir["\#{File.dirname(__FILE__)}/factories/**/*.rb"].each{|f| load f} | |
Rails.application.reload_routes! | |
sporkfile = File.expand_path('../Sporkfile.rb', __FILE__) | |
load sporkfile if File.exists?(sporkfile) | |
end | |
RSPEC_HELPER | |
# continuous testing with guard | |
file 'Guardfile', <<-GUARDFILE | |
guard 'ego' do | |
watch('Guardfile') | |
end | |
guard 'bundler' do | |
watch('Gemfile') | |
watch(/^.+\\\\.gemspec/) | |
end | |
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'cucumber' }, :rspec_env => { 'RAILS_ENV' => 'test' } do | |
watch('config/application.rb') | |
watch('config/environment.rb') | |
watch(%r{^config/environments/.+\.rb$}) | |
watch(%r{^config/initializers/.+\.rb$}) | |
watch('spec/spec_helper.rb') | |
end | |
guard 'rspec', :cli => '--color --format doc --drb', :version => 2 do | |
watch('spec/spec_helper.rb') { "spec" } | |
watch('config/routes.rb') { "spec/routing" } | |
watch(%r{^spec/.+_spec\.rb}) | |
watch(%r{^app/(.+)\.rb}) { |m| "spec/\#{m[1]}_spec.rb" } | |
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/\#{m[1]}_spec.rb" } | |
watch(%r{^app/controllers/(.+)_(controller|decorator)\.rb}) do |m| | |
["spec/routing/\#{m[1]}_routing_spec.rb", "spec/\#{m[2]}s/\#{m[1]}_\#{m[2]}_spec.rb", "spec/acceptance/\#{m[1]}_spec.rb"] | |
end | |
end | |
guard 'cucumber', :cli => '--format pretty --drb' do | |
watch(%r{features/.+\.feature}) | |
watch(%r{features/support/.+}) { 'features' } | |
watch(%r{features/step_definitions/(.+)_steps\.rb}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' } | |
end | |
guard 'livereload' do | |
watch(%r{app/.+\.(erb|haml)}) | |
watch(%r{app/helpers/.+\.rb}) | |
watch(%r{public/.+\.(css|js|html)}) | |
watch(%r{config/locales/.+\.yml}) | |
end | |
guard 'compass' do | |
watch('^src/(.*)\.s[ac]ss') | |
end | |
GUARDFILE | |
# setup haml | |
remove_file 'app/views/layouts/application.html.erb' | |
create_file 'app/views/layouts/application.html.haml', <<EOF | |
!!! 5 | |
%head | |
%html | |
= csrf_meta_tag | |
= stylesheet_link_tag 'compiled/screen.css', :media => 'screen, projection' | |
= stylesheet_link_tag 'compiled/print.css', :media => 'print' | |
/[if lt IE 8] | |
= stylesheet_link_tag 'compiled/ie.css', :media => 'screen, projection' | |
%body | |
= yield | |
= javascript_include_tag :defaults | |
EOF | |
initializer 'haml.rb',<<EOF | |
Haml::Template.options[:format] = :html5 | |
EOF | |
rake "db:create", :env => 'development' | |
rake "db:create", :env => 'test' | |
# heroku | |
run "heroku create #{app_name}" if yes?("Create heroku app '#{app_name}'?") | |
# commit changes to git | |
git :init | |
git :add => '.' | |
git :commit => '-a -m "rails app configured with template"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment