My favorites | Sign in
Project Logo
          
Code license: MIT License
Labels: ruby, wiki, mediawiki, rails
People details
Project owners:
  nricciar

Ruby implementation of the MediaWiki markup language.

Supports

Getting Started

Install

./script/plugin install http://wikicloth.googlecode.com/svn/trunk/wikicloth/

Controller

  include WikiCloth

  def show
    @wiki = WikiCloth.new({ 
      :data => "<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
      :params => { "test" => "World" } })
  end

View

<%= @wiki.to_html -%>

Output

  <p>&#123;&#123;test&#125;&#125;  <i>Hello World!</i></p>

Wiki Links and Variable/Template Handling

Use the url_for and link_attributes_for methods to override the default URL for an [[internal link]]. If you need even more control, the link_for can also be used to return raw html.

custom_link_handler.rb

class CustomLinkHandler < WikiCloth::WikiLinkHandler

  def url_for(page)
    "javascript:alert('You clicked on: #{page}');"
  end

  def link_attributes_for(page)
     { :href => url_for(page) }
  end

end

You can also override the include_resource method to give you control over {{ template_variables }}...

custom_link_handler.rb

  def include_resource(resource,options=[])
    case resource
    when "date"
      Time.now.to_s
    else
      # default behavior
      super(resource,options)
    end
  end

Controller

  include WikiCloth

  def show
    @wiki = WikiCloth.new({ 
      :params => { "PAGENAME" => "Testing123" }, 
      :link_handler => CustomLinkHandler.new, 
      :data => "Hello World From {{ PAGENAME }} on {{ date }}\n" 
    })
  end

Output (@wiki.to_html)

  <p>
  <a href="javascript:alert('You clicked on: Hello World');">Hello World</a> From Testing123 on Wed Jul 08 22:23:44 -0400 2009
  </p>








Hosted by Google Code