Skip to content

Commit

Permalink
Added Chameleon-support.
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Oct 15, 2009
1 parent fb596d4 commit 3d1ed1a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changes

In next release...

- Added Chameleon-support.

- Reimplemented override logic; the total usage cost is now reduced to
an insignificant amount. Meanwhile, only templates that are defined
as class-attributes (e.g. on views, viewlets and portlets) can be
Expand Down
8 changes: 6 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Overview
========

The z3c.jbot (or "Just a bunch of templates") package allows drop-in
page template overrides. It works on Zope 2 and Zope 3.
The ``z3c.jbot`` (or "Just a bunch of templates") package allows
drop-in page template overrides. It works on Zope 2 and Zope 3. The
Chameleon rendering engine is supported [#]_.

Any template that is defined as a class-attribute can be overriden
using jbot, e.g. those used in views, viewlets and portlets. The
Expand Down Expand Up @@ -32,6 +33,9 @@ use with jbot using a ZCML-directive::
Use of this package adds a small (2-3 ms per request on Plone) to the
total application response time.

.. [#] To enable Chameleon on Zope 2, use the ``five.pt`` package
(CMF-apps like Plone should use ``cmf.pt`` which adds full support).

Author
------

Expand Down
55 changes: 36 additions & 19 deletions z3c/jbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,43 @@
except:
pass

logger.info("Patching page template classes for use with z3c.jbot...")

registry = {}

for pt_class in PT_CLASSES:
def get(template, view=None, cls=None):
layer = utility.getLayer()
key = layer, template
inst = registry.get(key)
if inst is None:
cls = type(template)
inst = registry[key] = cls.__new__(cls)
inst.__dict__ = template.__dict__.copy()

for manager in utility.getManagers():
# register template; this call returns ``True`` if
# template was invalidated
if manager.registerTemplate(inst, template):
break

return inst
def get(template, view=None, cls=None):
layer = utility.getLayer()
key = layer, template
inst = registry.get(key)
if inst is None:
cls = type(template)
inst = registry[key] = cls.__new__(cls)
inst.__dict__ = template.__dict__.copy()

for manager in utility.getManagers():
# register template; this call returns ``True`` if the
# template was invalidated (changed filename)
if manager.registerTemplate(inst, template):
break

return inst

try:
import five.pt.pagetemplate
except ImportError:
pass
else:
pt_class = five.pt.pagetemplate.ViewPageTemplateFile
bind = pt_class.__get__

def get_and_bind(template, view=None, cls=None):
inst = get(template, view, cls)
if inst._v_last_read is False:
inst.registry.purge()
inst.read()
return bind(inst, view, cls)

pt_class.__get__ = get_and_bind
logger.info(repr(pt_class))

for pt_class in PT_CLASSES:
pt_class.__get__ = get
logger.info(repr(pt_class))
1 change: 1 addition & 0 deletions z3c/jbot/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def registerTemplate(self, template, token):
self.templates[token] = filename
else:
self.templates[token] = IGNORE
return False

# force cook
template._v_last_read = False
Expand Down

0 comments on commit 3d1ed1a

Please sign in to comment.