From f072c6b7f987d9ec7131ac8805e46f3bbc9399cb Mon Sep 17 00:00:00 2001 From: helmutm Date: Fri, 24 Nov 2006 17:52:43 +0000 Subject: [PATCH] make zpt implementation basically working git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1522 fd906abe-77d9-0310-91a1-e0d9ade77398 --- web/README.txt | 4 ++-- web/configure.zcml | 10 ++++++++ web/template.py | 4 ++++ web/zpt/configure.zcml | 16 +++++++++++++ web/zpt/content.pt | 6 ++--- web/zpt/main.pt | 54 ++++++++++++++++++++++++++++++++++++++++++ web/zpt/template.py | 16 +++++++++++++ 7 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 web/configure.zcml create mode 100644 web/zpt/configure.zcml create mode 100644 web/zpt/main.pt diff --git a/web/README.txt b/web/README.txt index 202e1b6..b103071 100644 --- a/web/README.txt +++ b/web/README.txt @@ -15,7 +15,7 @@ calls a `main` macro and fills a slot there. But at least the template implementation is decoupled from the view, so we are able to put a lot of generic functionality into the view. -But in order to make a ZPT work we need a Zope-compatible request, so we use +In order to make a ZPT work we need a Zope-compatible request, so we use the standard Zope 3 TestRequest. >>> from zope.publisher.browser import TestRequest @@ -23,5 +23,5 @@ the standard Zope 3 TestRequest. >>> from cybertools.web.view import View >>> view = View(None, TestRequest()) >>> view.render() - u'............' + u'< html...>............' diff --git a/web/configure.zcml b/web/configure.zcml new file mode 100644 index 0000000..dd31ae9 --- /dev/null +++ b/web/configure.zcml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/web/template.py b/web/template.py index b4eb9bd..dfdb0a1 100644 --- a/web/template.py +++ b/web/template.py @@ -22,6 +22,9 @@ Generic template base class. $Id$ """ +from zope.app.traversing.adapters import DefaultTraversable +from zope import component + class Template(object): @@ -33,3 +36,4 @@ class Template(object): def render(self, *args, **kw): return u'' +component.provideAdapter(DefaultTraversable, (Template,)) diff --git a/web/zpt/configure.zcml b/web/zpt/configure.zcml new file mode 100644 index 0000000..c072812 --- /dev/null +++ b/web/zpt/configure.zcml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/web/zpt/content.pt b/web/zpt/content.pt index ae87358..cfdc7c3 100644 --- a/web/zpt/content.pt +++ b/web/zpt/content.pt @@ -1,14 +1,14 @@ - - +
This is the body
-
+ diff --git a/web/zpt/main.pt b/web/zpt/main.pt new file mode 100644 index 0000000..4b56ac7 --- /dev/null +++ b/web/zpt/main.pt @@ -0,0 +1,54 @@ + + + + + + Powered by Zope 3 + + + + + + + + + + +
+
+ +
+
+ + + +
+ + + + Here comes the body + +
+ +
+ +
+ + + + + + +
+ diff --git a/web/zpt/template.py b/web/zpt/template.py index 495a949..ac0d016 100644 --- a/web/zpt/template.py +++ b/web/zpt/template.py @@ -23,6 +23,7 @@ $Id$ """ from zope.app.pagetemplate import ViewPageTemplateFile +from zope.cachedescriptors.property import Lazy from cybertools.web import template @@ -30,6 +31,21 @@ class Template(template.Template): zpt = ViewPageTemplateFile('content.pt') + macroTemplate = ViewPageTemplateFile('main.pt') + + skin = None + + @Lazy + def main_macro(self): + return self.macroTemplate.macros['page'] + + @Lazy + def resourceBase(self): + skinSetter = self.skin and ('/++skin++' + self.skin.__name__) or '' + # TODO: put '/@@' etc after path to site instead of directly after URL0 + return self.request.URL[0] + skinSetter + '/@@/' + def render(self, *args, **kw): + kw['template'] = self return self.zpt(*args, **kw)