[Checkins] SVN: zope.kgs/trunk/src/zope/kgs/template.py Initial draft of templating support for the KGS site.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jan 27 01:15:48 EST 2009


Log message for revision 95071:
  Initial draft of templating support for the KGS site.
  

Changed:
  A   zope.kgs/trunk/src/zope/kgs/template.py

-=-
Added: zope.kgs/trunk/src/zope/kgs/template.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/template.py	                        (rev 0)
+++ zope.kgs/trunk/src/zope/kgs/template.py	2009-01-27 06:15:48 UTC (rev 95071)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Helper components for the Web site generation.
+"""
+import zope.pagetemplate.pagetemplatefile
+
+class FileContext(object):
+
+    def __init__(path, root):
+        self.path = path
+        self.root = root
+
+    def __call__(self):
+        pt = Template(self.path, root)
+        return pt()
+
+
+class DirectoryContext(object):
+
+    def __init__(self, path, root=None):
+        self.path = path
+        self.root = root or self
+
+    def __getitem__(self, name):
+        path = os.path.join(self.path, name)
+        if os.path.exists(path):
+            return FileContext(path, self.root)
+        return None
+
+
+class Template(zope.pagetemplate.pagetemplatefile.PageTemplateFile):
+
+    def __init__(self, path, templates):
+        super(Template, self).__init__(path)
+        self.templates = templates
+
+    def pt_getContext(self, args=(), options=None, **ignore):
+        rval = {'args': args,
+                'nothing': None,
+                'self': self,
+                'templates': self.templates
+                }
+        rval.update(self.pt_getEngine().getBaseNames())
+        return rval


Property changes on: zope.kgs/trunk/src/zope/kgs/template.py
___________________________________________________________________
Added: svn:keywords
   + Id



More information about the Checkins mailing list