[Checkins] SVN: z3c.jbot/trunk/ Added Chameleon-support.
Malthe Borch
mborch at gmail.com
Thu Oct 15 12:29:10 EDT 2009
Log message for revision 105088:
Added Chameleon-support.
Changed:
U z3c.jbot/trunk/CHANGES.txt
U z3c.jbot/trunk/README.txt
U z3c.jbot/trunk/z3c/jbot/__init__.py
U z3c.jbot/trunk/z3c/jbot/manager.py
-=-
Modified: z3c.jbot/trunk/CHANGES.txt
===================================================================
--- z3c.jbot/trunk/CHANGES.txt 2009-10-15 15:59:55 UTC (rev 105087)
+++ z3c.jbot/trunk/CHANGES.txt 2009-10-15 16:29:10 UTC (rev 105088)
@@ -3,6 +3,8 @@
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
Modified: z3c.jbot/trunk/README.txt
===================================================================
--- z3c.jbot/trunk/README.txt 2009-10-15 15:59:55 UTC (rev 105087)
+++ z3c.jbot/trunk/README.txt 2009-10-15 16:29:10 UTC (rev 105088)
@@ -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
@@ -32,6 +33,9 @@
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
------
Modified: z3c.jbot/trunk/z3c/jbot/__init__.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/__init__.py 2009-10-15 15:59:55 UTC (rev 105087)
+++ z3c.jbot/trunk/z3c/jbot/__init__.py 2009-10-15 16:29:10 UTC (rev 105088)
@@ -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()
+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
+ 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
+ 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))
Modified: z3c.jbot/trunk/z3c/jbot/manager.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/manager.py 2009-10-15 15:59:55 UTC (rev 105087)
+++ z3c.jbot/trunk/z3c/jbot/manager.py 2009-10-15 16:29:10 UTC (rev 105088)
@@ -142,6 +142,7 @@
self.templates[token] = filename
else:
self.templates[token] = IGNORE
+ return False
# force cook
template._v_last_read = False
More information about the checkins
mailing list