[Checkins] SVN: grok/branches/regebro-guido-templates/s Primitive
Genshi support. Main problems: Bad error messages,
no support for the
Lennart Regebro
regebro at gmail.com
Tue Oct 2 09:02:50 EDT 2007
Log message for revision 80482:
Primitive Genshi support. Main problems: Bad error messages, no support for the
include story.
Changed:
U grok/branches/regebro-guido-templates/setup.py
U grok/branches/regebro-guido-templates/src/grok/components.py
U grok/branches/regebro-guido-templates/src/grok/templatereg.py
-=-
Modified: grok/branches/regebro-guido-templates/setup.py
===================================================================
--- grok/branches/regebro-guido-templates/setup.py 2007-10-02 12:27:51 UTC (rev 80481)
+++ grok/branches/regebro-guido-templates/setup.py 2007-10-02 13:02:50 UTC (rev 80482)
@@ -45,6 +45,7 @@
'martian',
'simplejson',
'pytz',
+ 'Genshi',
'ZODB3 == 3.8.0b2',
'zope.annotation',
'zope.app.apidoc',
Modified: grok/branches/regebro-guido-templates/src/grok/components.py
===================================================================
--- grok/branches/regebro-guido-templates/src/grok/components.py 2007-10-02 12:27:51 UTC (rev 80481)
+++ grok/branches/regebro-guido-templates/src/grok/components.py 2007-10-02 13:02:50 UTC (rev 80482)
@@ -187,6 +187,9 @@
class GrokPageTemplate(object):
+
+ __grok_name__ = ''
+ __grok_location__ = ''
def __repr__(self):
return '<%s template in %s>' % (self.__grok_name__,
@@ -230,6 +233,37 @@
self.__grok_module__ = martian.util.caller_module()
+import genshi.template
+
+class GenshiMarkupTemplate(GrokPageTemplate):
+
+ interface.implements(interfaces.ITemplateFile)
+
+ def __init__(self, filename=None, _prefix=None, html=None):
+ if ((html is not None and filename is not None) or
+ (html is None and filename is None)):
+ raise AssertionError("You must pass either html or filename but not both.")
+
+ if html is not None:
+ self._template = genshi.template.MarkupTemplate(html)
+ else:
+ loader = genshi.template.TemplateLoader(_prefix)
+ self._template = loader.load(filename)
+
+
+ def __call__(self, namespace):
+ stream = self._template.generate(**namespace)
+ return stream.render('xhtml')
+
+ # XXX Ugly temporary ZPT emulation
+ def pt_getContext(self):
+ return {}
+
+ # XXX Ugly temporary ZPT emulation
+ def pt_render(self, namespace):
+ return self(namespace)
+
+
class DirectoryResource(directoryresource.DirectoryResource):
# We subclass this, because we want to override the default factories for
# the resources so that .pt and .html do not get created as page
Modified: grok/branches/regebro-guido-templates/src/grok/templatereg.py
===================================================================
--- grok/branches/regebro-guido-templates/src/grok/templatereg.py 2007-10-02 12:27:51 UTC (rev 80481)
+++ grok/branches/regebro-guido-templates/src/grok/templatereg.py 2007-10-02 13:02:50 UTC (rev 80482)
@@ -79,7 +79,15 @@
grok.implements(grok.interfaces.ITemplateFactory)
grok.name('pt')
+ def __call__(self, filename, _prefix=None):
+ return grok.components.PageTemplateFile(filename, _prefix)
+
+
+class GenshiMarkupTemplateFileFactory(grok.GlobalUtility):
+ grok.implements(grok.interfaces.ITemplateFactory)
+ grok.name('gmt')
+
def __call__(self, filename, _prefix=None):
- return grok.components.PageTemplateFile(filename, _prefix)
+ return grok.components.GenshiMarkupTemplate(filename, _prefix)
\ No newline at end of file
More information about the Checkins
mailing list