[Checkins] SVN: z3c.pt/trunk/ Add a TemplateLoader class to have a
convenient method to instantiate
Wichert Akkerman
wichert at wiggy.net
Fri Aug 8 06:16:45 EDT 2008
Log message for revision 89540:
Add a TemplateLoader class to have a convenient method to instantiate
templates. This is similar to the template loaders from other template
toolkits and makes integration with Pylons a lot simpler.
Changed:
U z3c.pt/trunk/CHANGES.txt
A z3c.pt/trunk/src/z3c/pt/loader.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2008-08-08 10:15:24 UTC (rev 89539)
+++ z3c.pt/trunk/CHANGES.txt 2008-08-08 10:16:44 UTC (rev 89540)
@@ -4,6 +4,11 @@
Version 0.9.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Add a TemplateLoader class to have a convenient method to instantiate
+ templates. This is similar to the template loaders from other template
+ toolkits and makes integration with Pylons a lot simpler.
+ [wichert]
+
- Switch from hardcoding all options in config.py to using parameters
for the template. This also allows us to use the more logical
auto_reload flag instead of reusing PROD_MODE, which is also used
Added: z3c.pt/trunk/src/z3c/pt/loader.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/loader.py (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/loader.py 2008-08-08 10:16:44 UTC (rev 89540)
@@ -0,0 +1,41 @@
+import errno
+import os.path
+from z3c.pt.pagetemplate import PageTemplateFile
+from z3c.pt.texttemplate import TextTemplateFile
+
+class TemplateLoader(object):
+ """Template loader tool.
+ """
+
+ def __init__(self, search_path=None, auto_reload=False, cachedir=None):
+ self.search_path = search_path is not None and search_path or []
+ self.auto_reload = auto_reload
+ self.cachedir = cachedir
+ if cachedir is not None:
+ if not os.path.isdir(cachedir):
+ raise ValueError, "Invalid cachedir")
+
+
+ def _load(self, filename, klass):
+ if os.path.isabs(filename):
+ return PageTemplateFile(filename)
+
+ for path in self.search_path:
+ path = os.path.join(path, filename)
+ try:
+ return klass(path, auto_reload=self.auto_reload,
+ cachedir=self.cachedir)
+ except OSError, e:
+ if e.errno!=erro.ENOENT:
+ raise
+
+ raise ValueError("Can not find template %s" % filename)
+
+
+ def load_page(self, filename):
+ return self._load(filename, PageTemplateFile)
+
+
+ def load_text(self, filename):
+ return self._load(filename, TextTemplateFile)
+
Property changes on: z3c.pt/trunk/src/z3c/pt/loader.py
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the Checkins
mailing list