Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Created March 8, 2012 21:19
Show Gist options
  • Save krainboltgreene/2003506 to your computer and use it in GitHub Desktop.
Save krainboltgreene/2003506 to your computer and use it in GitHub Desktop.
An rails project scaffold gem
# Requirements:
# - The 'session' gem
# - A directory called 'rgen' and the files listed with copy, in the exact places listed
require 'session'
def run(command)
@session ||= Session::Shell.new
stdout, stderr = @session.execute command
puts stdout unless stdout.empty?
puts stderr unless stderr.empty?
end
def copy(path)
"Gemfile"
"lib/tasks/release.rake"
path = if path.include?("/") then path else ("/" + path) end.split("/")
name = path.pop
content = File.read File.join "rgen", path, name
open File.join($app_name, path, name), "w" do |file|
file.write content
end
run "git add . && git commit -am 'Adding the #{name} file'"
end
print "What is your application's name? "; $app_name = gets.chomp!.gsub(/(\W)/, '_')
run "source ~/.zshrc"
run "rvm --create mri@#{$app_name}"
run "gem install rails"
run "rails new #{$app_name} --skip-gemfile --skip-bundle --skip-active-record --skip-test-unit"
run "cd #{$app_name}"
run "git init && git add . && git commit -am 'Initial application skeleton'"
copy "vendor/assets/stylesheets/bootstrap.css"
copy "vendor/assets/stylesheets/bootstrap-responsive.css"
copy "vendor/assets/javascripts/bootstrap.js"
copy "vendor/assets/javascripts/modernizr.js"
copy "vendor/assets/javascripts/prefixfree.js"
copy "vendor/assets/javascripts/underscore.js"
run "mkdir vendor/assets/stylesheets/jquery"
copy "vendor/assets/stylesheets/jquery/mobile.css"
run "mkdir vendor/assets/javascripts/jquery"
copy "vendor/assets/javascripts/jquery/mobile.js"
run "mkdir vendor/assets/images"
copy "vendor/assets/images/glyphicons-halflings-white.png"
copy "vendor/assets/images/glyphicons-halflings.png"
copy "Gemfile"
copy "lib/tasks/release.rake"
run "rvm --rvmrc mri@#{$app_name}"
run "bundle install --binstubs"
run "git add . && git commit -am 'Adding the lock file'"
run "rails generate mongoid:config"
run "git add . && git commit -am 'Adding in the mongoid.yml file'"
run "rails generate rspec:install"
run "git add . && git commit -am 'Adding the rspec generated files'"
run "rails generate draper:install"
run "git add . && git commit -am 'Adding the draper generated files'"
run "rails generate simple_form:install --bootstrap "
run "git add . && git commit -am 'Adding the simple_form generated files'"
run "rails generate sorcery:install --model Account remember_me"
run "git add . && git commit -am 'Adding the sorcery generated files'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment