Skip to content

Instantly share code, notes, and snippets.

@inem
Created January 31, 2009 06:18
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 inem/55456 to your computer and use it in GitHub Desktop.
Save inem/55456 to your computer and use it in GitHub Desktop.
# Link to local copy of edge rails
# inside('vendor') { run 'ln -s ~/dev/rails/rails rails' }
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
#run "rm -f public/javascripts/*"
# Download JQuery
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js > public/javascripts/jquery.js"
# Set up git repository
git :init
git :add => '.'
# Copy database.yml for distribution use
run "cp config/database.yml config/database.yml.example"
# Set up .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}
file '.gitignore', <<-END
.DS_Store
log/*.log
log/*.pid
tmp/**/*
config/database.yml
db/*.sqlite3
doc/api
doc/app
END
#plugins
plugin 'rspec', :git => 'git://github.com/dchelimsky/rspec.git', :submodule => true
plugin 'rspec-rails', :git => 'git://github.com/dchelimsky/rspec-rails.git', :submodule => true
plugin 'asset_packager', :git => 'git://github.com/sbecker/asset_packager.git', :submodule => true
plugin 'aasm', :git => 'git://github.com/rubyist/aasm.git', :submodule => true
plugin 'haml_scaffold', :git => 'git://github.com/cnaths/haml_scaffold.git', :submodule => true
plugin 'resource_this', :git => 'git://github.com/jnewland/resource_this.git', :submodule => true
#http://video.railstips.org/giving-mailers-observers-and-sweepers-their-own-space/
run("mkdir -p app/observers app/sweepers app/mailers/views")
file 'app/mailers/application_mailer.rb', <<-CODE
class ApplicationMailer < ActionMailer::Base
self.template_root = File.join(RAILS_ROOT, 'app', 'mailers', 'views')
end
CODE
file 'app/mailers/user_mailer.rb', <<-CODE
class UserMailer < ApplicationMailer
def invitation(user)
subject 'Invitation'
from "do-not-reply@foobar.com"
recipients user.email
body :user => user
end
end
CODE
file 'app/observers/user_observer.rb', <<-CODE
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserMailer.deliver_invitation(user)
end
end
CODE
#environment.rb
file 'config/environment.rb', <<-CODE
# RAILS_GEM_VERSION = '2.1.1' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
config.time_zone = 'UTC'
config.action_controller.session = {
:session_key => "_app_session",
:secret => "#{(1..36).map { |x| (65 + rand(26)).chr }.join}"
}
%w(observers sweepers mailers).each do |dir|
config.load_paths << "\#\{RAILS_ROOT\}/app/\#\{dir\}"
end
config.active_record.observers = :user_observer
end
CODE
#gems
gem 'haml'
gem 'authlogic'
gem 'cucumber'
gem 'webrat'
gem 'rack', :version => '~>0.9.0'
gem 'sqlite3-ruby', :lib => 'sqlite3'
rake("gems:install", :sudo => true)
run('haml --rails .')
#Authlogic stuff
file 'db/migrate/001_create_users.rb', <<-CODE
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :login, :null => false
t.string :crypted_password, :null => false
t.string :password_salt, :null => false # not needed if you are encrypting your pw instead of using a hash algorithm.
t.string :persistence_token, :null => false
t.string :single_access_token, :null => false # optional, see the tokens section below.
t.string :perishable_token, :null => false # optional, see the tokens section below.
t.integer :login_count, :null => false, :default => 0 # optional, this is a "magic" column, see the magic columns section below
end
end
def self.down
drop_table :posts
end
end
CODE
file 'app/models/user.rb', <<-CODE
class User < ActiveRecord::Base
end
CODE
rake("db:migrate")
generate(:session, "user_session")
file 'app/models/user.rb', <<-CODE
class User < ActiveRecord::Base
acts_as_authentic # for options see documentation: Authlogic::ORMAdapters::ActiveRecordAdapter::ActsAsAuthentic::Config
end
CODE
# fixing application_controller
run("mv app/controllers/application.rb app/controllers/application_controller.rb")
generate("rspec")
generate("cucumber")
#webrat support for features
file 'features/support/env.rb', <<-CODE
# Sets up the Rails environment for Cucumber
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/rails/world'
#require 'cucumber/formatters/unicode' # Comment out this line if you don't want Cucumber Unicode support
Cucumber::Rails.use_transactional_fixtures
require 'webrat/rails'
# Comment out the next two lines if you're not using RSpec's matchers (should / should_not) in your steps.
require 'cucumber/rails/rspec'
require 'webrat/rspec-rails'
require "webrat"
Webrat.configure do |config|
config.mode = :rails
end
CODE
git :commit => "-a -m 'Setting up a new rails app. Copy config/database.yml.sample to config/database.yml and customize.'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment