CategoryHelper
(This feature is not yet in a released version)
This was inspired by Alexandru Popescu, and adds WikiPedia / Instiki style categories. To use, put this in your start file next to all the other helper bits:
require 'category-helper'
CategoryHelper.new( wiki )
Then, anytime you start a line on a page with Category: this is a category, it will create a new page called ‘this is a category’ that will list all the pages in that category. You can put a page in several pages by repeating the command several times, or by separating categories with semicolons. e.g.: Category: category one; category two
class CategoryHelper
def initialize( wiki )
@wiki = wiki
@categories = Hash.new
@wiki.watch_for(:page_revised) { |event,page,revision| check_for_category(revision) }
check_existing_pages
end
def check_existing_pages
@wiki.each { |name, page| check_for_category( page ) }
end
def check_for_category( revision )
revision.content.scan( /^category:(.*)$/i ) do |categories,other|
categories.scan( /([^;]+)/ ) do |category,other|
ensure_summary_for( category.strip, revision )
end
end
end
def ensure_summary_for( category_name, revision )
return if @categories[ category_name ]
@categories[ category_name ] = AutomaticList.new( @wiki, category_name ) do |page|
page.content =~ /^category:(\s*|.*?;\s*)#{category_name}\s*([;\n]|$)/i
end
end
end
Edit this page or
watch for changes using RSS.