[Baypiggies] Discussion for newbies/beginner night talks - stan

Drew Perttula drewp at bigasterisk.com
Thu Feb 15 08:21:49 CET 2007


Dennis Reinhardt wrote:
> At 11:03 PM 2/13/2007, Drew Perttula wrote:
> 
>  >Some notes:
>  >The python lists and tuples in the xml-creating code will simply
>  >disappear in the output. T.p["foo", "bar"] renders to "<p>foobar</p>".
> 
> Hmmm... I thought the x[y] syntax was doing an element access on dict or 
> list x to find element y.  If x is an function, then I am guessing that 

Nope, the square brackets are being used in a novel way that creates 
stan structures, which are later rendered as html. It's absolutely 
unguessable and essentially new syntax, except that it follows the 
python rules for subscripting (which do allow comma-separated objects).

Fortunately, the xml angle brackets are completely gone in stan, so a 
python programmer actually has less overall syntax rules to memorize. I 
also never think about xml quoting or unicode issues in my stan 
templates, which is really nice.

The implementation of that special stan syntax is surprisingly simple. 
You can check it out at 
http://divmod.org/trac/browser/trunk/Nevow/nevow/stan.py
Line 313 lets T.p(align="center") save an attribute on a p tag; lines 
336-338 remember the children in T.p[child1, child2, child3].

Other files of interest:

http://divmod.org/trac/browser/trunk/Nevow/nevow/flat/flatstan.py
   -> the rendering of stan into xml (with all the quoting).

http://divmod.org/trac/browser/trunk/Nevow/nevow/tags.py
   -> setup of the standard tags, such as T.p, T.h1, T.table





More information about the Baypiggies mailing list