Skip to content

Instantly share code, notes, and snippets.

@dennyabraham
Created November 4, 2011 15:39
Show Gist options
  • Save dennyabraham/1339617 to your computer and use it in GitHub Desktop.
Save dennyabraham/1339617 to your computer and use it in GitHub Desktop.
In the year 201X, app was beginning...
project_name = ask("What is the application name?")
project_url = ask("What is the application URL?")
use_default_admin = yes?("Install prebuilt admin?")
use_twitter_bootstrap = yes?("Use the twitter bootstrap?")
setup_heroku = yes?("Set the application up on heroku?")
if setup_heroku
use_s3 = yes?("Configure s3 storage?")
if use_s3
aws_access_key_id = ask("What is the aws access key id?")
aws_secret_access_key = ask("What is the aws secret access key?")
end
end
def insert(at, file, text)
lines = File.readlines(file)
lines.insert at, "#{text}\n"
File.open(file, "w") { |f| f.write lines.join }
end
def replace(file, regex, replacement)
lines = File.readlines(file)
replace_line = lines.grep(regex).first
line_number = lines.index(replace_line)
lines.delete(replace_line)
lines.insert line_number, "#{replacement}\n"
File.open(file, "w") { |f| f.write lines.join }
end
files_to_remove = %w(
README
Gemfile
public/index.html
app/assets/images/rails.png
)
run "rm #{files_to_remove.join(' ')}"
file "README.md", "# #{project_name}"
file "Gemfile", <<-GEMFILE
source :rubygems
gem 'rails', '~>3.1'
gem 'activeadmin'
gem 'cancan'
gem 'capistrano'
gem 'carrierwave'
gem 'delayed_job'
gem 'formtastic'
gem 'devise'
gem 'fog'
gem 'foreman'
gem 'heroku'
gem 'inherited_resources'
gem 'jquery-rails'
gem 'kaminari'
gem 'meta_search'
gem 'newrelic_rpm'
gem 'omniauth', '~>0.3.2'
gem 'pg'
gem 'rmagick'
gem 'sass'
gem 'sass-rails'
gem 'unicorn'
group :test, :development do
gem 'sqlite3'
gem 'rspec-rails'
gem 'guard'
gem 'cucumber'
gem 'capybara'
gem 'database_cleaner'
gem 'factory_girl_rails'
gem 'ruby-debug19'
gem 'rb-fsevent'
gem 'growl'
end
GEMFILE
if setup_heroku
file "Procfile", <<-PROCFILE
web: bin/unicorn -c config/unicorn.rb -E $RAILS_ENV -p $PORT
PROCFILE
end
file "Guardfile", <<-'GUARDFILE'
guard 'rspec' do
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
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)\.rb}) { |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
GUARDFILE
file ".rvmrc", <<-RVMRC
rvm 1.9.2@#{project_name} --create
RVMRC
run "bundle --binstubs"
inside 'config' do
file 'unicorn.rb', <<-NEIGHHHH
worker_processes 3
timeout 30
NEIGHHHH
end
generate("jquery:install")
generate("devise:install")
generate("controller", "home")
inside "app/views/home" do
file "index.html.erb", "<h1>Home</h1>"
end
route "root :to => 'home#index'"
insert 4, "config/environments/development.rb", <<-EOF
config.action_mailer.default_url_options = { :host => "localhost:3000" }
EOF
insert 4, "config/environments/test.rb", <<-EOF
config.action_mailer.default_url_options = { :host => "example.com" }
EOF
insert 4, "config/environments/production.rb", <<-EOF
config.action_mailer.default_url_options = { :host => "#{project_url}" }
EOF
insert -6, "app/views/layouts/application.html.erb", <<-EOF
<% flash.each do |key, value| -%>
<div class="flash <%= key %>"><%= value %></div>
<% end -%>
EOF
replace "config/initializers/devise.rb", /mailer_sender/, " config.mailer_sender = 'admin@#{project_url}'"
insert -1, "Rakefile", <<-EOF
task(:default).clear
task :default => [:spec, :cucumber]
EOF
generate("rspec:install")
generate("cucumber:install", "--rspec --capybara")
generate("cucumber_rails_training_wheels:install")
generate("kaminari:config")
generate("formtastic:install")
if use_default_admin
generate("active_admin:install")
else
generate("devise", "account")
generate("devise:views")
end
if use_twitter_bootstrap
run("cd tmp && curl -L https://github.com/twitter/bootstrap/tarball/master|tar -xzv")
run("mv tmp/twi*/*.css public/stylesheets/")
run("mv tmp/twi*/js/*.js public/javascripts/")
end
if setup_heroku && use_s3
initializer "carrierwave.rb", <<-CARRIERWAVE
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => ENV['ACCESS_KEY_ID'],
:aws_secret_access_key => ENV['SECRET_ACCESS_KEY'],
}
config.fog_directory = '#{project_name + "_bucket"}'
end
CARRIERWAVE
# TODO - DSA - investigate jammit-s3
end
rake "db:create"
rake "db:migrate"
rake "db:test:prepare"
run "curl https://raw.github.com/github/gitignore/master/Rails.gitignore -o .gitignore"
git :init
git :add => '.'
git :commit => "-m 'Initial commit for #{project_name}'"
if setup_heroku
run "heroku create #{project_name} --stack cedar"
git :push => 'heroku master'
run "heroku run rake db:migrate"
run "heroku addons:add custom_domains"
run "heroku domains:add #{project_url}"
run "heroku addons:upgrade logging:expanded"
run "heroku addons:add loggly:mole"
run "heroku addons:add sendgrid:starter"
run "heroku addons:add newrelic:standard"
if use_s3
run "heroku config:add ACCESS_KEY_ID=#{aws_access_key_id}"
run "heroku config:add SECRET_ACCESS_KEY=#{aws_secret_access_key}"
end
end
rails new $(APP_NAME) -T --skip-bundle --skip-sprockets -m https://raw.github.com/gist/1339617/f90a9f1bb7ebfb5e1c207ad30a7d72495c2a5c1b/combined_template.rb
http://git.io/denny-apptemplate1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment