public
Created

template for r3

  • Download Gist
template.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.