
What about WikiWords?
=====================

Our wiki doesn't yet have a way to link pages.

A "WikiWord" is a word that starts with an uppercase letter, has a collection
of lowercase letters and numbers followed by another uppercase letter and
more letters and numbers (sometimes described as WordsSmashedTogether).
A typical wiki will automatically create links for *WikiWords* when it
finds them. This sounds like a job for a regular expression.

Here's the new version of ``root.py``, which will be explained afterwards:

.. literalinclude:: ../../project_code/wiki_root/snapshots/5/wiki20/controllers/root.py
   :linenos:

**9-10:**  we include two more imports: ``re`` for regular expressions
and a method called ``publish_parts`` from ``docutils``.

**12:**  the  ``wikiwords`` regular expression describes a WikiWord.

**19:**  In ``default``, the new material begins here with the use of
``publish_parts``, a utility that takes string input and returns
a dictionary of document parts after performing conversions;
here converting the *data* field of the *FrontPage* record from
Restructured Text to HTML (specified by ``writer_name="html"``).
Selecting the ``fragment`` part produces the document without the document title,
subtitle, docinfo, header, or footer.

**21:** You can configure TurboGears so that it doesn't live at the root
of a site. That way you can combine multiple TurboGears apps on a single
server. We use ``tg.url()`` to create relative links so that they will
continue to work regardless of how many apps you're running.

**22:** rewrites the string ``content``  by finding any WikiWords and
substituting hyperlinks for those WikiWords. That way when you click
on a WikiWord, it will take you to that page. The ``r'string'`` means
'raw string', one that turns off escaping, which is mostly used in
regular expression strings to prevent you from having to double
escape slashes. The substitution may look a bit weird, but is more
understandable if you recognize that the ``%s`` gets substituted with
``root``, then each occurrence of the ``\1`` is replaced with the
string matching the regex.

**23:** Note that ``default()`` is now returning a ``dict`` containing
an additional key-value pair: ``content=content``. This will not break
``wiki20.templates.page`` because that page is only looking for ``page``
in the dictionary, however if we want to do something interesting with the new
key-value pair we'll need to edit ``wiki20.templates.page``:


    .. literalinclude:: ../../project_code/wiki_root/snapshots/6/wiki20/templates/page.html
       :linenos:
       :language: html

**21:**  Genshi defaults to XML: since ``content`` comes through as XML,
we strip it off using the ``XML()`` function to produce plain text
(try removing the function call to see what happens).

To test the new version of the system, edit the data in your front page to
include a WikiWord. When the page is displayed, you'll see that it's now a link.
You probably won't be surprised to find that clicking that link produces an
error.


