Can't subclass when docFactory is a loaders.stan instance.

Is there anyway when constructing a page using stan to use render_* methods which are defined in the subclass? e.g. class Template (rend.Page): docFactory=loaders.stan(T.html()[T.title()[T.span(render='title')]]) class Foo (Template): def render_title (self, ctx, data): return 'My title is Foo' If I assign a string to render (in the T.span attribute) then the string is just returned rather than a render_* method being called. If I assign a render_* method (eg 'render_title') to render then the rendering is done by calling the method in Template not in the subclass. For instance this does not work: class Template (rend.Page): def render_title (self, ctx, data): raise NotImplementedError docFactory = \ loaders.stan(T.html()[T.title()[T.span(render=render_title)]]) class Foo (Template): def render_title (self, ctx, data): return 'My title is Foo' I don't have this issue if I use loaders.htmlfile() and store my stuff in an html file. Thanks for your help. -Pat. ============================ Patrick Day uf069@victoria.tc.ca

On Sep 9, 2004, at 3:06 PM, Patrick B. Day wrote:
Is there anyway when constructing a page using stan to use render_* methods which are defined in the subclass?
The same way the HTML templates cause an invocation of a render_* method -- by setting the render special on a Tag to a directive. Sorry it's not better documented: class Foo(Page): docFactory = rend.stan(tags.html[ tags.head[ tags.title(render=tags.directive('title'))], tags.body[ tags.h1(render=tags.directive('header')), tags.div(render=tags.directive('body'))]] class Bar(Foo): def render_title(self, ctx, data): return ctx.tag["Hello Title"] def render_header(self, ctx, data): return ctx.tag["Hello Header"] def render_body(self, ctx, data): return ctx.tag["Hello Body"] By the way, this is a perfect example of where you would want to use the macro special, when it is implemented. Page would have to have a metaclass that cloned and compiled a unique copy of the superclass' docFactory, but after that all the non-dynamic nodes (nodes without a render method) would be optimized into contiguous string runs. As it is now, the render methods run every time the page is hit, which isn't too big of a deal but is slightly slower. dp
participants (2)
-
Donovan Preston
-
Patrick B. Day