Skip to content

Instantly share code, notes, and snippets.

@colindensem
Created March 4, 2011 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colindensem/855719 to your computer and use it in GitHub Desktop.
Save colindensem/855719 to your computer and use it in GitHub Desktop.
template for r3
generators = []
puts 'Spinning up a new app'
devise = yes?('Use Devise? (yes/no)')
jquery = yes?('Use jQuery? (yes/no)')
jquery_ui = yes?('Use jQuery UI? (yes/no)') if jquery
haml = yes?('Use haml? (yes/no)')
rspec = yes?('Use Rspec? (yes/no)')
machinist = yes?('Use machinist? (yes/no)')
factory_girl = yes?('Use factorygirl? (yes/no)')
cucumber = yes?('Use Cucumber? (yes/no)')
capybara = yes?('Use Capybara? (yes/no)')
run 'rm public/index.html'
run 'rm public/images/rails.png'
run 'rm README'
run 'touch README'
gsub_file 'public/robots.txt', /# User-Agent/, 'User-Agent'
gsub_file 'public/robots.txt', /# Disallow/, 'Disallow'
gem 'jquery-rails' if jquery
gem 'bson_ext' if mongoid
gem 'haml' if haml
gem 'haml-rails' if haml
gem 'rspec', :group => :test if rspec
gem 'rspec-rails', :group => :development if rspec
gem 'fuubar', :group => :test if rspec
gem 'cucumber' if cucumber
gem 'cucumber-rails', :group => :cucumber if cucumber
gem 'capybara', :group => :cucumber if capybara
gem 'launchy', :group => :cucumber if capybara
gem 'machinist', '>= 2.0.0.beta2', :group => :test if machinist
gem 'factory_girl_rails', :group => :test if factory_girl
gem 'devise' if devise
run 'bundle install'
if jquery
command = "rails generate jquery:install"
command << " --ui" if jquery_ui
run command
end
if haml
generators << "g.template_engine :haml"
end
if rspec
run 'rails g rspec:install'
generators << "g.test_framework :rspec"
end
if cucumber
run 'rails g cucumber:install'
generators << "g.integration_tool :cucumber"
end
if machinist
run 'rails generate machinist:install'
generators << "g.fixture_replacement :machinist, :dir => '#{rspec ? 'spec/support' : 'test'}/blueprints'"
end
if factory_girl
end
if devise
run 'rails generate devise:install'
gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '### ActionMailer Config'
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
<<-RUBY
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
# A dummy setup for development - no deliveries, but logged
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
RUBY
end
gsub_file 'config/environments/production.rb', /config.i18n.fallbacks = true/ do
<<-RUBY
config.i18n.fallbacks = true
config.action_mailer.default_url_options = { :host => 'yourhost.com' }
### ActionMailer Config
# Setup for production - deliveries, no errors raised
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
RUBY
end
run 'rails generate devise User'
run 'rails generate migration add_name_to_user name:string'
gsub_file 'app/models/user.rb', /attr_accessible :email, :password, :password_confirmation, :remember_me/ do
<<-RUBY
validates_uniqueness_of :email, :case_sensitive => false
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
RUBY
end
append_file 'db/seeds.rb' do <<-FILE
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => "New User", :email => 'user@test.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user.name
FILE
end
run 'rake db:migrate'
run 'rake db:test:prepare'
run 'rake db:seed'
end
# Configuration
generators = <<-GENERATORS
config.generators do |g|
g.stylesheets false
#{generators.join("\n\t\t\t")}
end
GENERATORS
application generators
generate(:controller, "home index")
gsub_file 'config/routes.rb', /get \"home\/index\"/, 'root :to => "home#index"'
git :init
git :add => '.'
git :commit => "-m 'Initial commit'"
if devise
puts "Note: Devise is currently using a user's email as an identifier. You may want to change this."
puts "The seed user is email 'user@test.com' pass 'please'."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment