Skip to content

Instantly share code, notes, and snippets.

@andremedeiros
Created November 24, 2010 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andremedeiros/714181 to your computer and use it in GitHub Desktop.
Save andremedeiros/714181 to your computer and use it in GitHub Desktop.
# Helpers
def get_file(http_location, file)
run "curl -sL #{http_location}/#{file} > #{file}"
end
def app_name
@app_name ||= @root.split('/').last
end
# Remove Prototype defaults and grab jQuery + Rails adapter
inside 'public/javascripts' do
['controls', 'dragdrop', 'effects', 'prototype'].each do |file|
run "rm #{file}.js"
end
get_file 'http://github.com/rails/jquery-ujs/raw/master/src', 'rails.js'
run 'mkdir libs'
inside 'libs' do
get_file 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4', 'jquery.js'
get_file 'http://github.com/documentcloud/underscore/raw/master', 'underscore.js'
end
end
# Delete unnecessary files
run 'rm README'
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/robots.txt'
# Initialize gem file
run 'rm Gemfile'
file 'Gemfile', %{
source :rubygems
gem 'rails', '3.0.3'
gem 'mysql2'
gem 'haml-rails'
gem 'sass'
gem 'jammit', :git => 'git://github.com/documentcloud/jammit.git'
gem 'redis-store', :git => 'git://github.com/andremedeiros/redis-store.git'
gem 'jnunemaker-validatable', :git => 'git://github.com/jnunemaker/validatable.git'
group :development do
gem 'ruby-debug19'
gem 'rails3-generators'
end
group :test do
gem 'rspec'
gem 'rspec-rails', '~> 2.0.1'
gem 'cucumber'
end
}
# Install gems
run 'bundle install'
# Base assets
file 'config/assets.yml', %{
package_assets: on
embed_assets: on
compress_assets: on
gzip_assets: on
javascript_compressor: closure
template_function: _.template
javascripts:
global:
- public/javascripts/libs/jquery.js
- public/javascripts/libs/underscore.js
- public/javascripts/rails.js
- public/javascripts/application.js
stylesheets:
global:
- public/stylesheets/reset.css
- public/stylesheets/common.css
}
# Rspec
run 'rm -rf test'
generate 'rspec:install'
# Replace application template by HAML equivalent
run 'rm app/views/layouts/application.html.erb'
file 'app/views/layouts/application.html.haml', <<-END
!!!
%html
%head
%title Application
= include_stylesheets :global
= csrf_meta_tag
%body
= yield
= include_javascripts :global
END
# Create SASS initializer, stylesheets directory and default stylesheets
run 'mkdir app/stylesheets'
file 'app/stylesheets/reset.scss', <<-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, b, u, i, center, 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-size: 100%;
vertical-align: baseline;
background: transparent; }
body {
line-height: 1; }
ol, ul {
list-style: none; }
blockquote, q {
quotes: none; }
/* remember to define focus styles! */
:focus {
outline: 0; }
/* remember to highlight inserts somehow! */
ins {
text-decoration: none; }
del {
text-decoration: line-through; }
/* tables still need 'cellspacing="0"' in the markup */
table {
border-collapse: collapse;
border-spacing: 0; }
END
file 'app/stylesheets/common.scss', ''
initializer 'sass.rb', <<-END
Sass::Plugin.options[:template_location] = { 'app/stylesheets' => 'public/stylesheets' }
END
# Update config/application.rb for our templating engine, testing framework and added filtered parameters
gsub_file 'config/application.rb', " config.filter_parameters += [:password]", <<-END
config.filter_parameters << [:password, :password_confirmation]
# Configure generators values. Many other options are available, be sure to check the documentation.
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec, :fixture => false
end
END
# Update database.yml and create an example one
run 'rm config/database.yml'
file 'config/database.yml', <<-END
common: &COMMON
adapter: mysql2
host: localhost
development:
database: #{app_name}_development
<<: *COMMON
production:
database: #{app_name}_production
<<: *COMMON
test:
database: #{app_name}_test
<<: *COMMON
END
inside 'config' do
run 'cp database.yml database.yml.example'
end
# Setup .gitignore files
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 'rm .gitignore'
file '.gitignore', <<-END
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
*.swp
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment