Created
January 8, 2010 21:43
-
-
Save forest/272448 to your computer and use it in GitHub Desktop.
Rails 2.3 Site Template
This file contains hidden or 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
# | |
# rails_site_template.rb | |
# based on: | |
# Suspenders by Thoughtbot | |
# http://m.onkey.org/2008/12/4/rails-templates | |
# http://github.com/jeremymcanally/rails-templates/blob/master/sethbc.rb | |
# | |
# Created by Forest Carlisle on 2009-12-30. | |
# | |
# Set up git repository | |
git :init | |
# Install plugins as git submodules | |
plugin 'acts_as_taggable_redux', :git => 'git://github.com/geemus/acts_as_taggable_redux.git', :submodule => true | |
#plugin 'exception_notifier', :git => 'git://github.com/rails/exception_notification.git', :submodule => true | |
#plugin 'asset_packager', :git => 'git://github.com/sbecker/asset_packager.git', :submodule => true | |
plugin 'limerick_rake', :git => "git://github.com/thoughtbot/limerick_rake.git", :submodule => true | |
# Initialize submodules | |
git :submodule => "init" | |
#==================== | |
# GEMS | |
#==================== | |
gem 'RedCloth' #, :lib => 'redcloth', :version => '~> 3.0.4' | |
gem 'will_paginate' | |
gem 'factory_girl' | |
gem 'shoulda' | |
gem 'quietbacktrace' | |
gem 'searchlogic' | |
gem 'authlogic' | |
gem 'rr' # plugin 'rr', :git => 'git://github.com/btakita/rr.git', :submodule => true | |
gem 'cucumber' | |
rake('gems:install', :sudo => true) | |
rake('gems:build', :sudo => true) | |
#rake('gems:unpack') | |
rake('gems:unpack') if yes?('Unpack gems?) | |
#==================== | |
# APP | |
#==================== | |
# file 'app/controllers/application_controller.rb', | |
# %q{class ApplicationController < ActionController::Base | |
# | |
# helper :all | |
# | |
# protect_from_forgery | |
# | |
# end | |
# } | |
file 'app/helpers/application_helper.rb', | |
%q{module ApplicationHelper | |
def body_class | |
"#{controller.controller_name} #{controller.controller_name}-#{controller.action_name}" | |
end | |
end | |
} | |
file 'app/views/layouts/_flashes.html.erb', | |
%q{<div id="flash"> | |
<% flash.each do |key, value| -%> | |
<div id="flash_<%= key %>"><%=h value %></div> | |
<% end -%> | |
</div> | |
} | |
file 'app/views/layouts/application.html.erb', | |
%q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
<title><%= PROJECT_NAME.humanize %></title> | |
<%= stylesheet_link_tag 'main', :media => 'all', :cache => true %> | |
<%= javascript_include_tag :defaults, :cache => true %> | |
</head> | |
<body class="<%= body_class %>"> | |
<%= render :partial => 'layouts/flashes' -%> | |
<%= yield %> | |
</body> | |
</html> | |
} | |
#==================== | |
# INITIALIZERS | |
#==================== | |
initializer 'action_mailer_configs.rb', | |
%q{ActionMailer::Base.smtp_settings = { | |
:address => "smtp.gmail.com", | |
:port => 587, | |
:domain => "gmail.com" | |
} | |
} | |
initializer 'errors.rb', | |
%q{# Example: | |
# begin | |
# some http call | |
# rescue *HTTP_ERRORS => error | |
# notify_hoptoad error | |
# end | |
HTTP_ERRORS = [Timeout::Error, | |
Errno::EINVAL, | |
Errno::ECONNRESET, | |
EOFError, | |
Net::HTTPBadResponse, | |
Net::HTTPHeaderSyntaxError, | |
Net::ProtocolError] | |
# SMTP_SERVER_ERRORS = [TimeoutError, | |
# IOError, | |
# Net::SMTPUnknownError, | |
# Net::SMTPServerBusy, | |
# Net::SMTPAuthenticationError] | |
# | |
# SMTP_CLIENT_ERRORS = [Net::SMTPFatalError, | |
# Net::SMTPSyntaxError] | |
# | |
# SMTP_ERRORS = SMTP_SERVER_ERRORS + SMTP_CLIENT_ERRORS | |
} | |
# initializer 'hoptoad.rb', | |
# %q{HoptoadNotifier.configure do |config| | |
# config.api_key = 'HOPTOAD-KEY' | |
# end | |
# } | |
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 | |
} | |
# ==================== | |
# CONFIG | |
# ==================== | |
capify! | |
file 'config/database.yml.useme', | |
%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" | |
set :scm, :git | |
set :repository, "[email protected]:changeme/changeme.git" | |
set :branch, "master" | |
set :deploy_via, :remote_cache | |
set :git_enable_submodules, true | |
# set :copy_exclude, [".git", "content"] | |
# If you aren't deploying to /u/apps/#{application} on the target | |
# servers (which is the default), you can specify the actual location | |
# via the :deploy_to variable: | |
set(:deploy_to) {"/home/#{user}/#{application}"} | |
# set :chmod755, "app config db lib public vendor script script/* public/disp*" | |
set :use_sudo, false | |
# | |
# TASKS | |
# | |
namespace :deploy do | |
desc "Restarting mod_rails with restart.txt" | |
task :restart, :roles => :app, :except => { :no_release => true } do | |
run "touch #{current_path}/tmp/restart.txt" | |
end | |
[:start, :stop].each do |t| | |
desc "#{t} task is a no-op with mod_rails" | |
task t, :roles => :app do ; end | |
end | |
end | |
desc "Copy production config files" | |
task :copy_config_files do | |
configs = %w(config/config.yml) #config/database.yml config/amazon_s3.yml | |
configs.each do |filename| | |
run "cp -f #{shared_path}/#{filename} #{release_path}/#{filename}" | |
end | |
end | |
after "deploy:update_code", :copy_config_files | |
desc "Force environment based on stage by replacing a line in environment.rb" | |
task :force_environment_for_stage, :roles => [:web, :app] do | |
# Force enviroment by replacing a line in environment.rb | |
run "perl -i -pe \"s/# ENV\\['RAILS_ENV'\\] \\|\\|= 'production'/ENV['RAILS_ENV'] = '#{stage}'/\" #{current_path}/config/environment.rb" | |
end | |
after "deploy:symlink", :force_environment_for_stage | |
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 'db/seeds.rb', | |
%q{require 'open-uri' | |
require 'active_record/fixtures' | |
# ["Windows", "Linux", "Mac OS X"].each do |os| | |
# OperatingSystem.find_or_create_by_name(os) | |
# end | |
# Country.delete_all | |
# open("http://openconcept.ca/sites/openconcept.ca/files/country_code_drupal_0.txt") do |countries| | |
# countries.read.each_line do |country| | |
# code, name = country.chomp.split("|") | |
# Country.create!(:name => name, :code => code) | |
# end | |
# end | |
# Fixtures.create_fixtures("#{Rails.root}/test/fixtures", "operating_systems") | |
} | |
# ==================== | |
# FINALIZE | |
# ==================== | |
# Delete unnecessary files | |
run "rm README" | |
run "rm doc/README_FOR_APP" | |
run "rm public/index.html" | |
run "rm public/favicon.ico" | |
run "rm public/robots.txt" | |
# get jquery | |
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js > public/javascripts/jquery.js" | |
# Set up .gitignore files | |
run %{find . -type d -empty | xargs -I xxx touch xxx/.gitignore} | |
file '.gitignore', <<-END | |
.DS_Store | |
coverage/* | |
log/*.log | |
db/*.db | |
db/*.sqlite3 | |
db/schema.rb | |
tmp/**/* | |
doc/api | |
doc/app | |
coverage/* | |
END | |
# Other setup: generators and run migrations | |
#rake('db:sessions:create') | |
#generate("authlogic", "user session") | |
#rake('acts_as_taggable:db:create') | |
#rake('db:migrate') | |
# Commit all work so far to the repository | |
git :add => '.' | |
git :commit => "-a -m 'Initial commit'" | |
puts %{TODO: | |
1. Add the following to the top of config/environment.rb: | |
# Change this to the name of your rails project, like mycoolapp. | |
# Just use the same name as the git 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_]*$/ | |
2. Replace config/database.yml with config/database.yml.useme | |
3. Run: | |
rake db:migrate | |
} | |
# Success! | |
puts "SUCCESS!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment