make zpt implementation basically working

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1522 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-11-24 17:52:43 +00:00
parent 5f9675c871
commit f072c6b7f9
7 changed files with 105 additions and 5 deletions

View file

@ -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'<html...>...<body...>...</body>...</html>...'
u'< html...>...<body...>...</body>...</html>...'

10
web/configure.zcml Normal file
View file

@ -0,0 +1,10 @@
<!-- $Id$ -->
<configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope">
<zope:include package=".zpt" />
</configure>

View file

@ -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,))

16
web/zpt/configure.zcml Normal file
View file

@ -0,0 +1,16 @@
<!-- $Id$ -->
<configure
xmlns:zope="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope">
<browser:page
for="*"
name="dummy.html"
class="cybertools.web.view.View"
attribute="render"
permission="zope.View"
/>
</configure>

View file

@ -1,14 +1,14 @@
<html x_metal:use-macro="context/@@skin_macros/page"
<html metal:use-macro="options/template/main_macro"
i18n:domain="zope">
<head></head>
<body>
<x_metal:body fill-slot="body">
<metal:body fill-slot="body">
<div>
This is the body
</div>
</x_metal:body>
</metal:body>
</body>

54
web/zpt/main.pt Normal file
View file

@ -0,0 +1,54 @@
<metal:block define-macro="page"><metal:block define-slot="doctype"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></metal:block>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
i18n:domain="zope">
<head metal:define-macro="head">
<title metal:define-slot="title"
tal:content="options/title|view/headTitle|view/title|context/title|default">
Powered by Zope 3
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<metal:block define-slot="ecmascript_slot" />
<link rel="icon" type="image/png"
tal:attributes="href string:${options/template/resourceBase}favicon.png" />
</head>
<body metal:define-macro="body">
<div id="global">
<div class="top" metal:define-slot="top">
<a href="#" name="top" metal:define-slot="logo"
tal:attributes="href string:request/URL/1"><img class="logo"
src="logo.gif" border="0" alt="Home"
tal:attributes="src string:logo.gif" /></a>
</div>
</div>
<div id="menu">
<metal:menu define-slot="navigators">
</metal:menu>
</div>
<div id="content">
<metal:message metal:define-slot="message" />
<metal:content define-slot="body">Here comes the body</metal:content>
</div>
<div id="sub-section">
<metal:sub define-slot="context_information"></metal:sub>
</div>
<div id="footer" class="footer">
<metal:footer define-slot="footer" />
</div>
</body>
</html>
</metal:block>

View file

@ -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)