Class: Web::Wiki

Inherits:
Object show all
Includes:
Store
Defined in:
lib/web/wiki.rb,
lib/web/wiki/page.rb,
lib/web/wiki/linker.rb

Overview

Purpose

This wiki exists to:

* Serve http://www.narf-lib.org
* Test the utility of features in the NARF toolkit, and serve
  as an example of how to build a decent-sized application
  with NARF
* Be a nice, useful wiki; aka UseMod with HTMLArea integration
  and image uploads

Usage

This is the quickest way to embed the narf wiki:

#!/usr/bin/env ruby
require 'web/wiki'
Web::process{
  Web::Wiki::handle_request()
}

You will enjoy your wiki more, however, by fiddling with a few config settings. Here what a production wiki.rb might look like:

#!/usr/bin/env ruby
require 'web/wiki'

Web::process{
  # this line allows me to overload the default templates
  Web::config[:load_path] << "../"

  # here I set a number of config variables.
  Web::Wiki::set_pref( :store_url  => "/pages/",
                       :store_dir  => "../pages/",
                       :home_page  => "NarfRocks",
                       :resourceurl => "/resources" )

  # finally, I handle the request
  Web::Wiki.handle_request
}

The default templates for the NARF wiki are located in

site_lib/web/wiki/resources/

Append your template dir to the :load_path and only worry about overriding the templates you care about. Chances are, you’ll care about these two templates:

template.html

the overall template

home.html

the template for the homepage

The following preferences can make a difference for your wiki:

store_dir

Web::Wiki uses YAML to save pages. By default, these pages will be saved in “./pages/”.

store_url

If you make your store files publicly accessible, Web::Wiki can let the webserver handle any the download of any upload page assets.

home_page

The default home page for the wiki is HomePage. Set the HomePage to something meaningful in your wiki.

resourceurl

By default, the NARF wiki will download various resource files from sitelib/web/wiki/resources. This makes installation easy, but a single visit to the edit page will incur the hit of executing ruby for every single image. Make these files accessible online and tell NARF where to find them, and things should run more quickly.

Credits

Web::Wiki must extend its thanks to these very, very useful projects:

YAML

yaml4r.sourceforge.net/

HTMLArea

sourceforge.net/projects/itools-htmlarea/

Defined Under Namespace

Modules: Store Classes: Linker, Page, Request

Constant Summary collapse

@@wiki =
nil
@@preferences =
nil

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Store

#load_page, #more_news, #move_asset, #news, #open_permissions, #page_list, #recent, #save, #store, #store_basedir, #store_dir, #store_dirname, #store_url, #vandal?, #vandals

Class Method Details

.method_missing(symbol, *args) ⇒ Object

It seems nicer to define the class methods on an object and delegate a few class methods



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/web/wiki.rb', line 92

def Wiki.method_missing( symbol, *args )
  if [:handle_request,
      :store_dir,
      :store_url,
      :store_basedir,
      :more_news,
      :page_list,
      :open_permissions ].include? symbol 
    wiki.send symbol, *args
  else
    super( symbol, args )
  end
end

.pref(key) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/web/wiki.rb', line 131

def Wiki.pref( key )
  key = key.to_s unless (key.kind_of? String)
  pref = Wiki.preferences[key]
  while (pref =~ /\{\$([^\}]*)\}/)
    variable = $1
    pref.gsub!( /\{\$#{variable}\}/, Wiki.pref( variable.strip ) || "")
  end
  pref
end

.preferencesObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/web/wiki.rb', line 116

def Wiki.preferences
  @@preferences ||= {"baseurl" => Web::script_name,
                     "resourceurl" => "{$baseurl}/resources",
                     "store_dir" => "./pages/",
                     "tarpit_dir" => "./tarpit/",
                     "resource_dir" => File.join( File.dirname( __FILE__ ),
                                                  "wiki",
                                                  "resources" ),
                     "vandals" => "vandals.txt",
                     "home_page" => "HomePage",
                     "home_template" => "home.html",
                     "allowed_actions" => Wiki::Request.actions.keys
  }
end

.set_pref(new_prefs = {}) ⇒ Object



141
142
143
144
145
146
# File 'lib/web/wiki.rb', line 141

def Wiki.set_pref( new_prefs={} )
  new_prefs.each{ |key,value|
    key = key.to_s unless (key.kind_of? String) 
    Wiki.preferences[key] = value
  }
end

.wikiObject



107
108
109
# File 'lib/web/wiki.rb', line 107

def Wiki.wiki
  @@wiki ||= Wiki.new
end

.wipeObject

:nodoc:



111
112
113
# File 'lib/web/wiki.rb', line 111

def Wiki.wipe #:nodoc:
  @@wiki = nil
end

Instance Method Details

#handle_requestObject




350
351
352
353
354
355
356
# File 'lib/web/wiki.rb', line 350

def handle_request
  Request.new( self ).handle_request
  #unless (Wiki.pref("added_exit_handler"))
  #  
  #  Wiki.set_pref("added_exit_handler" => true )
  #end
end