Features
- Looks clean, we don't want to replace python mess with strange template language mess
- Easy to learn - close as possible to Python
- Fast - also for CGI.
- Auto escaping of input, and an easy way to disable escaping for raw html. Needed for some parts like credits.
- General - text template that can be used for everything is more useful then special purpose xml based. For example, we can use templates to create email messages or css files from a set of colors
XML or text?
With XML templates otherwise you have valid documents while editing/designing. Also look at: HOWTO Avoid Being Called a Bozo When Producing XML for other pro's using xml-based templates - btw if using Genshi, you can choose easy between xml-based and text-based templates/output.
The link mentioned is about creating XML but MoinMoin templates need to create HTML and plain text. I think the features mentioned above are the important points: which system will be easier to learn? do moin developers and contributors have to learn 2 systems - one text based and one xml based? which code will be easier to maintain? which is faster?
But effectively (X)HTML is XML. Advantages of xml-based templating is, that it is more web designer - friendly (I am one, part-time) because the templates are still valid XHTML, and you can get a proper preview while designing the template, because also all of the additional tags with the templating logic is inside XML tags. The MoinMoin developers and contributiors dont have to learn two systems (the developers have additional mostly to do with the backend and the connection to the existing MoinMoin) because for the templating of the website you use XML-based templating. The advantage of my suggestion Genshi is, that if you have other documents than documents who will end up in HTML, but in textbased formats, you can also do templating on them! But for the main reason (html templates for moin) you use xml-based. Easy templating, especially for web designers is one of the best possibilities to increase the spreading and acception of MoinMoin. -- MarkusMajer
Current theme code style
For reference, code using current theme style:
def foo(self, title, stylesheet): """ Few lines of useless docstring... """ # some logic, temps... result = [ '<html>', '<head>', '<title>%s</title>' % wikiutil.escape(title), ] if stylesheet: result.append('<link rel="stylesheet" href="%s" type="text/css" />' % stylesheet result.append('</head>') return ''.join(result)
Most code is less clear, you have to jump between methods to find the place each html fragment is created.
Note that you have to escape everything, except stuff that is raw html. Finding what should be escaped is quite hard, require a trip to wikiutil.send_title, where d is created.
Text based templates
Can be used for anything - html, mail, code generation.
PTL / Qpy
PTL - part of quixote framework. This is the most pythonic template system, because it is actually 99% Python.
Qpy is newer standalone package based on PTL. It has better unicode support and easier to integrate into projects that does not use Quixote.
This is a big improvement over the current style, but compared with webpy, the template contains a lot of Python junk.
def header [html] (title, stylesheet): "<html>" "<head>" "<title>%s</title>" % title if stylesheet: '<link rel="stylesheet" href="%s" type="text/css" />' % stylesheet "</head>"
The title will be escaped automatically. There is also an easy way to prevent escaping of raw html (htmltext(rawhtml)).
Web.py
web.py templator debian easy to learn, pythonic. It produce the cleanest looking templates
def with (title, stylesheet=None) <html> <head> <title>$title</title> $if stylesheet: <link rel="stylesheet" href="$stylesheet" type="text/css" /> </head>
Note the (optional) smart indentation of conditional parts, without need to end of block markers.
Also, everything is automatically escaped, and there is a simple way to prevent escaping of raw html ($:rawhtml).
Issues: tempaltes are cached in RAM, but not compiled to bytecode, so CGI may need to use pickled tempaltes.
Mako
Mako - newer system similar to cheetah. Faster then webpy.templator - its considered (one of) the fastest templating engines in Python. Like cheeta and others, the syntax is less pythonic, and require end of block markers. Templates are compiled to byte code, similar to moin text_html formatter files.
<html> <head> <title>${title}</title> % if stylesheet: <link rel="stylesheet" href="${stylesheet}" type="text/css" /> %endif </head>
Again input is automatically escaped. However, I could not find a way to disable escaping of single variables, unless moving to explicit esacaping. This feature is needed for some parts of moin themes, for example the credits list.
Cheetah
Cheetah - more complicated, mature. The syntax is similar to Mako, but more ugly - too much $ everywhere.
Issues: I looked into the code - mess.
Django
Django template - ugly syntax.
XML based templates
Good for designers, which can use the template as is to work on the design.
Genshi
Genshi - inspired by kid. kid original author thinks it is better then kid. A new feature is support for text based templates.