# Run use this template by running: rails my_new_app -m /path/to/template.rb (can also be an URL)
# Or, to use on an existing project: rake rails:template LOCATION=~/template.rb
app_name = ask("What do you want to call this project? ")
environment("config.action_controller.session = { :key => '_#{app_name}_session', :secret => '#{(1..40).map { |x| (65 + rand(26)).chr }.join}' }")
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
run "rm -f public/javascripts/*"
# Download JQuery
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js > public/javascripts/jquery.js"
run "curl -L http://jqueryjs.googlecode.com/svn/trunk/plugins/form/jquery.form.js > public/javascripts/jquery.form.js"
# git:hold_empty_dirs
run("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;")
freeze!
# Link to local copy of edge rails
inside('vendor') { run 'ln -s ~/dev/rails/rails rails' }
# generate(:scaffold, "person name:string")
route "map.root :controller => 'people'"
rake("rails:freeze:gems") if yes?("Freeze rails gems ?")
run "rake rails:freeze:edge" if yes?("Do you want to use edge rails?")
if yes?("Do you want to use RSpec?")
plugin "rspec", :git => "git://github.com/dchelimsky/rspec.git"
plugin "rspec-rails", :git => "git://github.com/dchelimsky/rspec-rails.git"
# generate(:what, "name", "column:type")
generate :rspec
end
if yes?("Do you want authentication?")
plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git'
run "mv vendor/plugins/restful-authentication vendor/plugins/restful_authentication"
modle = ask("What do you want your account model to be called? [account]")
modle = "account" if modle.blank?
controller = ask("What do you want your authentication controller to be called? [sessions]")
controller = "sessions" if modle.blank?
run "./script/generate authenticated #{modle} #{controller} --include-activation --rspec"
end
run "echo 'TODO add readme content' > README"
run "cp config/database.yml config/database_sample.yml"
plugin "rspec", :git => "git://github.com/dchelimsky/rspec.git", :submodule => true
plugin "rspec-rails", :git => "git://github.com/dchelimsky/rspec-rails.git", :submodule => true
plugin "exception-notifier", :git => "git://github.com/rails/exception_notification.git", :submodule => true
plugin "restful-authentication", :git => "git://github.com/technoweenie/restful-authentication.git", :submodule => true
plugin "semantic-form-builder", :git => "git://github.com/rubypond/semantic_form_builder.git", :submodule => true
plugin "paperclipped", :git => "git://github.com/kbingman/paperclipped.git", :submodule => true
# Or use SVN: plugin 'wtfsvn' :svn => 'svn://crap.com/wtf/trunk'
# Install necessary gems
gem "will-paginate", :git => "git://github.com/mislav/will_paginage.git"
gem "haml", :git => "git://github.com/nex3/haml.git" #, :version => '0.6'
rake "gems:install", :sudo => true
run "haml --rails ."
# Create a route
route "map.login '/login', :controller => 'sessions', :action => 'new'"
initializer 'form_builder.rb', <<-CODE
ActionView::Base.default_form_builder = SemanticFormBuilder
CODE
# Set up sessions, RSpec, user model, OpenID, etc, and run migrations
rake('db:sessions:create')
generate("authenticated", "user session")
generate("roles", "Role User")
generate("rspec")
rake('acts_as_taggable:db:create')
rake('open_id_authentication:db:create')
rake('db:migrate')
# Set up session store initializer
initializer 'session_store.rb', <<-END
ActionController::Base.session = { :session_key => '_#{(1..6).map { |x| (65 + rand(26)).chr }.join}_session', :secret => q }
ActionController::Base.session_store = :active_record_store
END
git :submodule => "init"
rake "db:migrate" #, :env => 'test'
run "cp config/database.yml config/database.yml.sample"
initializer 'action_mailer_configs.rb',
%q{ ActionMailer::Base.smtp_settings = {
:address => "smtp.thoughtbot.com",
:port => 25,
:domain => "thoughtbot.com"
}
}
initializer 'requires.rb',
%q{require 'redcloth'
Dir[File.join(RAILS_ROOT, 'lib', 'extensions', '*.rb')].each do |f|
require f
end
Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f|
require f
end
}
initializer 'time_formats.rb',
%q{# Example time formats
{ :short_date => "%x", :long_date => "%a, %b %d, %Y" }.each do |k, v|
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v)
end
}
capify!
file 'config/environment.rb',
%q{# Be sure to restart your server when you modify this file
# Change this to the name of your rails project, like carbonrally.
# Just use the same name as the svn repo.
PROJECT_NAME = "CHANGEME"
throw "The project's name in environment.rb is blank" if PROJECT_NAME.empty?
throw "Project name (#{PROJECT_NAME}) must_be_like_this" unless PROJECT_NAME =~ /^[a-z_]*$/
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.0' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# See Rails::Configuration for more options.
# Skip frameworks you're not going to use. To use Rails without a database
# you must remove the Active Record framework.
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
# Specify gems that this application depends on.
config.gem 'RedCloth',
:lib => 'redcloth',
:version => '~> 3.0.4'
config.gem 'mislav-will_paginate',
:lib => 'will_paginate',
:source => 'http://gems.github.com',
:version => '~> 2.3.5'
config.gem 'mocha',
:version => '>= 0.9.2'
config.gem 'quietbacktrace',
:version => '>= 0.1.1'
config.gem 'thoughtbot-factory_girl',
:lib => 'factory_girl',
:source => 'http://gems.github.com',
:version => '>= 1.1.3'
config.gem 'thoughtbot-shoulda',
:lib => 'shoulda',
:source => 'http://gems.github.com',
:version => '>= 2.0.5'
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Add the vendor/gems/*/lib directories to the LOAD_PATH
config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
# Force all environments to use the same logger level
# (by default production uses :info, the others :debug)
# config.log_level = :debug
# Make Time.zone default to the specified zone, and make Active Record store time values
# in the database in UTC, and return them converted to the specified local zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
config.time_zone = 'UTC'
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
SESSION_KEY = "CHANGESESSION"
config.action_controller.session = {
:session_key => "_#{PROJECT_NAME}_session",
:secret => SESSION_KEY
}
# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rake db:sessions:create")
# config.action_controller.session_store = :active_record_store
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
# like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql
# Activate observers that should always be running
# config.active_record.observers = :cacher, :garbage_collector
end
}
file 'Capfile',
%q{load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
}
file 'config/database.yml',
%q{<% PASSWORD_FILE = File.join(RAILS_ROOT, '..', '..', 'shared', 'config', 'dbpassword') %>
development:
adapter: mysql
database: <%= PROJECT_NAME %>_development
username: root
password:
host: localhost
encoding: utf8
test:
adapter: mysql
database: <%= PROJECT_NAME %>_test
username: root
password:
host: localhost
encoding: utf8
staging:
adapter: mysql
database: <%= PROJECT_NAME %>_staging
username: <%= PROJECT_NAME %>
password: <%= File.read(PASSWORD_FILE).chomp if File.readable? PASSWORD_FILE %>
host: localhost
encoding: utf8
socket: /var/lib/mysql/mysql.sock
production:
adapter: mysql
database: <%= PROJECT_NAME %>_production
username: <%= PROJECT_NAME %>
password: <%= File.read(PASSWORD_FILE).chomp if File.readable? PASSWORD_FILE %>
host: localhost
encoding: utf8
socket: /var/lib/mysql/mysql.sock
}
file 'config/deploy.rb',
%q{set :stages, %w(staging production)
set :default_stage, 'staging'
require 'capistrano/ext/multistage'
before "deploy:setup", "db:password"
namespace :deploy do
desc "Default deploy - updated to run migrations"
task :default do
set :migrate_target, :latest
update_code
migrate
symlink
restart
end
desc "Start the mongrels"
task :start do
send(run_method, "cd #{deploy_to}/#{current_dir} && #{mongrel_rails} cluster::start --config #{mongrel_cluster_config}")
end
desc "Stop the mongrels"
task :stop do
send(run_method, "cd #{deploy_to}/#{current_dir} && #{mongrel_rails} cluster::stop --config #{mongrel_cluster_config}")
end
desc "Restart the mongrels"
task :restart do
send(run_method, "cd #{deploy_to}/#{current_dir} && #{mongrel_rails} cluster::restart --config #{mongrel_cluster_config}")
end
desc "Run this after every successful deployment"
task :after_default do
cleanup
end
end
namespace :db do
desc "Create database password in shared path"
task :password do
set :db_password, Proc.new { Capistrano::CLI.password_prompt("Remote database password: ") }
run "mkdir -p #{shared_path}/config"
put db_password, "#{shared_path}/config/dbpassword"
end
end
}
file 'config/deploy/staging.rb',
%q{# For migrations
set :rails_env, 'staging'
# Who are we?
set :application, 'CHANGEME'
set :repository, "git@github.com:thoughtbot/#{application}.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, "staging"
# Where to deploy to?
role :web, "staging.example.com"
role :app, "staging.example.com"
role :db, "staging.example.com", :primary => true
# Deploy details
set :user, "#{application}"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :use_sudo, false
set :checkout, 'export'
# We need to know how to use mongrel
set :mongrel_rails, '/usr/local/bin/mongrel_rails'
set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_staging.yml"
}
file 'config/deploy/production.rb',
%q{# For migrations
set :rails_env, 'production'
# Who are we?
set :application, 'CHANGEME'
set :repository, "git@github.com:thoughtbot/#{application}.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, "production"
# Where to deploy to?
role :web, "production.example.com"
role :app, "production.example.com"
role :db, "production.example.com", :primary => true
# Deploy details
set :user, "#{application}"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :use_sudo, false
set :checkout, 'export'
# We need to know how to use mongrel
set :mongrel_rails, '/usr/local/bin/mongrel_rails'
set :mongrel_cluster_config, "#{deploy_to}/#{current_dir}/config/mongrel_cluster_production.yml"
}
file 'config/environments/development.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_view.debug_rjs = true
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
HOST = 'localhost'
}
file 'config/environments/production.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
config.action_mailer.raise_delivery_errors = false
}
file 'config/environments/staging.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# We'd like to stay as close to prod as possible
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable delivery errors if you bad email addresses should just be ignored
config.action_mailer.raise_delivery_errors = false
}
file 'config/environments/test.rb',
%q{# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
HOST = 'localhost'
require 'quietbacktrace'
require 'factory_girl'
require 'mocha'
begin require 'redgreen'; rescue LoadError; end
}
# generate(:scaffold, "person name:string")
route "map.root :controller => 'people'"
# Install necessary gems
gem "will-paginate", :git => "git://github.com/mislav/will_paginage.git"
gem "haml", :git => "git://github.com/nex3/haml.git" #, :version => '0.6'
rake "gems:install", :sudo => true
run "haml --rails ."
rake "db:migrate" #, :env => 'test'
# Setup git ignore file
file '.gitignore', <<-END
*~
*.cache
config/database.yml
public/stylesheets/*.css
*.swo
*.swp
.DS_Store
*.tmproj
log/*
tmp/*
TAGS
.#*
.hgignore
.hg/*
.svn/*
END
git :add => "."
git :commit => "-a -m 'Initial commit'"
puts "Great success!"