Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add render_tempita class to integrate Tempita templates.

  • Loading branch information...
commit dff0e87fddfce6e81d757b7e0e65b28caabfa5f5 1 parent 0cca746
Michael Gorven authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 web/contrib/template.py
View
24 web/contrib/template.py
@@ -113,6 +113,30 @@ def __getattr__(self, name):
t = self._lookup.get_template(path)
return t.render
+class render_tempita:
+ """Rendering interface to Tempita templates.
+ """
+
+ extensions = {
+ '.html': ('HTMLTemplate', 'text/html; charset=utf-8'),
+ '.xhtml': ('HTMLTemplate', 'application/xhtml+xml; charset=utf-8'),
+ '.txt': ('Template', 'text/plain'),
+ }
+
+ def __init__(self, directories):
+ import tempita
+ self.directories = directories
+
+ def __getattr__(self, name):
+ import tempita
+
+ for directory in self.directories:
+ for extension in self.extensions:
+ filename = os.path.join(directory, name + extension)
+ if os.path.exists(filename):
+ template = getattr(tempita, self.extensions[extension][0]).from_filename(filename)
+ return template.substitute
+
class cache:
"""Cache for any rendering interface.
Please sign in to comment.
Something went wrong with that request. Please try again.