Created
December 18, 2008 19:50
-
-
Save uhlenbrock/37619 to your computer and use it in GitHub Desktop.
My Rails Template
This file contains 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
# TODO | |
# - authentication for admin | |
# - hoptoad/exception_notification | |
# - setup layouts | |
# - any gems? | |
# - any plugins? | |
# - blueprint? | |
# Delete unneeded files | |
run 'rm README' | |
run 'rm public/index.html' | |
run 'rm public/favicon.ico' | |
run 'rm public/robots.txt' | |
# Setup the initializers | |
initializer 'constants.rb', | |
%q{META = { | |
:keywords => "", | |
:description => "" | |
} | |
} | |
# Setup the admin | |
generate(:controller, "admin") | |
route("map.admin 'admin', :controller => 'admin'") | |
run "touch app/views/layouts/admin.html.erb" | |
file "app/controllers/admin_controller.rb", | |
%q{class AdminController < ApplicationController | |
USER_NAME, PASSWORD = "username", "password" | |
layout 'admin' | |
before_filter :authenticate | |
def index | |
end | |
protected | |
# DRY method to manage redirects from form submissions. | |
# :continue will save the record and return to :edit, | |
# otherwise it will save and return to :index. | |
def model_conditional_continue (record, return_url = nil, continue_url = nil) | |
model = record.class.to_s.underscore | |
if params[:continue] | |
url = continue_url || eval("edit_admin_#{model}_path(record)") | |
else | |
url = return_url || eval("admin_#{model.pluralize}_path") | |
end | |
redirect_to url | |
end | |
private | |
def authenticate | |
authenticate_or_request_with_http_basic do |user_name, password| | |
user_name == USER_NAME && password == PASSWORD | |
end | |
end | |
end | |
} | |
# Setup the public site | |
generate(:controller, "public") | |
run "touch app/views/layouts/public.html.erb" | |
run "touch app/views/public/404.html.erb" | |
route("map.root :controller => 'public'") | |
route("map.four_oh_four '*args', :controller => 'public', :action => 'four_oh_four'") | |
file "app/controllers/public_controller.rb", | |
%q{class PublicController < ApplicationController | |
layout 'public' | |
rescue_from ActiveRecord::RecordNotFound, :with => :file_not_found | |
# don't call me, use file_not_found | |
def four_oh_four | |
file_not_found | |
end | |
protected | |
def file_not_found | |
render :template => "public/404", :layout => "public", :status => 404 | |
end | |
helper_method :meta_description, :meta_keywords | |
def meta_keywords | |
@meta_keywords ||= META[:keywords] | |
end | |
def meta_description | |
@meta_description ||= META[:description] | |
end | |
end | |
} | |
# Setup helpers | |
file "app/helpers/application_helper.rb", | |
%q{module ApplicationHelper | |
def title(title) | |
content_for(:title) { h(title) } | |
return title | |
end | |
def stylesheet(*args) | |
content_for(:head) { stylesheet_link_tag(*args) } | |
end | |
def javascript(*args) | |
content_for(:head) { javascript_include_tag(*args) } | |
end | |
def show_flashes | |
flash.collect { |k,v| content_tag :div, v, :class => "flash #{k}" } | |
end | |
def link_to_active(name, url, html_options = {}) | |
html_options[:class] = "active" if current_page?(url) | |
link_to(name, url, html_options) | |
end | |
def link_to_section(cont, name, url, html_options = {}) | |
html_options[:class] = "active" if controller.controller_name == cont | |
html_options[:title] = name | |
link_to(name, url, html_options) | |
end | |
end | |
} | |
# Setup Capistrano | |
run "capify ." | |
file "config/deploy.rb", | |
%q{set :application, "my_app" | |
# Github options | |
default_run_options[:pty] = true | |
set :deploy_via, :remote_cache | |
set :repository, "[email protected]:uhlenbrock/#{application}.git" | |
set :scm, "git" | |
set :branch, "master" | |
set :git_enable_submodules, 1 | |
# set :scm_passphrase, | |
# Slicehost options | |
set :user, "user" | |
set :group, user | |
set :deploy_to, "/home/#{user}/sites/#{application}.com" | |
set :host, "127.0.0.1" | |
set :use_sudo, false | |
ssh_options[:port] = 31234 | |
# Deploy options | |
role :app, host | |
role :web, host | |
role :db, host, :primary => true | |
# Passenger 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 | |
task :after_update_code, :roles => :app do | |
run "cp #{shared_path}/config/database.yml #{release_path}/config/" | |
cleanup | |
end | |
task :after_setup, :roles => :app do | |
create_database_yml | |
create_logs_dir | |
end | |
# Inspired by http://shanesbrain.net/2007/5/30/managing-database-yml-with-capistrano-2-0 | |
# desc "create database.yml file on staging" | |
task :create_database_yml, :roles => :app do | |
config = ERB.new <<-EOF | |
base: &base | |
adapter: mysql | |
host: localhost | |
username: | |
password: | |
development: | |
database: #{application}_development | |
<<: *base | |
test: | |
database: #{application}_test | |
<<: *base | |
production: | |
database: #{application}_production | |
<<: *base | |
EOF | |
run "mkdir -p #{shared_path}/config" | |
put config.result, "#{shared_path}/config/database.yml" | |
end | |
task :create_logs_dir, :roles => :app do | |
run "mkdir -p #{deploy_to}/logs" | |
end | |
end | |
} | |
# Prepare .gitignore files | |
run 'touch tmp/.gitignore log/.gitignore vendor/.gitignore' | |
file '.gitignore', <<-CODE.gsub(/^\s*/,'') | |
.DS_Store | |
log/*.log | |
tmp/* | |
tmp/**/* | |
db/*.sqlite3 | |
public/system/**/* | |
public/stylesheets/all.css | |
public/javascripts/all.js | |
CODE | |
# git :init | |
# git :add => "." | |
# git :commit => "-a -m 'Initial commit'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment