Created
July 31, 2009 16:29
-
-
Save neilmiddleton/159304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download, from_repo, and commit_state methods swiped from | |
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb | |
require 'open-uri' | |
def download(from, to = from.split("/").last) | |
#run "curl -s -L #{from} > #{to}" | |
file to, open(from).read | |
rescue | |
puts "Can't get #{from} - Internet down?" | |
exit! | |
end | |
def from_repo(github_user, from, to = from.split("/").last) | |
download("http://github.com/#{github_user}/rails-template/raw/master/#{from}", to) | |
end | |
def commit_state(comment) | |
git :add => "." | |
git :commit => "-am '#{comment}'" | |
end | |
# Piston methods out of my own head | |
# Piston locking support with git requires Piston 2.0.3+ | |
# Use Piston to install and lock a plugin: | |
# piston_plugin 'stuff', :git => 'git://github.com/whoever/stuff.git' | |
# Use Piston to install a plugin without locking: | |
# piston_plugin 'stuff', :git => 'git://github.com/whoever/stuff.git', :lock => false | |
def piston_plugin(name, options={}) | |
lock = options.fetch(:lock, true) | |
log "plugin installed #{'and locked ' if lock}with Piston:", name | |
if options[:git] || options[:svn] | |
in_root do | |
run("piston import #{options[:svn] || options[:git]} vendor/plugins/#{name}") | |
run("piston lock vendor/plugins/#{name}") if lock | |
commit_state("Added pistoned #{name}") | |
end | |
else | |
log "! no git or svn provided for #{name}. skipping..." | |
end | |
end | |
# Use Piston to install and lock current Rails edge (master): | |
# piston_rails | |
# Use Piston to install but not lock current Rails edge (master): | |
# piston_rails :lock => false | |
# Use Piston to install and lock edge of a specific Rails branch (WARNING - hangs with Piston 2.0.3): | |
#piston_rails :branch => "2-3-stable" | |
# Use Piston to install but not lock edge of a specific Rails branch: | |
# piston_rails, :branch => "2-3-stable", :lock => false | |
def piston_rails(options={}) | |
lock = options.fetch(:lock, true) | |
log "rails installed #{'and locked ' if lock}with Piston", options[:branch] | |
if options[:branch] | |
branch = options[:branch] =~ /^origin\// ? options[:branch] : "origin/#{options[:branch]}" | |
in_root do | |
run("piston import --commit #{branch} git://github.com/rails/rails.git vendor/rails") | |
run("piston lock vendor/rails") if lock | |
end | |
else | |
in_root do | |
run("piston import git://github.com/rails/rails.git vendor/rails") | |
run("piston lock vendor/rails") if lock | |
end | |
end | |
end | |
current_app_name = File.basename(File.expand_path(root)) | |
# Delete unnecessary files | |
run "rm README" | |
run "rm public/index.html" | |
run "rm public/favicon.ico" | |
# Set up git repository | |
# must do before running piston | |
git :init | |
# plugins | |
piston_plugin 'admin_data', | |
:git => 'git://github.com/neerajdotname/admin_data.git' | |
piston_plugin 'db-populate', | |
:git => 'git://github.com/ffmike/db-populate.git' | |
piston_plugin 'hoptoad', | |
:git => 'git://github.com/thoughtbot/hoptoad_notifier.git' | |
piston_plugin 'jrails', | |
:git => 'git://github.com/aaronchi/jrails.git' | |
plugin 'newrelic_rpm', | |
:svn => 'http://newrelic.rubyforge.org/svn/newrelic_rpm' | |
piston_plugin 'paperclip', | |
:git => 'git://github.com/thoughtbot/paperclip.git' | |
piston_plugin 'rack-bug', | |
:git => 'git://github.com/brynary/rack-bug.git' | |
piston_plugin 'shmacros', | |
:git => 'git://github.com/maxim/shmacros.git' | |
piston_plugin 'stringex', | |
:git => 'git://github.com/rsl/stringex.git' | |
# gems | |
gem 'authlogic', | |
:version => '~> 2.0' | |
gem 'mislav-will_paginate', | |
:version => '~> 2.2', | |
:lib => 'will_paginate', | |
:source => 'http://gems.github.com' | |
gem "binarylogic-searchlogic", | |
:lib => 'searchlogic', | |
:source => 'http://gems.github.com', | |
:version => '~> 2.0' | |
# development only | |
gem "cwninja-inaction_mailer", | |
:lib => 'inaction_mailer/force_load', | |
:source => 'http://gems.github.com', | |
:env => 'development' | |
gem "haml" | |
# assume gems are already on dev box, so don't install | |
# rake("gems:install", :sudo => true) | |
# Set up gitignore and commit base state | |
file '.gitignore', <<-END | |
log/*.log | |
tmp/**/* | |
.DS\_Store | |
.DS_Store | |
db/test.sqlite3 | |
db/development.sqlite3 | |
/log/*.pid | |
/coverage/* | |
public/system/* | |
.idea/* | |
tmp/metric_fu/* | |
tmp/sent_mails/* | |
END | |
commit_state "Base application with plugins and gems" | |
# some files for app | |
#download "http://livevalidation.com/javascripts/src/1.3/livevalidation_prototype.js", "public/javascripts/livevalidation.js" | |
file 'app/views/layouts/_flashes.html.erb', <<-END | |
<div id="flash"> | |
<% flash.each do |key, value| -%> | |
<div id="flash_<%= key %>"><%=h value %></div> | |
<% end -%> | |
</div> | |
END | |
file 'app/views/layouts/application.html.erb', <<-END | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> | |
<title><%= @page_title || controller.action_name %></title> | |
<%= stylesheet_link_tag 'application', :media => 'all' %> | |
<%= yield :head %> | |
</head> | |
<body> | |
<%= render :partial => 'layouts/flashes' -%> | |
<%= yield %> | |
</body> | |
</html> | |
END | |
file 'public/stylesheets/application.css', <<-END | |
/* @group Browser Reset */ | |
html, body { | |
font-size: 12.5px; } | |
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { | |
margin: 0; | |
padding: 0; | |
border: 0; | |
outline: 0; | |
font-family: helvetica, verdana, arial, sans-serif; | |
font-style: inherit; | |
font-weight: inherit; | |
line-height: 1.25em; | |
text-align: left; | |
vertical-align: baseline; } | |
html { | |
overflow-y: scroll; } | |
a img, :link img, :visited img { | |
border: 0; } | |
strong { | |
font-weight: bold; } | |
em { | |
font-style: italic; } | |
table { | |
border-collapse: collapse; | |
border-spacing: 0; } | |
ul { | |
list-style: none; } | |
/* @end */ | |
END | |
file 'app/controllers/application_controller.rb', <<-END | |
# 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 | |
# make methods available to views | |
helper_method :logged_in?, :admin_logged_in?, :current_user_session, :current_user | |
# See ActionController::RequestForgeryProtection for details | |
protect_from_forgery | |
# See ActionController::Base for details | |
# Uncomment this to filter the contents of submitted sensitive data parameters | |
# from your application log (in this case, all fields with names like "password"). | |
filter_parameter_logging :password, :confirm_password, :password_confirmation, :creditcard | |
def logged_in? | |
!current_user_session.nil? | |
end | |
def admin_required | |
unless current_user && current_user.admin? | |
flash[:error] = "Sorry, you don't have access to that." | |
redirect_to root_url and return false | |
end | |
end | |
def admin_logged_in? | |
logged_in? && current_user.admin? | |
end | |
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 require_user | |
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 require_no_user | |
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 | |
END | |
file 'app/helpers/application_helper.rb', <<-END | |
# Methods added to this helper will be available to all templates in the application. | |
module ApplicationHelper | |
# Block method that creates an area of the view that | |
# is only rendered if the request is coming from an | |
# anonymous user. | |
def anonymous_only(&block) | |
if !logged_in? | |
block.call | |
end | |
end | |
# Block method that creates an area of the view that | |
# only renders if the request is coming from an | |
# authenticated user. | |
def authenticated_only(&block) | |
if logged_in? | |
block.call | |
end | |
end | |
# Block method that creates an area of the view that | |
# only renders if the request is coming from an | |
# administrative user. | |
def admin_only(&block) | |
role_only("admin", &block) | |
end | |
private | |
def role_only(rolename, &block) | |
if not current_user.blank? and current_user.has_role?(rolename) | |
block.call | |
end | |
end | |
end | |
END | |
# initializers | |
initializer 'requires.rb', <<-END | |
Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f| | |
require f | |
end | |
END | |
initializer 'admin_data.rb', <<-END | |
ADMIN_DATA_VIEW_AUTHORIZATION = Proc.new { |controller| controller.send("admin_logged_in?") } | |
ADMIN_DATA_UPDATE_AUTHORIZATION = Proc.new { |controller| return false } | |
END | |
initializer 'mail.rb', <<-END | |
ActionMailer::Base.delivery_method = :smtp | |
ActionMailer::Base.smtp_settings = { | |
:address => "mail.monochrome.co.uk", | |
:port => "25", | |
:user_name => "[email protected]", | |
:password => "xxxx" | |
} | |
END | |
initializer 'date_time_formats.rb', <<-END | |
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( | |
:uk => '%d/%m/%y', | |
:uk_with_time => '%d/%m/%y, %l:%M %p', | |
:short_day => '%e %B %Y', | |
:long_day => '%A, %e %B %Y' | |
) | |
Date::DATE_FORMATS[:human] = "%B %e, %Y" | |
END | |
commit_state "application files and initializers" | |
# error tracking | |
file 'config/initializers/hoptoad.yml', <<-END | |
HoptoadNotifier.configure do |config| | |
config.api_key = 'b63a43c2c278c372ff34f2a90661ee15' | |
config.environment_filters << 'rack-bug.*' | |
end | |
END | |
# performance | |
file 'config/newrelic.yml', <<-END | |
# | |
# This file configures the NewRelic RPM Agent, NewRelic RPM monitors Rails | |
# applications with deep visibility and low overhead. For more information, | |
# visit www.newrelic.com. | |
# | |
# This configuration file is custom generated for Lark Group Lite Account | |
# | |
# here are the settings that are common to all environments | |
common: &default_settings | |
# ============================== LICENSE KEY =============================== | |
# You must specify the licence key associated with your New Relic account. | |
# This key binds your Agent's data to your account in the New Relic RPM service. | |
license_key: '8b18c4035aab5437afdbe7c12244e7f5ff95631c' | |
# Application Name | |
# Set this to be the name of your application as you'd like it show up in RPM. | |
# RPM will then auto-map instances of your application into a RPM "application" | |
# on your home dashboard page. This setting does not prevent you from manually | |
# defining applications. | |
app_name: #{current_app_name} | |
# the 'enabled' setting is used to turn on the NewRelic Agent. When false, | |
# your application is not instrumented and the Agent does not start up or | |
# collect any data; it is a complete shut-off. | |
# | |
# when turned on, the agent collects performance data by inserting lightweight | |
# tracers on key methods inside the rails framework and asynchronously aggregating | |
# and reporting this performance data to the NewRelic RPM service at NewRelic.com. | |
# below. | |
enabled: false | |
# The newrelic agent generates its own log file to keep its logging information | |
# separate from that of your application. Specify its log level here. | |
log_level: info | |
# The newrelic agent communicates with the RPM service via http by default. | |
# If you want to communicate via https to increase security, then turn on | |
# SSL by setting this value to true. Note, this will result in increased | |
# CPU overhead to perform the encryption involved in SSL communication, but this | |
# work is done asynchronously to the threads that process your application code, so | |
# it should not impact response times. | |
ssl: false | |
# Set your application's Apdex threshold value with the 'apdex_t' setting, in seconds. The | |
# apdex_t value determines the buckets used to compute your overall Apdex score. Requests | |
# that take less than apdex_t seconds to process will be classified as Satisfying transactions; | |
# more than apdex_t seconds as Tolerating transactions; and more than four times the apdex_t | |
# value as Frustrating transactions. For more | |
# about the Apdex standard, see http://support.newrelic.com/faqs/general/apdex | |
apdex_t: 0.5 | |
# Proxy settings for connecting to the RPM server. | |
# | |
# If a proxy is used, the host setting is required. Other settings are optional. Default | |
# port is 8080. | |
# | |
# proxy_host: hostname | |
# proxy_port: 8080 | |
# proxy_user: | |
# proxy_pass: | |
# Tells transaction tracer and error collector (when enabled) whether or not to capture HTTP params. | |
# When true, the RoR filter_parameters mechanism is used so that sensitive parameters are not recorded | |
capture_params: false | |
# Transaction tracer captures deep information about slow | |
# transactions and sends this to the RPM service once a minute. Included in the | |
# transaction is the exact call sequence of the transactions including any SQL statements | |
# issued. | |
transaction_tracer: | |
# Transaction tracer is enabled by default. Set this to false to turn it off. This feature | |
# is only available at the Silver and above product levels. | |
enabled: true | |
# When transaction tracer is on, SQL statements can optionally be recorded. The recorder | |
# has three modes, "off" which sends no SQL, "raw" which sends the SQL statement in its | |
# original form, and "obfuscated", which strips out numeric and string literals | |
record_sql: obfuscated | |
# Threshold in seconds for when to collect stack trace for a SQL call. In other words, | |
# when SQL statements exceed this threshold, then capture and send to RPM the current | |
# stack trace. This is helpful for pinpointing where long SQL calls originate from | |
stack_trace_threshold: 0.500 | |
# Error collector captures information about uncaught exceptions and sends them to RPM for | |
# viewing | |
error_collector: | |
# Error collector is enabled by default. Set this to false to turn it off. This feature | |
# is only available at the Silver and above product levels | |
enabled: true | |
# Tells error collector whether or not to capture a source snippet around the place of the | |
# error when errors are View related. | |
capture_source: true | |
# To stop specific errors from reporting to RPM, set this property to comma separated | |
# values | |
# | |
#ignore_errors: ActionController::RoutingError, ... | |
# override default settings based on your application's environment | |
# NOTE if your application has other named environments, you should | |
# provide newrelic conifguration settings for these enviromnents here. | |
development: | |
<<: *default_settings | |
# turn off communication to RPM service in development mode. | |
# NOTE: for initial evaluation purposes, you may want to temporarily turn | |
# the agent on in development mode. | |
enabled: false | |
# When running in Developer Mode, the New Relic Agent will present | |
# performance information on the last 100 transactions you have | |
# executed since starting the mongrel. to view this data, go to | |
# http://localhost:3000/newrelic | |
developer: true | |
test: | |
<<: *default_settings | |
# it almost never makes sense to turn on the agent when running unit, functional or | |
# integration tests or the like. | |
enabled: false | |
test2: | |
<<: *default_settings | |
# it almost never makes sense to turn on the agent when running unit, functional or | |
# integration tests or the like. | |
enabled: false | |
test3: | |
<<: *default_settings | |
# it almost never makes sense to turn on the agent when running unit, functional or | |
# integration tests or the like. | |
enabled: false | |
test4: | |
<<: *default_settings | |
# it almost never makes sense to turn on the agent when running unit, functional or | |
# integration tests or the like. | |
enabled: false | |
# Turn on the agent in production for 24x7 monitoring. NewRelic testing shows | |
# an average performance impact of < 5 ms per transaction, you you can leave this on | |
# all the time without incurring any user-visible performance degredation. | |
production: | |
<<: *default_settings | |
enabled: true | |
# many applications have a staging environment which behaves identically to production. | |
# Support for that environment is provided here. By default, the staging environment has | |
# the agent turned on. | |
staging: | |
<<: *default_settings | |
enabled: true | |
app_name: #{current_app_name} (Staging) | |
END | |
file 'db/populate/01_sample_seed.rb', <<-END | |
# Model.create_or_update(:id => 1, :name => 'sample') | |
# User db/populate/development/01_file.rb for development-only data | |
END | |
commit_state "configuration files" | |
# authlogic setup | |
file 'app/controllers/password_resets_controller.rb', <<-END | |
class PasswordResetsController < ApplicationController | |
before_filter :load_user_using_perishable_token, :only => [:edit, :update] | |
before_filter :require_no_user | |
def new | |
@page_title = "Forgot Password?" | |
end | |
def create | |
@user = User.find_by_email(params[:email]) | |
if @user | |
@user.deliver_password_reset_instructions! | |
flash[:notice] = "Instructions to reset your password have been emailed to you. " + | |
"Please check your email." | |
redirect_to root_url | |
else | |
flash[:notice] = "No user was found with that email address" | |
render :action => :new | |
end | |
end | |
def edit | |
@page_title = "Select a New Password" | |
end | |
def update | |
@user.password = params[:user][:password] | |
@user.password_confirmation = params[:user][:password_confirmation] | |
if @user.save | |
flash[:notice] = "Password successfully updated" | |
redirect_to account_url | |
else | |
render :action => :edit | |
end | |
end | |
private | |
def load_user_using_perishable_token | |
@user = User.find_using_perishable_token(params[:id]) | |
unless @user | |
flash[:notice] = "We're sorry, but we could not locate your account." + | |
"If you are having issues try copying and pasting the URL " + | |
"from your email into your browser or restarting the " + | |
"reset password process." | |
redirect_to root_url | |
end | |
end | |
end | |
END | |
file 'app/controllers/user_sessions_controller.rb', <<-END | |
class UserSessionsController < ApplicationController | |
before_filter :require_no_user, :only => [:new, :create] | |
before_filter :require_user, :only => :destroy | |
def new | |
@page_title = "Login" | |
@user_session = UserSession.new | |
end | |
def create | |
@user_session = UserSession.new(params[:user_session]) | |
if @user_session.save | |
flash[:notice] = "Login successful!" | |
redirect_back_or_default account_url | |
else | |
render :action => :new | |
end | |
end | |
def destroy | |
current_user_session.destroy | |
flash[:notice] = "Logout successful!" | |
redirect_back_or_default new_user_session_url | |
end | |
end | |
END | |
file 'app/controllers/users_controller.rb', <<-END | |
class UsersController < ApplicationController | |
before_filter :require_no_user, :only => [:new, :create] | |
before_filter :require_user, :only => [:show, :edit, :update] | |
before_filter :admin_required, :only => [:index, :destroy] | |
def index | |
@users = User.all | |
@page_title = "All Users" | |
end | |
def new | |
@user = User.new | |
@page_title = "Create Account" | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
flash[:notice] = "Account registered!" | |
redirect_back_or_default account_url | |
else | |
render :action => :new | |
end | |
end | |
def show | |
find_user | |
@page_title = "\#{@user.login} details" | |
end | |
def edit | |
find_user | |
@page_title = "Edit \#{@user.login}" | |
end | |
def update | |
find_user | |
if @user.update_attributes(params[:user]) | |
flash[:notice] = "Account updated!" | |
redirect_to account_url | |
else | |
render :action => :edit | |
end | |
end | |
def destroy | |
find_user | |
@user.destroy | |
flash[:notice] = 'User was deleted.' | |
redirect_to(users_url) | |
end | |
private | |
def find_user | |
if @current_user.admin? && params[:id] | |
@user = User.find(params[:id]) | |
else | |
@user = @current_user | |
end | |
end | |
end | |
END | |
file 'app/models/notifier.rb', <<-END | |
class Notifier < ActionMailer::Base | |
default_url_options[:host] = "larkfarm.com" | |
def password_reset_instructions(user) | |
subject "Password Reset Instructions" | |
from "Administrator <[email protected]>" | |
recipients user.email | |
sent_on Time.now | |
body :edit_password_reset_url => edit_password_reset_url(user.perishable_token) | |
end | |
end | |
END | |
file 'app/models/user.rb', <<-END | |
class User < ActiveRecord::Base | |
acts_as_authentic | |
serialize :roles, Array | |
before_validation_on_create :make_default_roles | |
attr_accessible :login, :password, :password_confirmation, :email, :first_name, :last_name | |
def deliver_password_reset_instructions! | |
reset_perishable_token! | |
Notifier.deliver_password_reset_instructions(self) | |
end | |
def admin? | |
has_role?("admin") | |
end | |
def has_role?(role) | |
roles.include?(role) | |
end | |
def add_role(role) | |
self.roles << role | |
end | |
def remove_role(role) | |
self.roles.delete(role) | |
end | |
def clear_roles | |
self.roles = [] | |
end | |
def kaboom! | |
r = RegExp.new("foo") | |
end | |
private | |
def make_default_roles | |
clear_roles if roles.nil? | |
end | |
end | |
END | |
file 'app/models/user_session.rb', <<-END | |
class UserSession < Authlogic::Session::Base | |
end | |
END | |
file 'app/views/notifier/password_reset_instructions.erb', <<-END | |
A request to reset your password has been made. If you did not make this request, simply ignore this email. If you did make this request just click the link below: | |
<%= @edit_password_reset_url %> | |
If the above URL does not work try copying and pasting it into your browser. If you continue to have problem please feel free to contact us. | |
END | |
file 'app/views/password_resets/edit.html.erb', <<-END | |
<h1>Change My Password</h1> | |
<% form_for @user, :url => password_reset_path, :method => :put, :live_validations => true do |f| %> | |
<%= f.error_messages %> | |
<%= f.label :password %><br /> | |
<%= f.password_field :password %><br /> | |
<br /> | |
<%= f.label :password_confirmation %><br /> | |
<%= f.password_field :password_confirmation %><br /> | |
<br /> | |
<%= f.submit "Update my password and log me in" %> | |
<% end %> | |
END | |
file 'app/views/password_resets/new.html.erb', <<-END | |
<h1>Forgot Password</h1> | |
Fill out the form below and instructions to reset your password will be emailed to you:<br /> | |
<br /> | |
<% form_tag password_resets_path do %> | |
<label>Email:</label><br /> | |
<%= text_field_tag "email" %><br /> | |
<br /> | |
<%= submit_tag "Reset my password" %> | |
<% end %> | |
END | |
file 'app/views/user_sessions/new.html.haml', <<-END | |
%h1= "Login" | |
- form_for @user_session, :url => user_session_path do |f| | |
= f.error_messages | |
%p | |
= f.label :email | |
= f.text_field :email | |
%p | |
= f.label :password | |
= f.password_field :password | |
%p | |
= f.check_box :remember_me | |
= f.label :remember_me | |
= f.submit "Login" | |
= "or" | |
= link_to "Register", new_user_path | |
END | |
file 'app/views/users/index.html.erb', <<-END | |
<h1>Listing users</h1> | |
<table> | |
<tr> | |
<th>Login</th> | |
<th colspan="3"></th> | |
</tr> | |
<% @users.each do |user| %> | |
<tr> | |
<td><%=h user.login %></td> | |
<td><%= link_to 'Show', user %></td> | |
<td><%= link_to 'Edit', edit_user_path(user) %></td> | |
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td> | |
</tr> | |
<% end %> | |
</table> | |
<br /> | |
<%= link_to 'New user', new_user_path %> | |
END | |
file 'app/views/users/_form.html.haml', <<-END | |
%p | |
= form.label :email | |
= form.text_field :email | |
%p | |
= form.label :password, form.object.new_record? ? nil : "Change password" | |
= form.password_field :password | |
%p | |
= form.label :password_confirmation | |
= form.password_field :password_confirmation | |
END | |
file 'app/views/users/edit.html.haml', <<-END | |
%h1= "Edit My Account" | |
- form_for @user, :url => account_path do |f| | |
= f.error_messages | |
= render :partial => "form", :object => f | |
= f.submit "Update" | |
%br | |
= link_to "My Profile", account_path | |
END | |
file 'app/views/users/new.html.haml', <<-END | |
%h1= "Register" | |
- form_for @user, :url => account_path do |f| | |
= f.error_messages | |
= render :partial => "form", :object => f | |
= f.submit "Update" | |
END | |
file 'app/views/users/show.html.haml', <<-END | |
%p | |
%strong= "Email:" | |
=h @user.email | |
= link_to "Edit", edit_account_path | |
END | |
file 'db/migrate/01_create_users.rb', <<-END | |
class CreateUsers < ActiveRecord::Migration | |
def self.up | |
create_table :users do |t| | |
t.timestamps | |
t.string :email, :null => false | |
t.string :crypted_password, :null => false | |
t.string :password_salt, :null => false | |
t.string :persistence_token, :null => false | |
t.integer :login_count, :default => 0, :null => false | |
t.datetime :last_request_at | |
t.datetime :last_login_at | |
t.datetime :current_login_at | |
t.string :last_login_ip | |
t.string :current_login_ip | |
t.string :roles | |
t.string :first_name | |
t.string :last_name | |
t.string :perishable_token, :default => "", :null => false | |
end | |
add_index :users, :email | |
add_index :users, :persistence_token | |
add_index :users, :last_request_at | |
add_index :users, :perishable_token | |
end | |
def self.down | |
drop_table :users | |
end | |
end | |
END | |
file 'db/migrate/02_create_sessions.rb', <<-END | |
class CreateSessions < ActiveRecord::Migration | |
def self.up | |
create_table :sessions do |t| | |
t.string :session_id, :null => false | |
t.text :data | |
t.timestamps | |
end | |
add_index :sessions, :session_id | |
add_index :sessions, :updated_at | |
end | |
def self.down | |
drop_table :sessions | |
end | |
end | |
END | |
commit_state "basic Authlogic setup" | |
# static pages | |
file 'app/controllers/pages_controller.rb', <<-END | |
class PagesController < ApplicationController | |
def home | |
@page_title = '#{current_app_name}' | |
end | |
def css_test | |
@page_title = "CSS Test" | |
end | |
end | |
END | |
file 'app/views/pages/home.html.erb', <<-END | |
<div id="top_menu"> | |
<% anonymous_only do %> | |
<%= link_to "Register", new_account_path %> | |
<%= link_to "Login", new_user_session_path %> | |
<% end %> | |
<% authenticated_only do %> | |
<%= link_to "Logout", user_session_path, :method => :delete, :confirm => "Are you sure you want to logout?" %> | |
<% end %> | |
</div> | |
<div id="main"> | |
<h1>Welcome to #{current_app_name}</h1> | |
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | |
</div> | |
<div id="left_menu"> | |
<% anonymous_only do %> | |
<%= link_to "Register", new_account_path %> | |
<%= link_to "Login", new_user_session_path %> | |
<% end %> | |
<% authenticated_only do %> | |
<% end %> | |
</div> | |
END | |
file 'app/views/pages/css_test.html.erb', <<-END | |
<!-- Sample Content to Plugin to Template --> | |
<h1>CSS Basic Elements</h1> | |
<p>The purpose of this HTML is to help determine what default settings are with CSS and to make sure that all possible HTML Elements are included in this HTML so as to not miss any possible Elements when designing a site.</p> | |
<hr /> | |
<h1 id="headings">Headings</h1> | |
<h1>Heading 1</h1> | |
<h2>Heading 2</h2> | |
<h3>Heading 3</h3> | |
<h4>Heading 4</h4> | |
<h5>Heading 5</h5> | |
<h6>Heading 6</h6> | |
<small><a href="#wrapper">[top]</a></small> | |
<hr /> | |
<h1 id="paragraph">Paragraph</h1> | |
<img style="width:250px;height:125px;float:right" src="images/css_gods_language.png" alt="CSS | God's Language" /> | |
<p>Lorem ipsum dolor sit amet, <a href="#" title="test link">test link</a> adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</p> | |
<p>Lorem ipsum dolor sit amet, <em>emphasis</em> consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus.</p> | |
<small><a href="#wrapper">[top]</a></small> | |
<hr /> | |
<h1 id="list_types">List Types</h1> | |
<h3>Definition List</h3> | |
<dl> | |
<dt>Definition List Title</dt> | |
<dd>This is a definition list division.</dd> | |
</dl> | |
<h3>Ordered List</h3> | |
<ol> | |
<li>List Item 1</li> | |
<li>List Item 2</li> | |
<li>List Item 3</li> | |
</ol> | |
<h3>Unordered List</h3> | |
<ul> | |
<li>List Item 1</li> | |
<li>List Item 2</li> | |
<li>List Item 3</li> | |
</ul> | |
<small><a href="#wrapper">[top]</a></small> | |
<hr /> | |
<h1 id="form_elements">Fieldsets, Legends, and Form Elements</h1> | |
<fieldset> | |
<legend>Legend</legend> | |
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</p> | |
<form> | |
<h2>Form Element</h2> | |
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui.</p> | |
<p><label for="text_field">Text Field:</label><br /> | |
<input type="text" id="text_field" /></p> | |
<p><label for="text_area">Text Area:</label><br /> | |
<textarea id="text_area"></textarea></p> | |
<p><label for="select_element">Select Element:</label><br /> | |
<select name="select_element"> | |
<optgroup label="Option Group 1"> | |
<option value="1">Option 1</option> | |
<option value="2">Option 2</option> | |
<option value="3">Option 3</option> | |
</optgroup> | |
<optgroup label="Option Group 2"> | |
<option value="1">Option 1</option> | |
<option value="2">Option 2</option> | |
<option value="3">Option 3</option> | |
</optgroup> | |
</select></p> | |
<p><label for="radio_buttons">Radio Buttons:</label><br /> | |
<input type="radio" class="radio" name="radio_button" value="radio_1" /> Radio 1<br/> | |
<input type="radio" class="radio" name="radio_button" value="radio_2" /> Radio 2<br/> | |
<input type="radio" class="radio" name="radio_button" value="radio_3" /> Radio 3<br/> | |
</p> | |
<p><label for="checkboxes">Checkboxes:</label><br /> | |
<input type="checkbox" class="checkbox" name="checkboxes" value="check_1" /> Radio 1<br/> | |
<input type="checkbox" class="checkbox" name="checkboxes" value="check_2" /> Radio 2<br/> | |
<input type="checkbox" class="checkbox" name="checkboxes" value="check_3" /> Radio 3<br/> | |
</p> | |
<p><label for="password">Password:</label><br /> | |
<input type="password" class="password" name="password" /> | |
</p> | |
<p><label for="file">File Input:</label><br /> | |
<input type="file" class="file" name="file" /> | |
</p> | |
<p><input class="button" type="reset" value="Clear" /> <input class="button" type="submit" value="Submit" /> | |
</p> | |
</form> | |
</fieldset> | |
<small><a href="#wrapper">[top]</a></small> | |
<hr /> | |
<h1 id="tables">Tables</h1> | |
<table cellspacing="0" cellpadding="0"> | |
<tr> | |
<th>Table Header 1</th><th>Table Header 2</th><th>Table Header 3</th> | |
</tr> | |
<tr> | |
<td>Division 1</td><td>Division 2</td><td>Division 3</td> | |
</tr> | |
<tr class="even"> | |
<td>Division 1</td><td>Division 2</td><td>Division 3</td> | |
</tr> | |
<tr> | |
<td>Division 1</td><td>Division 2</td><td>Division 3</td> | |
</tr> | |
</table> | |
<small><a href="#wrapper">[top]</a></small> | |
<hr /> | |
<h1 id="misc">Misc Stuff - abbr, acronym, pre, code, sub, sup, etc.</h1> | |
<p>Lorem <sup>superscript</sup> dolor <sub>subscript</sub> amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. <cite>cite</cite>. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. <acronym title="National Basketball Association">NBA</acronym> Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. <abbr title="Avenue">AVE</abbr></p> | |
<pre><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus. Maecenas ornare tortor. Donec sed tellus eget sapien fringilla nonummy. <acronym title="National Basketball Association">NBA</acronym> Mauris a ante. Suspendisse quam sem, consequat at, commodo vitae, feugiat in, nunc. Morbi imperdiet augue quis tellus. <abbr title="Avenue">AVE</abbr></p></pre> | |
<blockquote> | |
"This stylesheet is going to help so freaking much." <br />-Blockquote | |
</blockquote> | |
<small><a href="#wrapper">[top]</a></small> | |
<!-- End of Sample Content --> | |
END | |
file 'doc/README_FOR_APP', <<-END | |
TODO after installing: | |
- Set up new app at http://monochrome.hoptoadapp.com | |
- Put mail server password in mail.rb | |
- git remote add origin [email protected]:#{current_app_name}.git | |
- git push origin master:refs/heads/master | |
- create databases for parallel_test (rake db:create:all) | |
This application includes: | |
Coding Tools | |
============ | |
- Authlogic for user authentication, including password resets, | |
anonymous_only, authenticated_only, admin_only application helpers | |
- World's simplest authorization system: manage multiple string roles on users with User#add_role, User#remove_role, User#clear_roles, and User#has_role? | |
- Date formats: :uk, :uk_with_time, :short_day, :long_day | |
- jRails | |
- Paperclip for attachment management | |
- /pages/css_test will show most CSS styles in action | |
- Searchlogic for magic named scopes and search forms - http://rdoc.info/projects/binarylogic/searchlogic | |
attribute_equals, attribute_does_not_equal, attribute_begins_with, attribute_like, attribute_ends_with, attribute_greater_than, | |
attribute_null, attribute_blank etc. etc. | |
- Stringex for extra string functionality | |
acts_as_url, String#to_ascii, String#to_html, String#to_url, String#remove_formatting, String.random | |
- will-paginate for pagination | |
Database Tools | |
============== | |
- admin-data plugin for administrative UI. http://localhost:3000/admin_data will get you to the application's data. On production, | |
only admin can view data, no one can edit (modify config/initializers/admin_data.rb to adjust this) | |
- db-populate for seed data | |
External Services | |
================= | |
- HopToad for error tracking. | |
- New Relic for performance tracking | |
END | |
commit_state "static pages" | |
# simple default routing | |
file 'config/routes.rb', <<-END | |
ActionController::Routing::Routes.draw do |map| | |
map.resource :account, :controller => "users" | |
map.resources :password_resets | |
map.resources :users | |
map.resource :user_session | |
map.login 'login', :controller => "user_sessions", :action => "new" | |
map.login 'logout', :controller => "user_sessions", :action => "destroy" | |
map.register 'register', :controller => "users", :action => "new" | |
map.root :controller => "pages", :action => "home" | |
map.pages 'pages/:action', :controller => "pages" | |
end | |
END | |
file 'config/environments/development.rb', <<-END | |
# Settings specified here will take precedence over those in config/environment.rb | |
# In the development environment your application's code is reloaded on | |
# every request. This slows down response time but is perfect for development | |
# since you don't have to restart the webserver when you make code changes. | |
config.cache_classes = false | |
# Log error messages when you accidentally call methods on nil. | |
config.whiny_nils = true | |
# Show full error reports and disable caching | |
config.action_controller.consider_all_requests_local = true | |
config.action_view.debug_rjs = true | |
config.action_controller.perform_caching = false | |
# Don't care if the mailer can't send | |
config.action_mailer.raise_delivery_errors = false | |
config.middleware.use "Rack::Bug" | |
END | |
commit_state "routing" | |
# databases | |
rake('db:create') | |
rake('db:migrate') | |
# Success! | |
puts "SUCCESS!" | |
puts ' Set up new app at http://monochrome.hoptoadapp.com' | |
puts ' Put mail server password in mail.rb' | |
puts ' git remote add origin [email protected]:#{current_app_name}.git' | |
puts ' git push origin master:refs/heads/master' | |
puts ' create databases for parallel_test (rake db:create:all)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment