Revamped ContextSerializer/TagSerializer and other contextish stuff
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
The HTTP output encoding is set to UTF-8 in renderer, and unicode strings are automatically encoded in utf-8 for output. If any browsers can't deal with UTF-8, screw them. ;) Revamping of TagSerializer and ContextSerializer to be more sensible. 1) Context chaining works properly now. - Precompiling a stan tree, html[body[ul(renderer=foo)[li[a(data="Bar")]]]] will result in the following (paraphrased): "<html><body>", WovenContext(parents=body,html, tag=ul(renderer=foo)[ "<li>",WovenContext(IData="Bar", parents=li, tag=a), "</li>"], "</body></html>" The thing to notice is that the parent context chain is cut off whenever a WovenContext is inserted into the actual tree, as it is redundant, and possibly wrong (since e.g. a renderer function could reparent its subtrees) In ContextSerializer, the rendering context is chained onto the end of the remembered context, thus creating the full context chain. 2) Because of the above change, stripContexts isn't needed anymore. 3) Contexts have an "isAttrib" field now, indicating whether the context is within an attribute value. This is used by StringSerializer to properly escape quotes. 4) Contexts don't erase their parent tag field when cloned. 5) ContextSerializer tells TagSerializer that the context is its own, and not to make a new context. 6) Removed a bunch of rendundant cloning. Renderer.precompile, WovenContext.patterns ContextSerializer uses shallow clone. 7) Tag.clone(deep=False) copies its children list. James This fixed the following bugs that noone noticed yet: - Attribute context doesn't contain tag. - Attribute values don't always get " quoted. - Extra contexts got put in the chain by TagSerializer sometimes. Ideas for new tests: 1) Render multiple times from one precompiled document, with mutation of context.tag by renderer function. 2) Attribute context is the context of their own tag. 3) Renderer can check its context chain to make sure that it looks proper (e.g. has the right parents from the stan tree). With and without precompilation and dynamic elements.
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
Fixes directive() used as a render function, which the previous broke. Apparently there are no tests for that. Also adjusts components.wsv which I forgot in the last patch. James
participants (1)
-
James Y Knight