=Wikipodia
Wikipodia is a DSL for defining wikis within a Controller. It contains a small
preprocessor which recognizes links within text and converts them to user
defined formats. It allows a way to define these formats and a way in which to
display content being linked to.
==A Simple Example
For example, a simple wiki which just has pages processed with RedCloth:
class FooController < ActionController::Base
wikipodia do
# Define a link to another page
section :page do
# Define what to do when one of the links is clicked
action do
@page = Page.find(params[:id])
render :text => RedCloth.new(handle_wiki_links(@page.content)).to_html
end
# Define how to transform the link
url do |id, text|
"\"#{text}\":#{page_path(id)}"
end
end
end
end
Anywhere in @page.content, links of the format
[[page:some-id Some Text]] will be converted into RedCloth links of the
format "Some Text":/page/some-id.
==A More Complex Example
A more complete wiki might support not only pages, but images and file
downloads:
class MiniWikiController < ActionController::Base
wikipodia do
section :page do
action do
@page = Page.find(params[:id])
render :text => RedCloth.new(handle_wiki_links(@page.content)).to_html
end
url do |id, text|
"\"#{text}\":#{page_path(id)}"
end
end
section :image do
action do
@image = Image.find(params[:id])
send_data @image.content
end
url do |id, text|
"!#{image_path(id)}!"
end
end
section :document do
action do
@document = Documents.find(params[:id])
send_data @document.content, :filename => @document.original_filename, :type => @document.content_type
end
url do |id, text|
"\"#{text}\":#{document_path(id)}"
end
end
end
end
==Gem
This plugin is available as a Gem. To use it, simply add the following line to
your config/environment.rb and run rake gems:install:
config.gem "WatersOfOblivion-wikipodia", :lib => "wikipodia", :source => "http://gems.github.com/"
Copyright (c) 2009 Jonathan Bryant, released under the MIT license