[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/presentation/ Added
++debug++source, tal for ZPT Templates.
Marius Gedminas
marius at pov.lt
Sat Jun 12 11:58:17 EDT 2004
Log message for revision 25404:
Added ++debug++source,tal for ZPT Templates.
-=-
Modified: Zope3/trunk/src/zope/app/presentation/tests/test_zpt.py
===================================================================
--- Zope3/trunk/src/zope/app/presentation/tests/test_zpt.py 2004-06-12 15:38:12 UTC (rev 25403)
+++ Zope3/trunk/src/zope/app/presentation/tests/test_zpt.py 2004-06-12 15:58:17 UTC (rev 25404)
@@ -20,6 +20,21 @@
from zope.publisher.browser import TestRequest
from zope.app.publisher.browser import BrowserView
+# All this just to get zapi.getPath() work :(
+from zope.app.tests import ztapi
+from zope.interface import directlyProvides
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.traversing.interfaces import IPhysicallyLocatable
+from zope.app.traversing.interfaces import IContainmentRoot
+from zope.app.location.traversing import LocationPhysicallyLocatable
+from zope.app.traversing.adapters import RootPhysicallyLocatable
+from zope.app.container.contained import contained
+
+
+class Data(object):
+ pass
+
+
class Test(TestCase):
# XXX We need tests for the template class itself and for the
@@ -38,7 +53,7 @@
source = '<p>Test content</p>'
template.source = '<p>Old content</p>'
adapter = WriteFile(template)
- adapter.write(source)
+ adapter.write(source)
self.assertEqual(template.source, source)
def test_ZPTFactory(self):
@@ -46,9 +61,53 @@
source = '<p>Test content</p>'
template = factory('foo', 'text/html', source)
self.assertEqual(template.source, source)
-
+
+class TestDebugFlags(PlacelessSetup, TestCase):
+
+ def setUp(self):
+ PlacelessSetup.setUp(self)
+ ztapi.provideAdapter(
+ None, IPhysicallyLocatable, LocationPhysicallyLocatable)
+ ztapi.provideAdapter(
+ IContainmentRoot, IPhysicallyLocatable, RootPhysicallyLocatable)
+
+ def test_source_file(self):
+ template = ZPTTemplate()
+ self.assert_(template.pt_source_file() is None)
+
+ template = self.pageInContext(template)
+ self.assertEquals(template.pt_source_file(), '/folder/zpt')
+
+ def pageInContext(self, page):
+ root = Data()
+ directlyProvides(root, IContainmentRoot)
+ folder = contained(Data(), root, name='folder')
+ return contained(page, folder, name='zpt')
+
+ def test_debug_flags(self):
+ template = self.pageInContext(ZPTTemplate())
+ template.source = '<tal:p>Test</tal:p>'
+
+ self.request = TestRequest()
+ self.context = None
+ self.assertEquals(template.render(self), 'Test\n')
+
+ self.request.debug.showTAL = True
+ self.assertEquals(template.render(self), '<tal:p>Test</tal:p>\n')
+
+ self.request.debug.showTAL = False
+ self.request.debug.sourceAnnotations = True
+ self.assertEquals(template.render(self),
+ '<!--\n' +
+ '=' * 78 + '\n' +
+ '/folder/zpt (line 1)\n' +
+ '=' * 78 + '\n' +
+ '-->Test\n')
+
+
def test_suite():
return TestSuite((
makeSuite(Test),
+ makeSuite(TestDebugFlags),
))
Modified: Zope3/trunk/src/zope/app/presentation/zpt.py
===================================================================
--- Zope3/trunk/src/zope/app/presentation/zpt.py 2004-06-12 15:38:12 UTC (rev 25403)
+++ Zope3/trunk/src/zope/app/presentation/zpt.py 2004-06-12 15:58:17 UTC (rev 25404)
@@ -30,6 +30,7 @@
from zope.app.filerepresentation.interfaces import IFileFactory
from zope.app.pagetemplate.engine import AppPT
from zope.pagetemplate.pagetemplate import PageTemplate
+from zope.app import zapi
class IZPTInfo(Interface):
"""ZPT Template configuration information
@@ -87,6 +88,12 @@
namespace['context'] = view.context
return namespace
+ def pt_source_file(self):
+ try:
+ return zapi.getPath(self)
+ except TypeError:
+ return None
+
def render(self, view, *args, **keywords):
if args:
@@ -101,8 +108,10 @@
kw = ProxyFactory(keywords)
namespace = self.pt_getContext(view, args=args, options=kw)
+ debug_flags = view.request.debug
- return self.pt_render(namespace)
+ return self.pt_render(namespace, showtal=debug_flags.showTAL,
+ sourceAnnotations=debug_flags.sourceAnnotations)
# Adapters for file-system emulation
More information about the Zope3-Checkins
mailing list