On Wed, Jan 14, 2004 at 10:11:51PM -0500, Graham Fawcett wrote: > This is what Nevow template code looks like. It's valid Python, though it > looks more like an S-expression: > > document = html[ > body[ > form(action="")[ input(type="text", name="name") ], > ] > ] That's pretty cute. What are the pros and cons of this vs. PTL? * Full Nevow seems aimed at improving performance by pre-generating the document, but this means you need support for callouts. I'm not sure this optimization is worthwhile; is gluing together HTML strings the bottleneck in any real applications? * No need to remember to write ending tags. Advantage: Nevow. * I'll bet you could make the classes enforce validity by checking the child tags (so body[input()] would raise an exception). I'm trying to figure out if I would drop using PTL in favor of this, and am not really sure; guess I'll have to try it at some point... > Callables are lazy-evaluated (at render-time). Nevow passes a "request > context" as a parameter to the callables; my toy implementation does not. Inside Quixote, you could just call get_request(). > They also use interfaces and component adaptation to adapt various Python > types to Nevow "renderables", a very Twisted thing to do. (I used Sigh. To rephrase Peter Gutmann [1], whenever someone thinks they need to write some complicated new component model, their computer speakers should generate some sort of penis-shaped sound wave and plunge it repeatedly into their skulls until they achieve enlightenment. > Whether you try the code or not, it would be interesting to hear other > people's opinions of the Nevow templating system: is it black magic to be > shunned, the next best thing, or just YATS? It's a neat hack, removes some classes of error such as nesting tags wrongly, could provide automatic escaping if it used htmltext, and might provide a way to guarantee valid HTML output. PTL might be easier to refactor, though, since you can just call subtemplates using Python's usual array of calling mechanisms. I'd suggest taking the idea without using the Twisted implementation. Twisted's Nevow is LGPL'ed, for a start. More importantly, the tags/stan/renderer modules are 552 lines of code + another 450 for twisted.python.component; Graham's implementation is roughly 80 or so lines, which would make it much easier to debug problems. Do we need a public CVS/Subversion repository to serve as a Quixote sandbox for things like this? --amk [1] http://www.mail-archive.com/cryptography@metzdowd.com/msg00891.html)