Skip to content

Instantly share code, notes, and snippets.

@ddollar
Created July 20, 2009 15:51
Show Gist options
  • Save ddollar/150410 to your computer and use it in GitHub Desktop.
Save ddollar/150410 to your computer and use it in GitHub Desktop.
Rails Template
# Rails Template
require 'open-uri'
def download(from, to = from.split("/").last)
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
end
def commit_state(message)
git :add => "."
git :commit => "-am '#{message}'"
end
def github_plugin(plugin)
name = plugin.split('/').last
plugin name, :git => "git://github.com/#{plugin}.git"
end
# delete unnecessary files
run 'rm README'
run 'rm public/index.html'
run 'rm public/favicon.ico'
# set up git repository
git :init
# plugins
github_plugin 'ddollar/action_mailer_optional_tls'
github_plugin 'ddollar/jrails'
github_plugin 'ddollar/rack-debug'
github_plugin 'ddollar/shoebox'
github_plugin 'ddollar/tab_tab'
# set up gitignore and commit base state
file '.gitignore', <<-END
.DS_Store
.sass-cache/*
coverage/*
db/*.sqlite3
log/*
tmp/*
END
# environment
file 'config/environment.rb', <<-END
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
# gems
config.gem 'haml'
config.gem 'rspec-rails', :lib => false
config.gem 'rspec', :lib => false
# timezone
config.time_zone = 'UTC'
# debugging
# config.gem 'ruby-debug'
# config.middleware.use 'Rack::Debug'
end
END
generate :rspec
# add .gitignore files to hole open empty directories
run %{ find . -type d -empty xargs -I xxx touch xxx/.gitignore }
commit_state "base application with plugins and gems"
file 'app/views/layouts/application.html.haml', <<-END
!!! XML
!!! Strict
%html{ html_attrs }
%head
%title Default Title
= shoebox_styles
= shoebox_scripts
%body
= show_flash
#content
= yield(:content) || yield
END
file 'app/styles/application/_reset.sass', <<-END
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td
:margin 0
:padding 0
:border 0
:outline 0
:font-weight inherit
:font-style inherit
:font-size 100%
:font-family inherit
:vertical-align baseline
*:focus
:outline 10
body
:line-height 1
:color black
:background white
ol, ul
:list-style none
table
:border-collapse separate
:border-spacing 0
caption, th, td
:text-align left
:font-weight normal
blockquote:before, blockquote:after, q:before, q:after
:content ""
blockquote, q
:quotes "" ""
END
file 'app/styles/application/_util.sass', <<-END
=clearfix
&:after
content: "."
display: block
height: 0
clear: both
visibility: hidden
* html &
height: 1px
END
file 'app/controllers/application_controller.rb', <<-END
class ApplicationController < ActionController::Base
helper :all
protect_from_forgery
end
END
file 'app/helpers/application_helper.rb', <<-END
module ApplicationHelper
def show_flash
messages = [ :error, :warning, :success, :notice ].collect do |key|
unless flash[key].blank?
content_tag(:div, flash[key], :class => key)
end
end
content_tag(:div, messages.join("\n"), :id => 'flash') if messages.any?
end
end
END
# initializers
initializer 'mail.rb', <<-END
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:authentication => :plain,
:tls => true,
:address => "smtp.gmail.com",
:port => "587",
:domain => "example.org",
:user_name => "[email protected]",
:password => "password"
}
END
initializer 'date_time_formats.rb', <<-END
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:us => '%m/%d/%y',
:us_with_time => '%m/%d/%y, %l:%M %p',
:short_day => '%e %B %Y',
:long_day => '%A, %e %B %Y'
)
Date::DATE_FORMATS[:human] = "%B %e, %Y"
END
commit_state 'application files and initializers'
# static pages
file 'app/controllers/pages_controller.rb', <<-END
class PagesController < ApplicationController
rescue_from ActionView::MissingTemplate, :with => :invalid_page
def show
render params[:page]
end
def invalid_page
redirect_to root_path
end
end
END
file 'app/views/pages/welcome.html.haml', <<-END
%h1 Welcome to your default Rails application.
END
commit_state 'static pages'
# database
file 'config/database.yml', <<-END
development:
adapter: sqlite3
database: db/development.sqlite3
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
timeout: 5000
END
commit_state 'configuration files'
# simple default routing
file 'config/routes.rb', <<-END
ActionController::Routing::Routes.draw do |map|
map.pages 'pages/:page', :controller => 'pages', :action => 'show'
map.root :controller => 'pages', :action => 'welcome'
end
END
commit_state 'routing'
# jquery
download 'http://jqueryjs.googlecode.com/files/jquery-1.3.2.js',
'app/scripts/application/jquery.js'
commit_state 'jquery'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment