Our application, being a wiki, consists of articles. The way we would like to structure things, is for an article also to contain other articles. Thus, when one is viewing one page, one should be able to navigate to any pages contained by the current one, or to the parent. One should also be able to navigate back and forth through sibling pages- siblings are pages contained by the current article's parent.
By the above specification, we know that an article is a container (grok.Container). The application itself is also an article. We define the interface for an article as follows:
We can see that an article contains a title, a navigation title and text. As previously discussed, the attributes are instances of schema field classes, which may be mapped to fields and widgets in automatically generated forms.
Now, we also know that articles will be containers, and that applies both to the application itself as well as any contained articles. So it's a good idea to capture that fact in code:
We are already getting ahead of ourselves here with the definition of ArticleContainer.attachments;
we shall discuss the IArticleSorter
interface and adapter in due course. In the above, we are saying that traversing to an 'article/sorter' will return an instance of an IArticleSorter
.
For the moment, what is contained in attachments is still unknown, but if we assume it to be a list of attachments, this would not be far from the truth.
As for our application and contained articles, the difference is that the application has no parent and is at the root of the site, where every other kind of article has a parent:
We can see how both the Grok4Noobs application as well as the contained NoobsArticles are instances of ArticleContainer
. They also both implement IArticle
and ILayout
interfaces, thus inheriting the behaviour associated with those interfaces such as views, menus, viewlets and so forth.
As there is an index view defined for ILayout
, our above classes also get the index view. This view, as we have already discussed, will render providers (viewlet managers) for the various parts of the web page such as masthead, navigation or content. This means that we can easily include the article content by defining a viewlet manager for an IArticle
: