[Grok-dev] megrok.genshi
Shane Hathaway
shane at hathawaymix.org
Fri Mar 6 05:13:15 EST 2009
Grokstars,
I just tried out megrok.genshi (along with the rest of Grok, which is
looking good, BTW). It didn't work until I patched it. The patch below
fixes two problems:
- Grok 1.0a1 doesn't have an interface named ITemplateFileFactory in
grok.interface. The interface is located in grokcore.view.interfaces.
- Auto-reload didn't work.
Should I check in this change?
Shane
Index: components.py
===================================================================
--- components.py (revision 97554)
+++ components.py (working copy)
@@ -15,20 +15,23 @@
import zope.interface
import genshi.template
import grokcore.view.components
+import grokcore.view.interfaces
import grok
class GenshiTemplateBase(grokcore.view.components.GrokTemplate):
-
+
def render(self, view):
- stream = self._template.generate(**self.getNamespace(view))
+ template = self._get_template()
+ stream = template.generate(**self.getNamespace(view))
return stream.render(self.result_type)
def setFromString(self, string):
- self._template = self.cls(string)
-
+ template = self.cls(string)
+ self._get_template = lambda: template
+
def setFromFilename(self, filename, _prefix=None):
- loader = genshi.template.TemplateLoader(_prefix)
- self._template = loader.load(filename, cls=self.cls)
+ loader = genshi.template.TemplateLoader(_prefix, auto_reload=True)
+ self._get_template = lambda: loader.load(filename, cls=self.cls)
class GenshiMarkupTemplate(GenshiTemplateBase):
@@ -42,7 +45,7 @@
class GenshiMarkupTemplateFactory(grok.GlobalUtility):
- zope.interface.implements(grok.interfaces.ITemplateFileFactory)
+
zope.interface.implements(grokcore.view.interfaces.ITemplateFileFactory)
grok.name('g')
def __call__(self, filename, _prefix=None):
@@ -50,7 +53,7 @@
class GenshiTextTemplateFactory(grok.GlobalUtility):
- zope.interface.implements(grok.interfaces.ITemplateFileFactory)
+
zope.interface.implements(grokcore.view.interfaces.ITemplateFileFactory)
grok.name('gt')
def __call__(self, filename, _prefix=None):
More information about the Grok-dev
mailing list