Skip to content

Instantly share code, notes, and snippets.

@UserAd
Created October 14, 2009 10:47
Show Gist options
  • Save UserAd/209975 to your computer and use it in GitHub Desktop.
Save UserAd/209975 to your computer and use it in GitHub Desktop.
# newgit.rb
# from Joao Vitor
# Creates a new rails application using git
# Initializes the git based on the sake task published on
# http://gist.github.com/6750
# task 'git:rails:new_app', :needs => [ 'rails:rm_tmp_dirs', 'git:hold_empty_dirs' ]
# rails:rm_tmp_dirs
["./tmp/pids", "./tmp/sessions", "./tmp/sockets", "./tmp/cache"].each do |f|
run("rmdir ./#{f}")
end
# git:hold_empty_dirs
run("find . \\( -type d -empty \\) -and \\( -not -regex ./\\.git.* \\) -exec touch {}/.gitignore \\;")
# git:rails:new_app
git :init
initializer '.gitignore', <<-CODE
log/\\*.log
log/\\*.pid
db/\\*.db
db/\\*.sqlite3
db/schema.rb
tmp/\\*\\*/\\*
.DS_Store
doc/
config/database.yml
CODE
run "rm public/index.html"
run "cp config/database.yml config/database.yml.sample"
#add plugins as submodules
plugin 'authlogic', :git => 'git://github.com/binarylogic/authlogic.git', :submodule => true
plugin 'acl9', :git => 'git://github.com/be9/acl9.git', :submodule => true
plugin 'simple_captcha', :git => 'git://github.com/UserAd/simple_captcha.git', :submodule => true
plugin 'acts_as_commentable', :git => 'git://github.com/UserAd/acts_as_commentable.git', :submodule => true
plugin 'acts_as_rateable', :git => 'git://github.com/UserAd/acts_as_rateable.git', :submodule => true
plugin 'formtastic', :git => 'git://github.com/justinfrench/formtastic.git', :submodule => true
plugin 'jrails', :git => 'git://github.com/aaronchi/jrails.git', :submodule => true
plugin 'xilence', :git => 'git://github.com/inem/xilence.git', :submodule => true
plugin 'thinking-sphinx', :git => 'git://github.com/freelancing-god/thinking-sphinx.git', :submodule => true
plugin 'permalink_fu', :git => 'git://github.com/technoweenie/permalink_fu.git', :submodule => true
plugin 'paperclip', :git => 'git://github.com/thoughtbot/paperclip.git', :submodule => true
plugin 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :submodule => true
#Setup plugins
rake "simple_captcha:setup"
rake "jrails:js:install"
rake "jrails:js:scrub"
generate "acts_as_rateable_migration"
generate "comment"
#AUTHLOGIC
generate(:model, "user", "email:string", "crypted_password:string", "password_salt:string", "persistence_token:string")
file "app/models/user.rb", <<-END
class User < ActiveRecord::Base
acts_as_authentic
end
END
file "app/controllers/users_controller.rb", <<-END
class UsersController < ApplicationController
def index
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
flash[:notice] = "Registration successful."
redirect_to root_url
else
render :action => 'new'
end
end
def edit
@user = current_user
end
def update
@user = current_user
if @user.update_attributes(params[:user])
flash[:notice] = "Successfully updated profile."
redirect_to root_url
else
render :action => 'edit'
end
end
end
END
file "app/controllers/application_controller.rb", <<-END
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
filter_parameter_logging :password
helper_method :current_user
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.record
end
end
END
generate(:session, "user_session")
file "app/controllers/user_sessions.rb", <<-END
class UserSessionsController < ApplicationController
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Successfully logged in."
redirect_to root_url
else
render :action => 'new'
end
end
def destroy
@user_session = UserSession.find
@user_session.destroy
flash[:notice] = "Successfully logged out."
redirect_to root_url
end
end
END
route 'map.login "login", :controller => "user_sessions", :action => "new"'
route 'map.logout "logout", :controller => "user_sessions", :action => "destroy"'
route 'map.resources :user_sessions'
route 'map.resources :users'
route 'map.root :users'
#Git stuff
git :add => "."
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