Skip to content

Instantly share code, notes, and snippets.

@chrism
Created March 31, 2012 15:30
Show Gist options
  • Save chrism/2266221 to your computer and use it in GitHub Desktop.
Save chrism/2266221 to your computer and use it in GitHub Desktop.
Time saving template for Rails 3.2 projects using the standard configuration options
repo_name = app_name.gsub('_','-')
say "creating superuser for postgres with username : #{app_name}"
run "createuser #{app_name}"
say "initializing git repository"
git :init
say "adding .DS_Store & .env to .gitignore file"
append_to_file ".gitignore" do <<-TXT
# Ignore OS X generated .DS_Store files.
.DS_Store
# Ignore development environment variables.
.env
TXT
end
say "adding heroku gem for deployment"
gem("heroku")
say "adding thin gem as a server"
gem("thin")
say "adding foreman gem to manage processes"
gem("foreman")
say "adding guard-livereload for live reloading in development"
gem("guard-livereload", :group => "development")
say "creating .procfile for foreman to use"
add_file("Procfile")
append_to_file 'Procfile' do <<-TXT
web: bundle exec rails server thin -p $PORT
guard: guard start
TXT
end
say "creating .env to use for development environment variables"
add_file(".env")
if yes?("Do you want to use slim for templating?")
use_slim = true
say "adding slim gem for templating using slim"
gem("slim-rails")
end
if yes?("Do you want to use twitter boostrap?")
use_bootstrap = true
say "adding twitter bootstrap"
gem("twitter-bootstrap-rails", :group => "assets")
end
say "running bundle install... this may take a while"
run "bundle install"
say "creating Guardfile with guard init"
run "bundle exec guard init"
if use_bootstrap
run "rails g bootstrap:install"
if yes?("Do you want a fluid layout?")
run "rails g bootstrap:layout application fluid"
else
run "rails g bootstrap:layout application fixed"
end
say "removing old erb application template"
remove_file "app/views/layouts/application.html.erb"
say "removing broken default bootstrap application.html.slim"
remove_file "app/views/layouts/application.html.slim"
say "adding working application.html.slim"
add_file("app/views/layouts/application.html.slim")
append_to_file "app/views/layouts/application.html.slim" do <<-TXT
doctype html
html lang="en"
head
meta charset="utf-8"
title= content_for?(:title) ? yield(:title) : "#{app_name}"
= csrf_meta_tags
/! HTML5 shim for IE6-8 support of HTML elements
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
/! include styles
= stylesheet_link_tag "application", :media => "all"
body
.navbar.navbar-fixed-top
.navbar-inner
.container-fluid
a.btn.btn-navbar data-target=".nav-collapse" data-toggle="collapse"
span.icon-bar
span.icon-bar
span.icon-bar
= link_to "#{app_name}", "/", :class => "brand"
.container-fluid.nav-collapse
ul.nav
li= link_to "Link 1", "/path1"
li= link_to "Link 2", "/path2"
li= link_to "Link 3", "/path3"
.container-fluid
.row-fluid
.span3
.well.sidebar-nav
ul.nav.nav-list
li.nav-header Sidebar
li= link_to "Link 1", "/path1"
li= link_to "Link 2", "/path2"
li= link_to "Link 3", "/path3"
.span9
= yield
hr
footer
p &copy; Company 2012
/! include javascript at the end for better performance
= javascript_include_tag "application"
TXT
end
end
if yes?("Do you want to create a simple home controller?")
say "removing index.html"
remove_file 'public/index.html'
say "create a home controller and view"
if use_bootstrap
generate(:controller, "home index --skip-stylesheets")
else
generate(:controller, "home index")
end
say "set route to home#index now"
inject_into_file "config/routes.rb", :after => ".routes.draw do\n" do
" root :to => 'home#index'\n"
end
end
say "Updating README to default"
remove_file 'README.rdoc'
add_file("README.md")
append_to_file "README.md" do <<-TXT
# #{app_name}
Need to add a proper description here... ASAP.
TXT
end
say "creating & migrating database"
run "bundle exec rake db:create"
run "bundle exec rake db:migrate"
say "add files to git"
git :add => "."
say "first commit"
git :commit => "-m '#{repo_name} app generated using standard template'"
if yes?("Do you want to push this to a new public github repo called #{repo_name} now?")
run "gem install github"
if yes?("Are you using rbenv to manage ruby?")
run "rbenv rehash"
end
run "github create-from-local '#{repo_name}'"
end
if yes?("How about creating a heroku account called #{repo_name} now too?")
run "bundle exec heroku create #{repo_name} --stack cedar"
if yes?("...and push it live now?")
run "git push heroku master"
run "bundle exec heroku run rake db:migrate"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment