[Checkins] SVN: grokcore.chameleon/trunk/src/grokcore/chameleon/components.py adding a chameleonpagetemplatefile
Christian Klinger
cklinger at novareto.de
Tue Dec 13 13:42:14 UTC 2011
Log message for revision 123799:
adding a chameleonpagetemplatefile
Changed:
U grokcore.chameleon/trunk/src/grokcore/chameleon/components.py
-=-
Modified: grokcore.chameleon/trunk/src/grokcore/chameleon/components.py
===================================================================
--- grokcore.chameleon/trunk/src/grokcore/chameleon/components.py 2011-12-13 13:35:45 UTC (rev 123798)
+++ grokcore.chameleon/trunk/src/grokcore/chameleon/components.py 2011-12-13 13:42:14 UTC (rev 123799)
@@ -12,7 +12,11 @@
#
##############################################################################
"""Chameleon page template components"""
+
import os
+import sys
+import martian
+
from grokcore.component import GlobalUtility, implements, name
from grokcore.view import interfaces
from grokcore.view.components import GrokTemplate
@@ -29,7 +33,7 @@
#
# Chameleon Zope Page Templates...
#
-class PageTemplate(PageTemplate):
+class PageTemplate(PageTemplate, GrokTemplate):
"""A `z3c.pt` page template suitable for use with views.
This page template implementation is different from `z3c.pt`
@@ -38,7 +42,7 @@
- It sets ``python`` as default mode (instead of ``path``)
- It injects any views ``static`` variable in template namespace.
"""
- default_expression = 'python' # Use the chameleon default
+ default_expression = 'python' # Use the chameleon default
expression_types = {
'python': PythonExpr,
@@ -63,6 +67,7 @@
"""
default_expression = 'python'
+
class ChameleonPageTemplate(GrokTemplate):
def setFromString(self, string):
@@ -82,9 +87,20 @@
def render(self, view):
return self._template(**self.getNamespace(view))
+
+class ChameleonPageTemplateFile(ChameleonPageTemplate):
+
+ def __init__(self, filename, _prefix=None):
+ self.__grok_module__ = martian.util.caller_module()
+ if _prefix is None:
+ module = sys.modules[self.__grok_module__]
+ _prefix = os.path.dirname(module.__file__)
+ self.setFromFilename(filename, _prefix)
+
+
class ChameleonPageTemplateFactory(GlobalUtility):
implements(interfaces.ITemplateFileFactory)
name('cpt')
def __call__(self, filename, _prefix=None):
- return ChameleonPageTemplate(filename=filename, _prefix=_prefix)
+ return ChameleonPageTemplate(filename=filename, _prefix=_prefix)
\ No newline at end of file
More information about the checkins
mailing list