~ubuntu-branches/ubuntu/trusty/grantlee/trusty

« back to all changes in this revision

Viewing changes to dox/internals.dox

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2010-06-11 23:41:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100611234145-oas7rhdrbwy8j55c
Tags: upstream-0.1.1
ImportĀ upstreamĀ versionĀ 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
namespace Grantlee
 
3
{
 
4
 
 
5
/**
 
6
  @page internals Internals
 
7
 
 
8
  @note This page is intended only to be informative for new contributors to %Grantlee or people who are really interested in this kind of thing. These are implementation details and are likely to change without notice.
 
9
 
 
10
  @section how_works How Grantlee works.
 
11
 
 
12
  A template string is first tokenized by the lexer class. The result is a list of tokens with content which can be of type TextToken, CommentToken, VariableToken or TagToken.
 
13
 
 
14
  The tokens are further processed by the Parser class. The Parser generates nodes from the token stream. For a TextToken it generates a TextNode, for a CommentToken it generates nothing, for a VariableToken it generates a VariableNode, and for a TagToken it generates another type of Node determined by available plugins. Some plugins are built in, and others may be loaded by the template itself using the @gr_tag{load} tag, or preloaded by the application developer.
 
15
 
 
16
  The plugin uses the Abstract Factory pattern. It returns a list of concrete factories, one for each tag handled by that plugin. The factories have a getNode method which accepts the tag content and the active parser as an argument and returns a concrete Node. The getNode method may advance the parser in the case of begin/end tags etc. When the parser is finished, it has created a tree of nodes, which is essentially a Template object.
 
17
 
 
18
  A Template is rendered with a Context object. During rendering, each node in the template has its render method called with the Context. The node may contain different sub-trees, one of which is rendered, as is the case for IfNode, or it might contain a single sub-tree which is rendered multiple times, as in the case of ForNode, etc. The rendering outputs a string, which is the rendered output of the template for a particular context. A single Template may be rendered multiple times with mutliple different Contexts.
 
19
 
 
20
  Plugins can return Filters as well as AbstractNodeFactories. Filters can manipulate Variables in some way before rendering them to the output.
 
21
 
 
22
  Loading templates to include or extend is accomplished using the loadByName methods. The secondary template should use the same state as the initially created/loaded template, so that it uses the same template loaders, has the same plugins available by default and uses the same search directories to find additional plugins.
 
23
 
 
24
*/
 
25
 
 
26
}
 
27