More API BBB: Provide hook (pt_macros) for subclasses to do stuff when

macro access happens.
parent 9a829cef
...@@ -17,6 +17,8 @@ $Id$ ...@@ -17,6 +17,8 @@ $Id$
import sys import sys
import ExtensionClass import ExtensionClass
import zope.pagetemplate.pagetemplate import zope.pagetemplate.pagetemplate
from zope.pagetemplate.pagetemplate import PTRuntimeError
from zope.pagetemplate.pagetemplate import PageTemplateTracebackSupplement
from zope.tales.expressions import SimpleModuleImporter from zope.tales.expressions import SimpleModuleImporter
from Products.PageTemplates.Expressions import getEngine from Products.PageTemplates.Expressions import getEngine
...@@ -31,13 +33,11 @@ zope.deprecation.deprecated( ...@@ -31,13 +33,11 @@ zope.deprecation.deprecated(
"to zope.pagetemplate.pagetemplate.SimpleModuleImporter (this is a " "to zope.pagetemplate.pagetemplate.SimpleModuleImporter (this is a "
"class, not an instance)." "class, not an instance)."
) )
zope.deprecation.deprecated(
import zope.deferredimport ('PTRuntimeError', 'PageTemplateTracebackSupplement'),
zope.deferredimport.deprecatedFrom( "Zope 2 uses the Zope 3 ZPT engine now. The object you're importing "
"It has moved to zope.pagetemplate.pagetemplate. This reference will " "has moved to zope.pagetemplate.pagetemplate. This reference will "
"be gone in Zope 2.12.", "be gone in Zope 2.12.",
'zope.pagetemplate.pagetemplate',
'PTRuntimeError', 'PageTemplateTracebackSupplement'
) )
############################################################################## ##############################################################################
...@@ -65,6 +65,21 @@ class PageTemplate(ExtensionClass.Base, ...@@ -65,6 +65,21 @@ class PageTemplate(ExtensionClass.Base,
c['root'] = self c['root'] = self
return c return c
@property
def macros(self):
return self.pt_macros()
# sub classes may override this to do additional stuff for macro access
def pt_macros(self):
self._cook_check()
if self._v_errors:
__traceback_supplement__ = (PageTemplateTracebackSupplement, self, {})
raise PTRuntimeError, (
'Page Template %s has errors: %s' % (
self.id, self._v_errors
))
return self._v_macros
# these methods are reimplemented or duplicated here because of # these methods are reimplemented or duplicated here because of
# different call signatures in the Zope 2 world # different call signatures in the Zope 2 world
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment