Skip to content

Instantly share code, notes, and snippets.

@foca
Created September 24, 2010 14:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save foca/595435 to your computer and use it in GitHub Desktop.
Save foca/595435 to your computer and use it in GitHub Desktop.
Rails template using Isolate for dependency management. Most of the code was blatantly stolen from jbarnette
run "rm public/index.html"
file "Isolate", <<-END
gem "rails", "3.0.1"
gem "haml", "3.0.22"
gem "sqlite3-ruby", "1.3.1"
env :development do
gem "haml-rails", "0.2"
end
env :development, :test do
gem "rspec-rails", "2.0.0"
gem "ruby-debug19", "0.11.6"
end
END
run "rm config/boot.rb"
file "config/boot.rb", <<-END
require "rubygems"
require "isolate/now"
END
run "rm Gemfile"
# Remove the lines that require bundler
application = File.read("config/application.rb")
run "rm config/application.rb"
file "config/application.rb", application.gsub(%r{(require 'rails/all').*(\n\nmodule)}m, '\1\nrequire "haml"\2')
inject_into_file "config/application.rb", <<-END, :after => /config\.filter_parameters.*$/
# Configure the generators
config.generators do |g|
g.template_engine :haml
g.stylesheets false
end
END
run "rm README"
file "README", <<-END
Install the `isolate` rubygem. Run `rake`. Follow the instructions. Enjoy.
END
run "rm config/database.yml"
file "config/database.yml", <<-END
development: &defaults
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test: &test
<<: *defaults
database: ":memory:"
production:
development
END
run "rm doc/README_FOR_APP"
file "doc/newb.txt", <<-END
FINISHED. What I did for you:
* Installed gems for development and testing.
* Created DBs using SQLite and the stock database.yml.
* Reset them with db/schema.rb.
* Ran the specs.
END
routes = File.read("config/routes.rb")
run "rm config/routes.rb"
file "config/routes.rb", routes.gsub(%r{(.*\.routes\.draw do\n).*(end$)}m, '\1\2')
rakefile "newb.rake", <<-END
Rake::Task["default"].prerequisites.replace %w(newb) +
Rake::Task["default"].prerequisites
task :newb do
next unless Dir["log/*.log"].empty?
puts "Looks like you're new here. Let's get crackin'."
%w(db:create:all db:schema:dump spec).each do |t|
Rake::Task[t].invoke
end
puts IO.read(Rails.root.join("doc/newb.txt"))
end
END
rakefile "replacements.rake", <<-END
Rake::TaskManager.class_eval do # HACK
def nuke(task_name)
@tasks.delete task_name.to_s
end
end
doctasks = Rake.application.tasks.map(&:name).select { |n| /doc/ =~ n }
doctasks.each { |n| Rake.application.nuke n }
END
initializer "attr_accessible.rb", <<-END
# Force all models into using attr_accessible
class ActiveRecord::Base
attr_accessible nil
end
END
run "rm app/views/layouts/application.html.erb"
file "app/views/layouts/application.haml", <<-END
!!! html5
%html(lang="en")
%head
%meta(charset="utf-8")
%title #{File.basename(Dir.pwd).titleize}
= csrf_meta_tag
%body
= yield
END
generate "rspec:install"
run "rm -r test"
run "mkdir -p spec/support"
file "spec/support/in_memory_db.rb", <<-END
silence_stream STDOUT do
require File.expand_path('../../db/schema', __FILE__)
end
END
run "rm public/javascripts/*"
run "rm log/*"
rake "default"
run "git init"
run "git add ."
run "git commit -m 'F1RST PO5T!!!1!'"
readme "#{Dir.pwd}/doc/newb.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment