1
1
"TurboGears support for Zope Page Templates"
7
from zope.pagetemplate.pagetemplatefile import PageTemplateFile
8
from simpletal import simpleTAL, simpleTALES
9
10
log = logging.getLogger("turbogears.zptsupport")
14
15
tinstance = _zpt_cache.get(tfile)
16
tinstance = _zpt_cache[tfile] = TGPageTemplateFile(tfile)
17
if tinstance is None or tinstance.stat != stat:
18
tinstance = _zpt_cache[tfile] = TemplateWrapper(
19
simpleTAL.compileXMLTemplate(open(tfile)), tfile, stat)
19
class TGPageTemplateFile(PageTemplateFile):
21
def pt_getContext(self, args=(), options={}, **ignored):
22
namespace = super(TGPageTemplateFile, self).pt_getContext(
23
args, options, **ignored)
24
namespace.update(options)
23
class TemplateWrapper(object):
25
def __init__(self, template, filename, stat):
26
self.template = template
27
self.filename = filename
30
def expand(self, **info):
31
context = simpleTALES.Context(allowPythonPath=1)
32
for k, v in info.iteritems():
33
context.addGlobal(k, v)
34
s = StringIO.StringIO()
35
self.template.expandInline(context, s)
40
return self.template.macros
27
43
class TurboZpt(object):