operating on literals in nevow html templates

I'm using Nevow along with designers who use a WYSIWYG HTML editor, and it's working like a dream! However, I've run into an interesting scenario, and I was wondering if anyone has any advice or best practices to recommend. I would like to perform a transformation something like the following in my completed code: <a href="GUI_GENERATED_CALL(garbage, 'WindowName', 'WindowParams')"
Click here for a popup</a>
to <a href="dynamicCall('dynamicData', 'WindowName', 'WindowParams')"
Click here for a popup</a>
It's acceptable for me to bend, fold, or otherwise mutilate the designer-provided tag to some degree, so something like: <a href="GUI_GENERATED_CALL(garbage, 'WindowName', 'WindowParams')" nevow:data="{'name' : 'WindowName', 'params' : 'WindowParams'}" nevow:render="dynamicPopup"
Click here for a popup</a>
would be fine- but the literal parameters I need to preserve need to be under the control of the designers and present in the template rather than in the code. Any advice or pointers on how this sort of thing should be handled? Thanks for your help! -------------------- Joe Bowers Technical Director Seventy-two dpi 828.252.2408 [x308] joe@seventytwodpi.com http://www.seventytwodpi.com

If you can add n:render='dynamicPopup' to any links you want to process, then you can access the href attribute of that tag with "context.tag.attributes['href']" within your render method. To change it, first clone context.tag, modify the clone, and then return it, like so: def render_dynamicCall( self, context, data ): copy = context.tag.clone() href = copy.attributes['href'] # modify href to your liking copy.attributes['href'] = href return copy On Mon, Apr 12, 2004 at 04:59:02PM -0400, Joe Bowers wrote:
I'm using Nevow along with designers who use a WYSIWYG HTML editor, and it's working like a dream! However, I've run into an interesting scenario, and I was wondering if anyone has any advice or best practices to recommend.
I would like to perform a transformation something like the following in my completed code:
<a href="GUI_GENERATED_CALL(garbage, 'WindowName', 'WindowParams')"
Click here for a popup</a>
to
<a href="dynamicCall('dynamicData', 'WindowName', 'WindowParams')"
Click here for a popup</a>
It's acceptable for me to bend, fold, or otherwise mutilate the designer-provided tag to some degree, so something like:
<a href="GUI_GENERATED_CALL(garbage, 'WindowName', 'WindowParams')" nevow:data="{'name' : 'WindowName', 'params' : 'WindowParams'}" nevow:render="dynamicPopup"
Click here for a popup</a>
would be fine- but the literal parameters I need to preserve need to be under the control of the designers and present in the template rather than in the code.
Any advice or pointers on how this sort of thing should be handled?
Thanks for your help!
-------------------- Joe Bowers Technical Director Seventy-two dpi
828.252.2408 [x308] joe@seventytwodpi.com http://www.seventytwodpi.com

On Apr 12, 2004, at 4:59 PM, Joe Bowers wrote: <snip>
It's acceptable for me to bend, fold, or otherwise mutilate the designer-provided tag to some degree, so something like:
<a href="GUI_GENERATED_CALL(garbage, 'WindowName', 'WindowParams')" nevow:data="{'name' : 'WindowName', 'params' : 'WindowParams'}" nevow:render="dynamicPopup"
Click here for a popup</a>
would be fine- but the literal parameters I need to preserve need to be under the control of the designers and present in the template rather than in the code.
There is an experimental feature in the Nevow codebase that probably not too many people know about. I call them render parameters. They were designed for almost exactly this use, to allow designers to provide parameters to a renderer which will affect how it renders. The syntax is a bit odd and probably still open for discussion, but it is currently: <a nevow:render="dynamicPopup WindowName,WindowParams">Click here</a> The renderer name and arguments are separated by a space; the individual arguments are separated by commas. The arguments would be sent to the render method like so: def render_dynamicPopup(self, name, params): print name, params return "woo" Since you probably also want access to the context and data parameters normally passed to a renderer, you probably want to create and return a closure (nested function) which gets ctx and data: def render_dynamicPopup(self, name, params): def nestedFunction(ctx, data): print name, params, ctx, data # has access to name and params because they are "closed over" return "woo" return nestedFunction This is still a somewhat experimental feature; there is an example of usage in "sandbox/mg/reroot.py". If you try it out, please give us feedback on whether it solves your problem, how useful it is, and whether the syntax or semantics could be improved to make it more useful. dp
participants (3)
-
Donovan Preston
-
indigo@bitglue.com
-
Joe Bowers