/usr/share/pyshared/z3c/macro/zcml.txt is in python-z3c.macro 1.4.2-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | ===============
macro directive
===============
A macro directive can be used for register macros. Take a look at the
README.txt which explains the macro TALES expression.
>>> import sys
>>> from zope.configuration import xmlconfig
>>> import z3c.template
>>> context = xmlconfig.file('meta.zcml', z3c.macro)
First define a template which defines a macro:
>>> import os, tempfile
>>> temp_dir = tempfile.mkdtemp()
>>> file = os.path.join(temp_dir, 'file.pt')
>>> open(file, 'w').write('''
... <html>
... <head>
... <metal:block define-macro="title">
... <title>Pagelet skin</title>
... </metal:block>
... </head>
... <body>
... <div>content</div>
... </body>
... </html>
... ''')
and register the macro provider within the ``z3c:macroProvider`` directive:
>>> context = xmlconfig.string("""
... <configure
... xmlns:z3c="http://namespaces.zope.org/z3c">
... <z3c:macro
... template="%s"
... name="title"
... />
... </configure>
... """ % file, context=context)
We need a content object...
>>> import zope.interface
>>> class Content(object):
... zope.interface.implements(zope.interface.Interface)
>>> content = Content()
and we need a view...
>>> import zope.interface
>>> import zope.component
>>> from zope.publisher.browser import BrowserPage
>>> class View(BrowserPage):
... def __init__(self, context, request):
... self.context = context
... self.request = request
and we need a request:
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
Check if we get the macro template:
>>> from z3c.macro import interfaces
>>> view = View(content, request)
>>> macro = zope.component.queryMultiAdapter((content, view, request),
... interface=interfaces.IMacroTemplate, name='title')
>>> macro is not None
True
>>> import os, tempfile
>>> temp_dir = tempfile.mkdtemp()
>>> file = os.path.join(temp_dir, 'test.pt')
>>> open(file, 'w').write('''
... <html>
... <body>
... <metal:macro use-macro="options/macro" />
... </body>
... </html>
... ''')
>>> from zope.browserpage.viewpagetemplatefile import BoundPageTemplate
>>> from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
>>> template = ViewPageTemplateFile(file)
>>> print BoundPageTemplate(template, view)(macro=macro)
<html>
<body>
<title>Pagelet skin</title>
</body>
</html>
|