Overview
Comment: | Started Template class with basic Tcl rendering skillz. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | trunk |
Files: | files | file ages | folders |
SHA1: |
8eace4b0e02cd9a671f1c648383fa9dc |
User & Date: | setok on 2010-08-02 18:42:23 |
Other Links: | manifest | tags |
Context
2010-08-02
| ||
18:42 | Started Template class with basic Tcl rendering skillz. Leaf check-in: 8eace4b0e0 user: setok tags: trunk | |
18:28 | initial empty check-in check-in: 56df9b8406 user: Setok tags: trunk | |
Changes
Added tcl_templates.py version [f0d2f15be5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | import Tkinter #from django.template import RequestContext from django.template import Template #from django.template.loaders import app_directories class TclTemplate(Template): interp = None def __init__(self, source): Template.__init__(self, source) self.interp = Tkinter.Tcl() self.source = source def assoc_ob(self, ob): def caller(*args): func = getattr(ob, args[0]) return func() proc = self.interp.register(caller) #interp.setvar(var, proc) return proc def render(self, context): # flatten the Django Context into a single dictionary. context_dict = {} for (k, v) in context.iteritems(): if type(v).__name__ == 'instance': v = self.assoc_ob(v) self.interp.setvar(k, v) return self.interp.call("subst", self.source) for d in context.dicts: context_dict.update(d) l = dict_to_list(context_dict) return super(Template, self).render(context_dict) # class TclTemplateLoader(BaseLoader): # is_usable = True # def load_template(self, template_name, template_dirs=None): # source, origin = self.load_template_source(template_name, template_dirs) # template = TclTemplate(source) # return template, origin |