Plugins

  1. Engines
  2. Filter
  3. Tags
  4. Hooks

1 Engines

Engines render pages and are selected by an acceptor pattern. There can be multiple engines which accept a page. The default engine is selected by priority. You can specify a engines with the query parameter "aspect".

Example:

Engines have to implement three methods:

Engine example

require 'RMagick'

Engine.create(:image, :priority => 2, :layout => false, :cacheable => true) do
  def svg?(page); page.mime.to_s =~ /svg/; end
  def accepts?(page); page.mime.mediatype == 'image'; end
  def mime(page); svg?(page) ? 'image/png' : page.mime; end

  def output(context)
    page = context.page
    if svg?(page) || context['geometry']
      image = Magick::Image.from_blob(page.content).first
      image.change_geometry(context['geometry']) { |w,h| image.resize!(w, h) } if context['geometry']
      image.format = 'png' if svg?(page)
      image.to_blob
    else
      super
    end
  end
end

2 Filter

There is a engine type "filter" which creates engines based on chained filters. The filter engines are configured in the file engines.yml. See the plugins under plugin/filter.

Filter example

Filter.create :markdown do |content|
  RDiscount.new(content).to_html
end

3 Tags

Tags are a way to extend the wiki markup. See the plugins under plugin/tag.

Tag definition example

Tag.define(:code, :requires => :lang) do |context, attrs, content|
  Pygments.pygmentize(content, :format => attrs['lang'])
end

4 Hooks

Hook example used in the private_wiki plugin:

App.before :routing do
  if @user.anonymous?
    halt if request.path_info == '/sys/fragments/sidebar'
    redirect '/login' if !WHITE_LIST.any? {|pattern| request.path_info =~ /^#{pattern}$/ }
  end
end