-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
111 additions
and
1,004 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,16 @@ | ||
Overview | ||
======== | ||
|
||
This package implements a compatibility-layer between the following | ||
Zope Page Template engines: | ||
This package provides a page template engine implementation based on | ||
Chameleon. It plugs into the `zope.pagetemplate | ||
<http://pypi.python.org/pypi/zope.pagetemplate>`_ package and has an | ||
explicit dependency on this package. | ||
|
||
* z3c.pt | ||
* zope.pagetemplate | ||
You can use the package to replace Zope's reference template engine | ||
with Chameleon in an application based on the Zope Toolkit. | ||
|
||
If the environment-variable ``PREFER_Z3C_PT`` is set to a true value, | ||
the ``z3c.pt`` engine will be used instead of ``zope.pagetemplate``. | ||
Configuration | ||
------------- | ||
|
||
Note: This package superseeds and replaces the old z3c.pt.compat, | ||
please use z3c.ptcompat instead. | ||
The package is configured via ZCML. | ||
|
||
Usage | ||
----- | ||
|
||
When writing new code or modifying existing code, import page template | ||
classes from the ``z3c.ptcompat`` package: | ||
|
||
>>> from z3c.ptcompat import PageTemplateFile | ||
>>> from z3c.ptcompat import ViewPageTemplateFile | ||
|
||
Two methods are available to bind templates and template macros to a | ||
view: | ||
|
||
>>> from z3c.ptcompat import bind_template | ||
>>> from z3c.ptcompat import bind_macro | ||
|
||
Both function return render-methods that accept keyword arguments | ||
which will be passed to the template. | ||
|
||
>>> render = bind_template(template, view) | ||
>>> render = bind_macro(template, view, request, macro) | ||
|
||
Patches | ||
------- | ||
|
||
By loading the ``patches`` module, Zope view page template classes | ||
will be monkey-patched to use the ``z3c.pt`` rendering facilities: | ||
|
||
<include package="z3c.ptcompat.patches" /> | ||
|
||
This is an alternative to changing module import locations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope"> | ||
|
||
<include package="z3c.pt" /> | ||
<include package="zope.traversing" /> | ||
<utility component=".engine.Program" /> | ||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
############################################################################## | ||
# | ||
# Copyright (c) 2005 Zope Foundation and Contributors. | ||
# All Rights Reserved. | ||
# | ||
# This software is subject to the provisions of the Zope Public License, | ||
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | ||
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | ||
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | ||
# FOR A PARTICULAR PURPOSE. | ||
# | ||
############################################################################## | ||
|
||
__docformat__ = "reStructuredText" | ||
|
||
|
||
from zope.interface import implements | ||
from zope.interface import classProvides | ||
from zope.pagetemplate.interfaces import IPageTemplateEngine | ||
from zope.pagetemplate.interfaces import IPageTemplateProgram | ||
|
||
from z3c.pt.pagetemplate import PageTemplate as ChameleonPageTemplate | ||
from chameleon.tal import RepeatDict | ||
|
||
|
||
class Program(object): | ||
implements(IPageTemplateProgram) | ||
classProvides(IPageTemplateEngine) | ||
|
||
def __init__(self, template): | ||
self.template = template | ||
|
||
def __call__(self, context, macros, tal=True, **options): | ||
if tal is False: | ||
return self.template.body | ||
|
||
context.vars['repeat'] = RepeatDict(context.repeat_vars) | ||
|
||
return self.template.render(**context.vars) | ||
|
||
@classmethod | ||
def cook(cls, source_file, text, engine, content_type): | ||
template = ChameleonPageTemplate( | ||
text, filename=source_file, keep_body=True, | ||
) | ||
|
||
return cls(template), template.macros |
Oops, something went wrong.