Skip to content

Instantly share code, notes, and snippets.

@mwilc0x
Created January 15, 2011 22:29
Show Gist options
  • Save mwilc0x/781329 to your computer and use it in GitHub Desktop.
Save mwilc0x/781329 to your computer and use it in GitHub Desktop.
class WikiController < ApplicationController
def index
@page = Page.find_by_title( params[:title] || 'HomePage' )
if @page.nil?
redirect_to :action => 'new', :title => params[:title]
else
@page.body.gsub!(
Regexp.new( '\b((?:[A-Z]\w+){2,})' ), '<a href="/wiki/index?title=\1">\1</a>' )
render :action => 'show'
end
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :action => :list }
def list
@page_pages, @pages = paginate :pages, :per_page => 10
end
def show
@page = Page.find(params[:id])
@page.body.gsub!(
Regexp.new( '\b((?:[A-Z]\w+){2,})' ), '<a href="/wiki/index?title=\1">\1</a>' )
end
def new
@page = Page.new
@page.title = params[:title] || ''
end
def create
@page = Page.new(params[:page])
if @page.save
flash[:notice] = 'Page was successfully created.'
redirect_to :action => 'index', :title => params[:title]
else
render :action => 'new'
end
end
def edit
@page = (Page.find(params[:id]) ||
Page.find_by_title(params[:title]))
end
def update
@page = Page.find(params[:id])
if @page.update_attributes(params[:page])
flash[:notice] = 'Page was successfully updated.'
redirect_to :action => 'show', :id => @page
else
render :action => 'edit'
end
end
def history
@page = Page.find(params[:id])
end
def revert_version
@page = Page.find(params[:id])
@page.revert_to!(params[:version])
redirect_to :action => 'index', :title => @page.title
end
def diff_compare
@curr_page = Page.find(params[:id])
@version_page = @curr_page.find_version(params[:version])
@diff_results = HTMLDiff.diff(@curr_page.body,@version_page.body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment