~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to turbosimpletal/zptsupport.py

  • Committer: Michael Hudson
  • Date: 2008-06-13 05:33:39 UTC
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: michael.hudson@canonical.com-20080613053339-w1in3qyd8gq3e8zg
more progress

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        self.template.expandInline(context, s)
36
36
        return s.getvalue()
37
37
 
 
38
    def expand_(self, f, **info):
 
39
        context = simpleTALES.Context(allowPythonPath=1)
 
40
        for k, v in info.iteritems():
 
41
            context.addGlobal(k, v)
 
42
        self.template.expand(context, f, 'utf-8')
 
43
 
38
44
    @property
39
45
    def macros(self):
40
46
        return self.template.macros
64
70
            package, "%s.%s" % (basename, self.extension))
65
71
        return zpt(tfile)
66
72
 
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')