[Checkins] SVN: grok/branches/jw-simpler-skin-registration/src/grok/ start on implementing an instance grokker for skins.

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Jul 28 17:25:21 EDT 2008


Log message for revision 88913:
  start on implementing an instance grokker for skins.

Changed:
  U   grok/branches/jw-simpler-skin-registration/src/grok/ftests/view/layers.py
  U   grok/branches/jw-simpler-skin-registration/src/grok/meta.py

-=-
Modified: grok/branches/jw-simpler-skin-registration/src/grok/ftests/view/layers.py
===================================================================
--- grok/branches/jw-simpler-skin-registration/src/grok/ftests/view/layers.py	2008-07-28 21:23:35 UTC (rev 88912)
+++ grok/branches/jw-simpler-skin-registration/src/grok/ftests/view/layers.py	2008-07-28 21:25:21 UTC (rev 88913)
@@ -1,6 +1,6 @@
 """
   >>> getRootFolder()["manfred"] = Mammoth()
- 
+
   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
   >>> browser.handleErrors = False
@@ -11,7 +11,7 @@
   <h1>Hello, world!</h1>
   </body>
   </html>
-  
+
   >>> browser.open("http://localhost/++skin++Rotterdam/manfred/@@moredrawings")
   >>> print browser.contents
   Pretty
@@ -61,3 +61,6 @@
 
     def render(self):
         return "Awesome"
+
+class IFoo(IBrowserRequest):
+    grok.skin('foo')

Modified: grok/branches/jw-simpler-skin-registration/src/grok/meta.py
===================================================================
--- grok/branches/jw-simpler-skin-registration/src/grok/meta.py	2008-07-28 21:23:35 UTC (rev 88912)
+++ grok/branches/jw-simpler-skin-registration/src/grok/meta.py	2008-07-28 21:25:21 UTC (rev 88913)
@@ -17,6 +17,7 @@
 
 import zope.component.interface
 from zope import interface, component
+from zope.interface.interface import InterfaceClass
 from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
                                                IBrowserRequest,
                                                IBrowserPublisher,
@@ -274,7 +275,7 @@
     # this needs to happen before any other grokkers execute that actually
     # use the templates
     martian.priority(1000)
-    
+
     def grok(self, name, instance, module_info, config, **kw):
         templates = module_info.getAnnotation('grok.templates', None)
         if templates is None:
@@ -756,3 +757,26 @@
             return not has_render(factory)
         templates.checkTemplates(module_info, factory, 'viewlet',
                                  has_render, has_no_render)
+
+_skin_not_used = object()
+
+class SkinAsDirectiveGrokker(martian.InstanceGrokker):
+    martian.component(InterfaceClass)
+
+    def grok(self, name, factory, module_info, config, **kw):
+        skin = grok.skin.bind(default=_skin_not_used).get(factory)
+        if skin is _skin_not_used:
+            # The skin directive is not actually used on the found interface.
+            return False
+
+        if not issubclass(factory, IBrowserRequest):
+            # For layers it is required to subclass IBrowserRequest.
+            raise GrokError(
+                "The grok.skin() directive is used on interface %s. "
+                "However, %s does not subclass IBrowserRequest which is "
+                "required for interfaces that are used as layers and are to "
+                "be registered as a skin" % (factory, factory), factory)
+
+        # Now do the real stuff..
+
+        return True



More information about the Checkins mailing list