Created
October 4, 2009 17:31
-
-
Save tcocca/201506 to your computer and use it in GitHub Desktop.
My standard rails app 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
# Tom's standard rails template | |
# Application Gems | |
gem "formtastic", :version => '>= 0.9.7' | |
gem 'will_paginate', :version => '~> 2.3.11' | |
gem "acts-as-taggable-on", :version => '>= 1.1.6' | |
gem "paperclip", :version => '>= 2.3.1.1' | |
gem "friendly_id", :version => '>= 2.3.2' | |
gem "inherited_resources", :version => '>= 1.1.0' | |
gem "thinking-sphinx", :lib => 'thinking_sphinx', :version => '>= 1.3.6' | |
gem 'ts-delayed-delta', :lib => 'thinking_sphinx/deltas/delayed_delta', :version => '>= 1.0.3' | |
gem "whenever", :lib => false, :version => '>= 0.4.1' | |
gem "acts_as_audited", :lib => false,, :version => '>= 1.1.0' | |
gem "delayed_job", :version => '>= 1.8.4' | |
gem "jrails", :version => '>= 0.6.0' | |
gem "acts_as_archive", :version => '>= 0.2.3' | |
gem "web-app-theme", :version => '>= 0.5.2' | |
# Development Gems | |
gem "rails-footnotes", :version => '>= 3.6.6', :env => "development" | |
# Test Gems | |
gem "shoulda", :version => '>= 2.10.3', :env => "test" | |
gem "factory_girl", :version => '>= 1.2.3', :env => "test" | |
gem "cucumber", :version => "0.6.3", :env => "test" | |
gem "cucumber-rails", :version => "0.3.0", :env => "test" | |
gem "webrat", :version => "0.7.0", :env => "test" | |
# Standard Plugins | |
plugin 'exception_notifier', :git => 'git://github.com/rails/exception_notification.git -r 2-3-stable' | |
plugin 'asset_packager', :git => 'git://github.com/sbecker/asset_packager.git' | |
plugin 'limerick_rake', :git => 'git://github.com/thoughtbot/limerick_rake.git' | |
plugin 'acts_as_list', :git => 'git://github.com/rails/acts_as_list.git' | |
plugin 'blitz', :git => 'git://github.com/dancroak/blitz.git' | |
# Install and unpack gems | |
rake("gems:install") | |
rake("gems:unpack:dependencies") | |
rake("gems:install RAILS_ENV=development",) | |
rake("gems:unpack:dependencies RAILS_ENV=development") | |
rake("gems:install RAILS_ENV=test") | |
rake("gems:unpack:dependencies RAILS_ENV=test") | |
# Freeze Rails? | |
rake("rails:freeze:gems") if yes?("Freeze rails gems ?") | |
# Gem and Plugin configuration and installation | |
rake("jrails:js:scrub") | |
rake("asset:packager:create_yml") | |
generate("clearance") | |
generate("clearance_views") | |
generate("cucumber") | |
generate("clearance_features") | |
generate("formtastic") | |
generate("acts_as_taggable_on_migration") | |
generate("audited_migration add_audits_table") | |
generate("delayed_job") | |
run "wheneverize ." | |
# Set the Time Zone | |
environment( "config.time_zone = 'Eastern Time (US & Canada)'" ) | |
# Create DB example for SVN | |
inside('config') do | |
run "cp database.yml database.yml.example" | |
end | |
# Create the staging environment | |
inside('config/environments') do | |
run 'cp production.rb staging.rb' | |
end | |
# Capistrano | |
capify! | |
file "config/deploy.rb", <<-DEPLOY | |
require 'capistrano/ext/multistage' | |
set :stages, %w(staging production) # [optional] defaults to | |
set :default_stage, "staging" | |
set :application, "" | |
set :scm_user, "deploy" | |
set :repository, Proc.new { "" } | |
# : : : : : : : : : : : : : : : : : : : : : : : : : : : | |
after "deploy:finalize_update", "deploy:cleanup" | |
desc "Tasks to execute after code update" | |
task :after_update_code, :roles => [:app] do | |
# build the asset packages | |
#run "cd \#{current_path} && rake asset:packager:build_all" | |
# relink database configuration | |
run "cp \#{release_path}/config/database.yml.example \#{release_path}/config/database.yml" | |
# clear the frags directories | |
run "rm -rf \#{shared_path}/system/frags" | |
run "mkdir \#{shared_path}/system/frags" | |
run "ln -nfs \#{shared_path}/system/frags \#{release_path}/public/system/frags" | |
end | |
# : : : : : : : Delayed Job | |
after "deploy:start", "delayed_job:start" | |
after "deploy:stop", "delayed_job:stop" | |
after "deploy:restart", "delayed_job:restart" | |
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 | |
DEPLOY | |
file "config/deploy/staging.rb", <<-DEPLOY | |
puts "-- -- staging -- --" | |
role :web, "ip" | |
role :app, "ip" | |
role :db, "ip", :primary => true | |
set :deploy_to, "/home/deploy/rails/application" | |
set :user, "deploy" | |
set :stage, "staging" | |
ENV['RAILS_ENV'] = stage | |
set :env, stage | |
set :environment, env | |
set :rails_env, stage | |
desc "Set the Staging robots.txt file and Re-generate sitemap after deployment" | |
task :after_deploy, :roles => [:app, :db, :web] do | |
run "rm \#{release_path}/public/robots.txt" | |
run "cp \#{release_path}/public/robots_staging.txt \#{release_path}/public/robots.txt" | |
end | |
DEPLOY | |
file "config/deploy/production.rb", <<-DEPLOY | |
puts "-- -- production -- --" | |
role :web, "ip" | |
role :app, "ip" | |
role :db, "ip", :primary => true | |
set :deploy_to, "/home/deploy/rails/application" | |
set :user, "deploy" | |
set :stage, "production" | |
set :rails_env, stage | |
DEPLOY | |
# Remove the rails files | |
run "rm public/index.html" | |
run 'rm -f public/images/rails.png' | |
# Caching | |
initializer 'caching.rb', <<-CODE | |
ActionController::Base.cache_store = :file_store, "\#{RAILS_ROOT}/public/system/frags" | |
CODE | |
# Fix the way rails generates fields with errors | |
initializer 'field_errors.rb', <<-CODE | |
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<span class=\"fieldWithErrors\">\#{html_tag}</span>" } | |
CODE | |
# Ability to override emails in non-production environments | |
initializer 'staged_email.rb', <<-CODE | |
# Forces all outgoing mail from dev/staging environments to go to developers | |
module ActionMailer | |
class Base | |
protected | |
def staged_email(email_address) | |
ENV['RAILS_ENV'] == 'production' ? email_address : SYSTEM_TO_EMAIL | |
end | |
end | |
end | |
CODE | |
# Mail initializer setup | |
smtp_address = ask("What is your smtp address ?") | |
smtp_port = ask("What is your smtp port ?") | |
smtp_domain = ask("What is your smtp domain ?") | |
smtp_username = ask("What is your smtp username ?") | |
smtp_password = ask("What is your smtp password ?") | |
smtp_authentication = ask("What is your smtp authentication (plain / login) ?") | |
smtp_tls = ask("What enable tls (true / false) ?") | |
en_recipients = ask("Who are the exception recipients ?") | |
en_sender = ask("Who is the exception sender ?") | |
en_prefix = ask("What is the exception prefix ?") | |
initializer 'mail.rb', <<-CODE | |
ActionMailer::Base.smtp_settings = { | |
:address => "#{smtp_address}", | |
:port => #{smtp_port}, | |
:domain => "#{smtp_domain}", | |
:user_name => "#{smtp_username}", | |
:password => "#{smtp_password}", | |
:authentication => :#{smtp_authentication}, | |
:enable_starttls_auto => #{smtp_tls == "true" ? true : false} | |
} | |
ExceptionNotifier.exception_recipients = %w{#{en_recipients}} | |
ExceptionNotifier.sender_address = %W{#{en_sender}} | |
ExceptionNotifier.email_prefix = "[#{en_prefix}\#{"_\#{RAILS_ENV}" if RAILS_ENV != 'production'}] " | |
DO_NOT_REPLY = "[email protected]" | |
CODE | |
# Clearance current_user footnote setup | |
file 'lib/footnotes/notes/current_user_note.rb', <<-CODE | |
module Footnotes | |
module Notes | |
class CurrentUserNote < AbstractNote | |
# This method always receives a controller | |
# | |
def initialize(controller) | |
@current_user = controller.instance_variable_get("@current_user") | |
end | |
# The name that will appear as legend in fieldsets | |
# | |
def legend | |
"Current user: \#{@current_user.email}" | |
end | |
# This Note is only valid if we actually found an user | |
# If it's not valid, it won't be displayed | |
# | |
def valid? | |
@current_user | |
end | |
# The fieldset content | |
# | |
def content | |
escape(@current_user.inspect) | |
end | |
end | |
end | |
end | |
CODE | |
# Default application layout | |
file 'app/views/layouts/application.html.erb', <<-LAYOUT | |
<!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"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> | |
<title></title> | |
<meta name="Description" content="" /> | |
<meta name="Keywords" content="" /> | |
<meta name="verify-v1" content="" /> | |
<%= javascript_include_merged :base %> | |
<%= stylesheet_link_merged :base %> | |
<%#= stylesheet_link_merged :print, :media => "print" %> | |
<%= yield :head_content %> | |
<%= render :partial => "shared/google_analytics" %> | |
</head> | |
<body> | |
<%= yield %> | |
<%= yield :last_content %> | |
</body> | |
</html> | |
LAYOUT | |
# Google Analytics | |
file 'app/views/shared/_google_analytics.html.erb', <<-ANALYTICS | |
<script type="text/javascript"> | |
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); | |
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); | |
</script> | |
<script type="text/javascript"> | |
try { | |
var pageTracker = _gat._getTracker("<%= RAILS_ENV == "production" ? 'production_code' : 'other_code' %>"); | |
pageTracker._trackPageview(); | |
} catch(err) {}</script> | |
ANALYTICS | |
# Staging Robots.txt | |
file 'public/robots_staging.txt', <<-ROBOTS | |
User-agent: * | |
Disallow: / | |
User-agent: Googlebot | |
Disallow: / | |
ROBOTS | |
# Factory Girl Uploads helper | |
file 'test/factory_attachment.rb', <<-UPLOADS | |
require 'action_controller/test_process' | |
Factory.class_eval do | |
def attachment(name, path, content_type = nil) | |
path_with_rails_root = "\#{RAILS_ROOT}/\#{path}" | |
uploaded_file = if content_type | |
ActionController::TestUploadedFile.new(path_with_rails_root, content_type) | |
else | |
ActionController::TestUploadedFile.new(path_with_rails_root) | |
end | |
add_attribute name, uploaded_file | |
end | |
end | |
UPLOADS | |
# Environment specific settings | |
dev_email = ask("What is the development email address ?") | |
append_file 'config/environments/development.rb', <<-DEVELOPMENT | |
\n | |
SYSTEM_TO_EMAIL = "#{dev_email}" | |
SYSTEM_DOMAIN = "http://localhost:3000" | |
DEVELOPMENT | |
append_file 'config/environments/test.rb', <<-TEST | |
\n | |
SYSTEM_TO_EMAIL = "#{dev_email}" | |
SYSTEM_DOMAIN = "http://localhost:3000" | |
TEST | |
append_file 'config/environments/staging.rb', <<-STAGING | |
\n | |
SYSTEM_TO_EMAIL = "#{dev_email}" | |
SYSTEM_DOMAIN = "http://localhost:3000" | |
STAGING | |
append_file 'config/environments/production.rb', <<-PRODUCTION | |
\n | |
SYSTEM_TO_EMAIL = "#{dev_email}" | |
SYSTEM_DOMAIN = "http://localhost:3000" | |
PRODUCTION | |
append_file 'Rakefile', <<-RAKEFILE | |
\n | |
require 'thinking_sphinx/tasks' | |
\n | |
begin | |
require 'delayed/tasks' | |
rescue LoadError | |
STDERR.puts "Run `rake gems:install` to install delayed_job" | |
end | |
RAKEFILE | |
git :init | |
file ".gitignore", <<-END | |
.DS_Store | |
log/*.log | |
tmp/**/* | |
config/database.yml | |
db/*.sqlite3 | |
END | |
git :add => ".", :commit => "-m 'initial commit'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment