From: Tavis R. <ta...@ca...> - 2001-04-05 17:44:17
|
Sasa, I've been working on something very similar to what Mike just posted. It's only a few hours off now... The two modules it uses are attached. In the meantime, can you refresh me on how PHPLib does it? In brief, what I'm working on: - uses templates with variable names inserted like this: """ a template with a %[varName]""" """ a template that calls a %[function] """ """ a template that calls a %[object.method] """ """ a template that calls a %[function('with args')""" """ a template that calls a method of an obj in a dict %[dict.object.method(argA=anotherVarName)] """ """ a template that is linked to an object and can call its methods directly %[methodA(arg=1234)] """ a template that is linked to an object and can access its attributes directly %[myAttribute.subItem1] - can search for the variable names in a template in a cascade of objects, dictionaries, classes, BTrees, etc. So if you want to override only a few values and use the defaults for everything else, it's very easy (see the example below) - caching, nesting of templates and all conditional logic are left to standard python or python/psp. This gives the user max. flexibilty to use TemplateFiller how they see fit. It allows you to do something like this: ---------------------------------- from Templates.Report import template, defaults from TemplateFiller import BoundTemplate from Styles import formalStyle from Reports.Quarterly import reportData myValues = { 'bgColor': '#FFFFFF', 'tableWidth': 750, 'reportStyle': formalStyle(), 'reportData': reportData() } output = BoundTemplate(template, myValues, defaults).fill() response.write(output) ----------------------------------- BoundTemplate fills the template with the values from myValues first, and it the variables in the template can't be found in myValues it gets them from defaults. It will continue searching through however many dictionaries you provide it with. BTW, you can leave the () off formalStyle and any other callable objects in myValues (functions, etc.). BoundTemplate will recognize them as callable. Of course all this would be daunting to a non-programming so it could all be abstracted into a single function to hide all the plumming. They would then type this instead: writeReport(type='Quaterly', style='formalStyle', tableWidth=750) Tavis |