Author: jmorliaguet
Date: Sun Oct 30 01:44:45 2005
New Revision: 28807

Modified:
   z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metadirectives.py
Log:

- added support for filters that call a page template



Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py        
Sun Oct 30 01:44:45 2005
@@ -17,6 +17,7 @@
 """
 __docformat__ = "reStructuredText"
 
+from zope.app.pagetemplate import ViewPageTemplateFile
 from zope.app.publisher.browser import BrowserView
 from zope.app.traversing.api import getParent
 from zope.app.zapi import getMultiAdapter, queryMultiAdapter
@@ -26,11 +27,12 @@
 from zope.publisher.interfaces import IRequest
 
 from cpsskins import getThemeManager, getContexts
+from cpsskins.filters import PageTemplateFilter
 from cpsskins.browser.negociation.interfaces import INegociation
 from cpsskins.browser.rendering.interfaces import IUpdateData
 from cpsskins.configuration.interfaces import IRegistry
-from cpsskins.elements.interfaces import IElement, ILeaf, ISlot, IDisplayable
 from cpsskins.elements.interfaces import IType
+from cpsskins.elements.interfaces import IElement, ILeaf, ISlot, IDisplayable
 from cpsskins.relations.interfaces import IPredicate
 from cpsskins.storage.interfaces import IRelationStorage
 from interfaces import IViewer, IRenderer, IFilter, IContextInfo
@@ -207,6 +209,11 @@
 
     return index
 
+class PageTemplateFilter(object):
+
+    def __init__(self):
+        pass
+
 class Renderer(object):
     """A renderer is a collection of filters. It provides some rendering
     for elements.
@@ -312,14 +319,27 @@
                         % (filter_name, repr(adapted)))
                     continue
 
-            # the filter id refers to an adapter
-            elif IFilter.implementedBy(filter_id):
+            # the filter id refers to a display adapter
+            elif IFilter.providedBy(filter_id):
                 filter = filter_id(display)
 
-            else:
-                raise ConfigurationError(
-                    "The '%s' filter id is not supported." % repr(filter_id))
+            elif isinstance(filter_id, ViewPageTemplateFile):
+                filter = ZPTViewFilter(element, request)
+                filter.setTemplate(filter_id)
 
             filters.append(filter)
+
         return filters
 
+class ZPTViewFilter(BrowserView):
+
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+    def setTemplate(self, template):
+        self.template = template
+
+    def __call__(self, markup, info):
+        kw = {'markup': markup, 'info': info}
+        return self.template(self, **kw)

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py 
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py 
    Sun Oct 30 01:44:45 2005
@@ -19,6 +19,7 @@
 
 import os
 
+from zope.app import pagetemplate
 from zope.app.publisher.browser.resourcemeta import resource
 from zope.component import provideAdapter, getUtility
 from zope.configuration.exceptions import ConfigurationError
@@ -32,12 +33,13 @@
            for_=None,
            factory=None,
            predicate=None,
+           template='',
            stylesheet=None):
 
     if not name:
         raise ConfigurationError("Must specify the filter name.")
 
-    if not (for_ or factory or predicate or stylesheet):
+    if not (for_ or factory or predicate or template):
         raise ConfigurationError("Filter information is missing.")
 
     if name in filter_registry:
@@ -48,8 +50,15 @@
         raise ConfigurationError, \
             "Must specify the interface of the adapted element."
 
-    if not factory:
-        raise ConfigurationError("Must specify a filter factory.")
+    if not (factory or template):
+        raise ConfigurationError("Must specify a filter factory or a 
template.")
+
+    if factory and template:
+        raise ConfigurationError(
+            "Cannot specify both a filter factory and a template.")
+
+    if template:
+        factory = pagetemplate.ViewPageTemplateFile(template)
 
     # zope:adapter
     from cpsskins.browser.rendering.interfaces import IFilter
@@ -73,4 +82,3 @@
     elif factory:
         filter_registry.register(name, factory)
 
-

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metadirectives.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metadirectives.py
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metadirectives.py
    Sun Oct 30 01:44:45 2005
@@ -51,6 +51,12 @@
         required=False,
         )
 
+    template = Path(
+        title=_("Template"),
+        description=_("A template to apply."),
+        required=False,
+        )
+
     stylesheet = Path(
         title=_("CSS resource"),
         description=_("A css resource used by the filter."),
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to