12
def _compile_template(tfile):
13
mod = PageTemplate(tfile)
14
mtime = os.stat(tfile).st_mtime
19
if tfile in _zpt_cache:
20
mtime = os.stat(tfile).st_mtime
21
mod = _zpt_cache[tfile]
22
if mod.__mtime__ != mtime:
23
mod = _compile_template(tfile)
24
_zpt_cache[tfile] = mod
26
mod = _zpt_cache[tfile] = _compile_template(tfile)
10
29
class Here(object):
11
30
def __init__(self, base, options):
13
32
self.options = options
15
34
def __getitem__(self, name):
16
tpl = PageTemplate(os.path.join(self.base, name))
17
tpl.add_context(self.options)
35
tpl = zpt(os.path.join(self.base, name))
36
return tpl(**self.options)
20
38
class PageTemplate(pagetemplatefile.PageTemplateFile):
21
39
def __init__(self, name):
22
40
base = os.path.dirname(sys._getframe(1).f_globals["__file__"])
23
self.extra_context = {}
25
42
self.fullpath = os.path.join(base, self.name)
26
43
self.base = os.path.dirname(self.fullpath)
27
44
pagetemplatefile.PageTemplateFile.__init__(self, self.fullpath)
29
def render(self, extra_dict=None):
30
if extra_dict is None:
32
context = self.pt_getContext()
33
context.update(extra_dict)
34
return self.pt_render(context)
36
def add_context(self, d):
37
self.extra_context.update(d)
39
46
def pt_getContext(self, args=(), options={}, **ignored):
40
47
rval = pagetemplatefile.PageTemplateFile.pt_getContext(self, args, options, **ignored)
41
48
rval.update(options)
42
rval.update(self.extra_context)
43
49
rval.update({'here':Here(self.base, options), 'template':self})