Skip to content

Instantly share code, notes, and snippets.

@andrew
Forked from ioptics/gist:88895
Created April 2, 2009 12:39
Show Gist options
  • Save andrew/89169 to your computer and use it in GitHub Desktop.
Save andrew/89169 to your computer and use it in GitHub Desktop.
Rails template
# Delete unnecessary files
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/images/rails.png"
run "rm public/javascripts/prototype.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/controls.js"
# Copy database.yml for distribution use
run "cp config/database.yml config/database.yml.example"
# Plugins
plugin 'make_resourceful', :git => "git://github.com/hcatlin/make_resourceful.git"
plugin 'permalink_fu', :git => "git://github.com/technoweenie/permalink_fu.git"
plugin 'hoptoad_notifier', :git => "git://github.com/thoughtbot/hoptoad_notifier.git"
plugin 'country_select', :git => "git://github.com/rails/country_select.git"
# Gems
gem 'will_paginate'
gem 'haml'
gem 'authlogic'
gem 'newrelic_rpm'
gem 'thoughtbot-paperclip', :lib => 'paperclip', :source => 'http://gems.github.com'
gem "jchupp-is_paranoid", :lib => 'is_paranoid', :source => 'http://gems.github.com'
gem 'javan-whenever', :lib => false, :source => 'http://gems.github.com'
# Commands
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.2.js > public/javascripts/jquery.js"
run "touch tmp/.gitignore log/.gitignore vendor/.gitignore"
run %{find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore}
run 'wheneverize .'
# add a layout
run "touch app/views/layouts/application.html.haml"
# make some stylesheets
inside('public/stylesheets/sass') do
run "curl -L http://gist.github.com/130941.txt > reset.sass"
run "touch application.sass print.sass iphone.sass"
end
# Gems for test env
inside('config/environments') do
File.open("test.rb", "a+") {|f| f.write(<<-TASK
config.gem "thoughtbot-shoulda", :lib => "shoulda", :source => "http://gems.github.com"
config.gem "thoughtbot-factory_girl", :lib => "factory_girl", :source => "http://gems.github.com"
TASK
)}
end
# initializers
initializer 'hoptoad.rb', <<-CODE
HoptoadNotifier.configure do |config|
config.api_key = '1234567890abcdef'
end
CODE
initializer 'paperclip.rb', <<-CODE
# hack for passenger so it resizes images properly
# change path to where you installed imagemagick
if Rails.env.development?
Paperclip.options[:image_magick_path] = '/opt/local/bin/'
end
class Paperclip::Attachment
def self.default_options
@default_options ||= {
:url => "/system/:attachment/:id/:style/:filename",
:path => ":rails_root/public:url",
:styles => {},
:default_url => "/images/default_:attachment_:style.png",
:default_style => :original,
:validations => [],
:storage => :filesystem,
:whiny => Paperclip.options[:whiny] || Paperclip.options[:whiny_thumbnails]
}
end
end
CODE
# rcov rake task
rakefile("coverage.rake") do
<<-TASK
namespace :test do
desc 'Measures test coverage'
task :coverage do
rm_f "coverage"
rm_f "coverage.data"
rcov = 'rcov test/test_helper.rb --rails --aggregate coverage.data --text-summary -Ilib -x \\gem'
system("\#{rcov} --no-html test/unit/*_test.rb")
system("\#{rcov} --no-html test/functional/*_test.rb")
system("\#{rcov} --html test/integration/*_test.rb")
system("open coverage/index.html") if PLATFORM['darwin']
end
end
TASK
end
# add metric fu rake tasks
File.open("Rakefile", "a+") {|f| f.write(<<-TASK
begin
require 'metric_fu'
rescue LoadError
end
TASK
)}
# capify
run 'capify .'
# add whenever capistrano task
inside('config') do
File.open("deploy.rb", "a+") {|f| f.write(<<-TASK
namespace :deploy do
desc "Update the crontab file"
task :update_crontab, :roles => :db do
run "cd \#{release_path} && whenever --update-crontab \#{application} --set environment=\#{rails_env}"
end
end
after "deploy:symlink", "deploy:update_crontab"
TASK
)}
end
if yes?('Do you want thinking sphinx?')
# add thinking sphinx gem
gem 'freelancing-god-thinking-sphinx', :lib => 'thinking_sphinx', :source => "http://gems.github.com"
# add sphinx deploy tasks
inside('config') do
File.open("deploy.rb", "a+") {|f| f.write(<<-TASK
namespace :sphinx do
desc "Generate the sphinx index"
task :index, :roles => :app do
run "cd \#{current_path} && rake thinking_sphinx:index RAILS_ENV=\#{rails_env}"
end
desc "Configure sphinx"
task :configure, :roles => :app do
run "cd \#{current_path} && rake thinking_sphinx:configure RAILS_ENV=\#{rails_env}"
end
desc "Stop the sphinx server"
task :stop, :roles => :app do
run "cd \#{current_path} && rake thinking_sphinx:stop RAILS_ENV=\#{rails_env}"
end
desc "Start the sphinx server"
task :start, :roles => :app do
run "cd \#{current_path} && rake thinking_sphinx:start RAILS_ENV=\#{rails_env}"
end
desc "Restart the sphinx server"
task :rebuild, :roles => :app do
run "cd \#{current_path} && rake thinking_sphinx:rebuild RAILS_ENV=\#{rails_env}"
end
end
after "deploy", "sphinx:rebuild"
TASK
)}
end
File.open("Rakefile", "a+") {|f| f.write(<<-TASK
begin
require 'thinking_sphinx/tasks'
rescue LoadError
end
TASK
)}
end
# Set up git repository and Commit all work so far to the repository
file '.gitignore', <<-END
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
db/schema.rb
log/*.pid
public/system/**/*
public/stylesheets/*.css
tmp/restart.txt
coverage/
coverage.data
END
git :init
git :add => '.'
git :commit => "-a -m 'Initial commit'"
# Success!
puts "SUCCESS!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment