How to hack soks

How to hack soks

Here are some pointers to help you figure out where to make whatever changes and improvements you desire. Soks's licence is liberal, so please do whatever you want, but I would appreciate any improvements you can send me ( tamc@rubyforge.com ).

template

lib

soks-utils.rb

soks-model.rb

A Wiki class has many Page classes which have many Revision classes. ImagePage and AttachmentPage are subclasses of Page that return different textile.

The Wiki class decides what type of page to create based on its name. All AttachmentPage pages have names that start with ‘Attached ’, all ImagePage pages have names that start with ‘Picture of’. This is defined in the @page_classes instance variable of the Wiki class.

The Wiki loads all the pages from file into a hash. When pages are changed it writes a copy to disk immediately. It has a thread that watches the disk for any changes to the files.

soks-view.rb

The View object does the business. It is called by the soks-servlet, and then proceeds to call an appropriate method on the Wiki model. It may then Notify any observing AutomaticHelpers of any changes, before proceeding to render the html. This rendering happens in two places: First the Page.textile is turned into html by WikiRedCloth. then an appropriate ERB file is loaded and called.

The WikiRedCloth overrides the to_html method of redcloth to add a number of methods that do the automatic page insertion and automatic linking. The automatic linking is actually carried out in the RollingMatch class. A record of the links between pages is kept in the Links class and then written to each page object.

The ERB files are loaded from disk. The appropriate erb file is selected by looking for the pattern ClassName_viewname.rhtml (e.g. Page_edit.rhtml). If that page doesn’t exist then the process is repeated with the Page’s superclass. The ERB files are cached.

soks-servlet.rb

This runs a Webrick server to interact with the user. The server can be stopped by sending an interupt (ctrl-c).

The server has two handlers, a WEBrick::HTTPServlet::FileHandler for doing the dynamic content (which is attached to any url starting in /attachment/) and a WikiServlet for the dynamic content.

The WikiServlet service method takes a look at the request url. If it is ’/’ it redirects to ’/view/Home Page’. If it only has one slash in it (e.g. ’/Home Page‘) then it assumes that it is equivalent to ’/view/Home Page’. If it has two or more slashes in it (e.g. ’/edit/Home Page’ ) then it splits the url into a command (‘edit’) and the rest (‘Home Page‘). If the WikiServlet responds to doCommand (e.g. doEdit) then control is passed to that method. Otherwise it is assumed the command is the name of a view (e.g. ‘print’) and is therefore passed as is to the View object.

The WikiServlet deals with file uploads by separately writing the uploaded file to the ‘attachments’ directory and also asking the ‘View’ object to create or revise an ImagePage object whose content is the filename of the uploaded file.

soks-default-helpers.rb

These are a series of classes that may be optionally loaded by a wiki’s start.rb script. They receive notifications of page changes from the View object and can use this information to update other pages in the wiki. See automatic summaries for a little more detail.

Tag: Include this page in the distribution

Edit this page or watch for changes using RSS.