Skip to content

Instantly share code, notes, and snippets.

@grotezo
Created Aug 31, 2010
Embed
What would you like to do?
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm -f public/javascripts/*"
run "rm public/robots.txt"
file "public/robots.txt", <<-FILE.gsub(/^ /, '')
User-agent: *
Disallow: /
FILE
# Download jquery
run "curl -L http://jqueryjs.googlecode.com/files/jquery-1.3.2.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
tmp/**/*
config/database.yml
db/*.sqlite3
END
# Install all gems
gem 'will_paginate', :version => '~> 2.3.11', :source => 'http://gemcutter.org'
gem 'authlogic', :source => 'http://gems.github.com'
gem 'json'
gem 'oauth'
gem 'oauth2'
gem 'authlogic-connect'
gem 'paperclip'
rake('gems:install')
# Set up sessions
rake('db:sessions:create')
# UserSessions
generate("session", "user_session")
generate("controller", "user_sessions")
file "app/controllers/user_sessions_controller.rb", <<-FILE
class UserSessionsController < ApplicationController
before_filter :anonymous_required, :only => [:new, :create]
before_filter :login_required, :only => :destroy
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = I18n.t("user_sessions.create.success")
redirect_back_or_default account_url
else
render :action => :new
end
end
def destroy
current_user_session.destroy
flash[:notice] = I18n.t("user_sessions.destroy.success")
redirect_back_or_default new_user_session_url
end
end
FILE
file "app/views/user_sessions/new.html.erb", <<-FILE
<h1>Login</h1>
<% form_for @user_session, :url => user_session_path do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :login %><br />
<%= f.text_field :login %>
</p>
<p>
<%= f.label :password %><br />
<%= f.password_field :password %>
</p>
<%= f.check_box :remember_me %><%= f.label :remember_me %><br />
<br />
<%= f.submit "Submit" %>
<% end %>
FILE
# User
generate("model", "user")
file "app/models/user.rb", <<-FILE
class User < ActiveRecord::Base
acts_as_authentic
attr_accessible :login, :email, :password, :password_confirmation
has_attached_file :picture, :styles => { :large => "200x200>" :thumb => "50x50#" }
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
end
FILE
generate("paperclip", "user", "picture")
# Application controller
file "app/controllers/application_controller.rb", <<-FILE
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
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, :password_confirmation
helper_method :current_user_session, :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.user
end
def login_required
unless current_user
store_location
flash[:notice] = "You must be logged in to access this page"
redirect_to new_user_session_url
return false
end
end
def anonymous_required
if current_user
store_location
flash[:notice] = "You must be logged out to access this page"
redirect_to account_url
return false
end
end
def store_location
session[:return_to] = request.request_uri
end
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
end
FILE
file "app/views/layouts/application.html.erb", <<-FILE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="<%= I18n.locale %>" lang="<%= I18n.locale %>">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<% if protect_against_forgery? -%>
<meta name="csrf-token" content="<%= form_authenticity_token %>" />
<meta name="csrf-name" content="authenticity_token" />
<% end -%>
<title></title>
<link rel="shortcut icon" href="/favicon.ico" />
<%= stylesheet_link_tag 'reset', 'global', :cache => true %>
<%= yield :head %>
</head>
<body>
<div id="header">
<% if current_user -%>
<%= link_to "Log Out", logout_path, :method => :delete %>
<% else %>
<%= link_to "Log In", login_path %>
<% end -%>
</div>
<%= yield %>
<%= yield :footer %>
<%= javascript_include_tag 'jquery', 'application', :cache => true %>
<% if RAILS_ENV == 'production' %>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("XX-XXXXXXX-X");
pageTracker._addOrganic("neti","query");
pageTracker._addOrganic("www.ee","query");
pageTracker._addOrganic("delfi","q");
pageTracker._addOrganic("go.mail.ru","q");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<% end %>
</body>
</html>
FILE
file "app/views/layouts/application.html.erb", <<-FILE
jQuery(document).ready(function($) {
$(document).ajaxSend(function(event, request, settings) {
if (settings.type == 'GET' || settings.type == 'get') return;
settings.data = settings.data || "";
settings.data += (settings.data ? "&" : "") + encodeURIComponent($('meta[name=csrf-name]').attr('content')) + "=" + encodeURIComponent($('meta[name=csrf-token]').attr('content'));
});
})(jQuery);
FILE
file "app/views/home/index.html.erb", <<-FILE
Hello
FILE
route 'root :to => "home#index"'
# Remove test directory
run 'rm -rf test'
# Initialize submodules
git :submodule => "init"
# Commit all work so far to the repository
git :add => '.'
git :commit => "-a -m 'Initial commit'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment