File: templates.py

package info (click to toggle)
python-jtoolkit 0.7.8-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,436 kB
  • ctags: 2,536
  • sloc: python: 15,143; makefile: 20
file content (28 lines) | stat: -rwxr-xr-x 853 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""This is a match from HTMLTemplate to our widget structure"""

import HTMLTemplate
from jToolkit.widgets import widgets

class TemplateWidget(widgets.Widget, HTMLTemplate.Template):
  """A widget that generates its code using templates"""
  def __init__(self, htmltemplate, **kwargs):
    HTMLTemplate.Template.__init__(self, self.render, htmltemplate)
    self.kwargs = kwargs
    widgets.Widget.__init__(self, "template")

  def gethtml(self):
    """actually render the template"""
    return HTMLTemplate.Template.render(self)

class TestTemplate(TemplateWidget):
  def render(self, clone):
    clone.title.content = clone.kwargs["title"]

if __name__ == "__main__":
  t = TestTemplate("<h1 node='con:title'>title</h1>", title="Test")
  print t.gethtml("This title")
  print t.gethtml("That title")