The organisation of this wiki is a bit odd, one might say not as simple as might be found on other wikis. It's too deep one might argue; a wiki does not need to branch forever. And one may be right.
The reason why we did it this way, is that the navigation of the site almost forces one to build documentation in a structured manner. So, looking at one topic, one is not presented with the entire list of siblings in the navigation; rather, one can see the previous and next sibling, and the parent item. Looking at this page, one can see that the parent is "Application", and the topic "Printing a Book" has one sibling called "Doing Backups". This is similar behaviour to a book, where one may page forward or back, or go to the index.
This approach directs the focus of the author to the topic at hand, and if there are further topics, related to the current one, lets the author create sub topics. The effect is almost like a live Mind Map. When traversed in ordered depth first, the site tree produces a single document where topics are close to each other and follow each other, much the way a book is presented.
All of this makes for a pretty good printable text.
The best converter to PDF from HTML available seems to be a commercial procuct called PrinceXML. This converter is also free for non-commercial use, thanks to the creators of that product. This site does not depend on the converter, but will use it if it is present.
If the utility is present after startup, then the site will render a "Make Book" button when one navigates to the root of the site.
As mentioned, we need to start at the site root, and traverse the content in ordered depth first order, visiting each node in the tree and emitting the HTML associated with each node as we go. This produces a single document which may be processed and turned into a PDF document.
We start by defining a view called mkbook
for the main site:
This renders the whole site to a single document, uses Prince to convert the document to a PDF (using the FullPageHtml
view), and returns the PDF document to the browser.
The FullPageHtml
View is defined only for ISiteRoot
, being the first node in our tree. However, this view kicks off the process with the first call to a recursive view called PageSimpleHTML
The detail is in the page template for FullPageHtml
, which renders a full HTML page:
As one can see, the view template includes the content of the PageSimpleHTML
view. This turns out to be the whole site.
PageSimpleHTML
visits each node in the tree, appending the text of each node to the same output. It defines two convenience methods; sortedContent()
returns the ordered list of contained items for the article, and articleContent()
returns the HTML content for the article.
The articleNumber()
method creates a label for each IArticle
node as we visit it. The very first node (the introduction) does not get a section label. This is normal behaviour for books. Subsequent nodes use the parent's label and append their own order
(as determined by sorter.sortedItems()
) to produce a new section label.
What articleContent()
is doing, is to replace the relative links to image attachments (the src attribute) with absolute links. Normally when visiting a page in the site, it is sufficient to use relative links, and for the sake of backups and restoring backups, it is also a good thing to store them that way in the article. However, this would not work for a single page, as the links are not relative to the initial model.
The page template for the view is again relatively straightforward;
Now, when the MkBook
view is called for the ISiteRoot
, the view produces a full PDF document from the single HTML document that resulted from the FullPageHTML
view.
The only other little details around this relate to the specific CSS required to tell Prince how to format the documents. The bits we use are:
which overrides some defaults to make the background and font better for printed text, and
...which fills in page numbers and headers for each page in the book.
The produced document contains the Prince logo on the first page since this is the non commercial version, and frankly given the quality of the document, I would not have minded their logo appearing on every other page too. I certainly hope someone will use Prince commercially as a result of advertisement by this site.