~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to turbosimpletal/zptsupport.py

  • Committer: Michael Hudson
  • Date: 2008-06-18 04:26:13 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080618042613-ycnc9nsj7txhdby3
re-enable daemonization, remove require("TurboGears")

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"TurboGears support for Zope Page Templates"
2
2
 
3
3
import StringIO
4
 
import logging
5
4
import os
6
5
import pkg_resources
7
6
 
8
7
from simpletal import simpleTAL, simpleTALES
9
8
 
10
 
log = logging.getLogger("turbogears.zptsupport")
11
 
 
12
9
 
13
10
_zpt_cache = {}
14
11
def zpt(tfile):
35
32
        self.template.expandInline(context, s)
36
33
        return s.getvalue()
37
34
 
 
35
    def expand_(self, f, **info):
 
36
        context = simpleTALES.Context(allowPythonPath=1)
 
37
        for k, v in info.iteritems():
 
38
            context.addGlobal(k, v)
 
39
        self.template.expand(context, f, 'utf-8')
 
40
 
38
41
    @property
39
42
    def macros(self):
40
43
        return self.template.macros
64
67
            package, "%s.%s" % (basename, self.extension))
65
68
        return zpt(tfile)
66
69
 
67
 
    def render(self, info, format="html", fragment=False, template=None):
68
 
        """Renders data in the desired format.
69
 
 
70
 
        @param info: the data / context itself
71
 
        @type info: dict
72
 
        @para format: "html"
73
 
        @type format: "string"
74
 
        @para template: name of the template to use
75
 
        @type template: string
76
 
        """
77
 
        tinstance = self.load_template(template)
78
 
        log.debug("Applying template %s" % (tinstance.filename))
79
 
        data = dict()
80
 
        if self.get_extra_vars:
81
 
            data.update(self.get_extra_vars())
82
 
        data.update(info)
83
 
        return tinstance.expand(**data).encode('utf-8')