Skip to content

Instantly share code, notes, and snippets.

@melito
Created June 2, 2011 07:31
Show Gist options
  • Save melito/1004067 to your computer and use it in GitHub Desktop.
Save melito/1004067 to your computer and use it in GitHub Desktop.
run "rm Gemfile"
file 'Gemfile', <<-FILE
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'rake', '~> 0.8.7'
gem 'devise', '~> 1.2.0'
gem 'cancan'
gem 'will_paginate', '~> 3.0.pre2'
gem 'tzinfo'
gem 'hoptoad_notifier'
group :staging, :production do
gem 'mysql'
end
group :development, :test do
gem 'test-unit', '= 2.0.9', :require => 'test/unit'
gem 'sqlite3-ruby', :require => 'sqlite3'
# This is for gems without generators - like factory girl
gem 'rails3-generators'
# These help with tests
gem 'shoulda' # This is a cool library for easily writing boring tests
gem 'shoulda-matchers' # These are handy matchers from the above library
gem 'factory_girl_rails' # This lets us define objects using factories
gem 'faker' # This lets us easily define fake data in our factories
# This makes our tests colorful
gem 'turn'
gem 'ansi'
# Coffeescript
gem 'therubyracer'
# Growl notifications for testing
gem 'growl'
# Trying this out for now
gem 'guard', '>= 0.3.0'
gem 'guard-livereload'
gem 'guard-coffeescript'
gem 'guard-test'
gem 'rb-fsevent'
end
FILE
current_ruby = %x{rvm list}.match(/^=>\s+(.*)\s\[/)[1].strip
run "rvm gemset create #{app_name}"
run "rvm #{current_ruby}@#{app_name} gem install bundler --no-rdoc --no-ri"
run "rvm #{current_ruby}@#{app_name} -S bundle install"
file ".rvmrc", <<-END
rvm use #{current_ruby}@#{app_name}
END
# Clean up rails defaults
remove_file 'public/index.html'
remove_file 'rm public/images/rails.png'
inside "public" do
run "git clone http://github.com/paulirish/html5-boilerplate.git"
run 'cp -R html5-boilerplate/* .'
run 'mv js/* javascripts/'
run 'mv javascripts/libs/* javascripts/'
run 'mv css/* stylesheets/'
run 'rm -Rf js css html5-boilerplate'
run 'mv index.html example-html5b.html'
run 'rm README.md'
inside "javascripts" do
FileUtils.rm_rf %w(controls.js dragdrop.js effects.js prototype.js rails.js)
run "wget https://github.com/rails/jquery-ujs/raw/master/src/rails.js --no-check-certificate"
run "mv jquery-*.min.js jquery.js"
run "mv modernizr-* modernizr.js"
end
inside "stylesheets" do
run "wget 'http://grids.heroku.com/grid.css?column_width=20&column_amount=24&gutter_width=20' -O 960.gs"
end
end
# Layout
run 'rm app/views/layouts/application.html.erb'
file 'app/views/layouts/application.html.erb', <<-FILE
<!doctype html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>#{app_name}</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Mobile viewport optimized: j.mp/bplateviewport -->
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag 'jquery', 'rails', 'modernizr' %>
<%= csrf_meta_tag %>
</head>
<body>
<div id="container">
<header>
</header>
<div id="main">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</div>
<footer>
</footer>
</div>
<!-- end of #container -->
<!-- Javascript at the bottom for fast page loading -->
<script src="/javascripts/plugins.js?v=1"></script>
<script src="/javascripts/script.js?v=1"></script>
<!--[if lt IE 7 ]>
<script src="/javascripts/dd_belatedpng.js?"></script>
<script>
DD_belatedPNG.fix('img, .png_bg'); //fix any <img> or .png_bg background-images
</script>
<![endif]-->
<%= render :partial => 'shared/yahoo_profiling' %>
<%= render :partial => 'shared/google_analytics' %>
</body>
</html>
FILE
run "mkdir -p app/views/shared"
file 'app/views/shared/_yahoo_profiling.html.erb', <<-FILE
<% if Rails.env == 'development' %>
<!-- yui profiler and profileviewer - remove for production -->
<script src="/javascripts/profiling/yahoo-profiling.min.js"></script>
<script src="/javascripts/profiling/config.js?v=1"></script>
<!-- end profiling code -->
<% end %>
FILE
file 'app/views/shared/_google_analytics.html.erb', <<-FILE
<% if Rails.env == 'production' %>
<!-- asynchronous google analytics: mathiasbynens.be/notes/async-analytics-snippet -->
<script>
var _gaq = [['_setAccount', '<%= GOOGLE_ANALYTICS_TOKEN %>'], ['_trackPageview']];
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = ('https:' == location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
s.parentNode.insertBefore(g, s);
})(document, 'script');
</script>
<% end %>
FILE
inject_into_file 'config/environments/production.rb', :after => 'end' do
<<-eos
GOOGLE_ANALYTICS_TOKEN = "UA-123456"
eos
end
# Add factory_girl into the thing
inject_into_file 'config/application.rb', :after => "config.filter_parameters += [:password]" do
<<-eos
# Customize generators
config.generators do |g|
g.fixture_replacement :factory_girl
end
eos
end
run 'mkdir -p test/shoulda_macros'
file 'test/shoulda_macros/anafm.rb', %q{
module AcceptsNestedAttributesForMacros
def should_accept_nested_attributes_for(*attr_names)
klass = self.name.gsub(/Test$/, '').constantize
context "#{klass}" do
attr_names.each do |association_name|
should "accept nested attrs for #{association_name}" do
assert klass.instance_methods.include?(\"#{association_name}_attributes="),
"#{klass} does not accept nested attributes for #{association_name}"
end
end
end
end
end
class ActiveSupport::TestCase
extend AcceptsNestedAttributesForMacros
end
}
# Update the test helper
run "rm test/test_helper.rb"
file "test/test_helper.rb", <<-FILE
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require File.join(File.dirname(__FILE__), 'shoulda_macros', 'anafm')
module #{app_name.camelize}ControllerHelpers
# Put helpers for your controllers in here
# Ex:
# def login_as_admin
# @user = Factory.create(:admin_user)
# sign_in @user
# end
end
class ActiveSupport::TestCase
end
class ActionController::TestCase
include Devise::TestHelpers
include #{app_name.camelize}ControllerHelpers
end
FILE
file 'Guardfile', %q{
guard 'test' do
watch(%r{app/models/(.+)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
watch(%r{app/controllers/(.+)\.rb}) { |m| "test/functional/#{m[1]}_test.rb" }
watch(%r{app/views/.+\.rb}) { "test/integration" }
watch(%r{lib/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
watch(%r{test/.+_test.rb})
watch('app/controllers/application_controller.rb') { ["test/functional", "test/integration"] }
watch('test/test_helper.rb') { "test" }
end
guard 'coffeescript', :output => 'public/javascripts/compiled' do
watch('^app/coffeescripts/(.*)\.coffee')
end
guard 'coffeescript', :output => 'spec/javascripts' do
watch('^spec/coffeescripts/(.*)\.coffee')
end
guard 'livereload', :apply_js_live => false do
watch('^spec/javascripts/.+\.js$')
watch('^public/javascripts/compiled/.+\.js$')
end
guard 'livereload' do
watch(%r{app/.+\.(erb|haml|jst)})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{.*\.(sass|scss$)}) { 'css' }
watch(%r{config/locales/.+\.yml})
end
}
# authentication and authorization setup
generate "devise:install"
generate "devise user"
generate "devise:views"
rake "db:migrate"
generate "cancan:ability"
rake "db:create", :env => 'development'
rake "db:create", :env => 'test'
rake "db:migrate"
# create a git repo
git :init
git :add => '.'
git :commit => '-a -m "new rails app"'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment