[Checkins] SVN: grok/trunk/src/grok/ implemented ZCML-Directive <grok:grok package='package-or-module'/>

Wolfgang Schnerring wosc at wosc.de
Tue Oct 17 07:11:17 EDT 2006


Log message for revision 70739:
  implemented ZCML-Directive <grok:grok package='package-or-module'/>

Changed:
  A   grok/trunk/src/grok/meta.zcml
  A   grok/trunk/src/grok/metaconfigure.py
  A   grok/trunk/src/grok/metadirectives.py
  A   grok/trunk/src/grok/tests/scan/directivemodule.py
  A   grok/trunk/src/grok/tests/scan/directivepackage.py

-=-
Added: grok/trunk/src/grok/meta.zcml
===================================================================
--- grok/trunk/src/grok/meta.zcml	2006-10-17 10:45:36 UTC (rev 70738)
+++ grok/trunk/src/grok/meta.zcml	2006-10-17 11:11:16 UTC (rev 70739)
@@ -0,0 +1,13 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:meta="http://namespaces.zope.org/meta">
+
+  <meta:directives namespace="http://namespaces.zope.org/grok">
+    <meta:directive
+        name="grok"
+        schema=".metadirectives.IGrokDirective"
+        handler=".metaconfigure.grokDirective"
+        />
+  </meta:directives>
+</configure>
+  
\ No newline at end of file

Added: grok/trunk/src/grok/metaconfigure.py
===================================================================
--- grok/trunk/src/grok/metaconfigure.py	2006-10-17 10:45:36 UTC (rev 70738)
+++ grok/trunk/src/grok/metaconfigure.py	2006-10-17 11:11:16 UTC (rev 70739)
@@ -0,0 +1,19 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation 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.
+#
+##############################################################################
+"""Grok ZCML-Directives
+"""
+import grok
+
+def grokDirective(_context, package):
+    grok.grok(package.__name__)

Added: grok/trunk/src/grok/metadirectives.py
===================================================================
--- grok/trunk/src/grok/metadirectives.py	2006-10-17 10:45:36 UTC (rev 70738)
+++ grok/trunk/src/grok/metadirectives.py	2006-10-17 11:11:16 UTC (rev 70739)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation 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.
+#
+##############################################################################
+"""Grok ZCML-Directives
+"""
+from zope import interface
+import zope.configuration.fields
+
+class IGrokDirective(interface.Interface):
+    """
+    
+    """
+
+    package = zope.configuration.fields.GlobalObject(
+        title=u"Package",
+        description=u"The package or module to be analyzed by grok.",
+        required=False,
+        )
+    

Added: grok/trunk/src/grok/tests/scan/directivemodule.py
===================================================================
--- grok/trunk/src/grok/tests/scan/directivemodule.py	2006-10-17 10:45:36 UTC (rev 70738)
+++ grok/trunk/src/grok/tests/scan/directivemodule.py	2006-10-17 11:11:16 UTC (rev 70739)
@@ -0,0 +1,28 @@
+"""
+  >>> import grok
+  >>> from zope.configuration import xmlconfig
+  >>> context = xmlconfig.file('meta.zcml', grok)
+
+  >>> ignored = xmlconfig.string('''
+  ... <configure
+  ...     xmlns="http://namespaces.zope.org/zope"
+  ...     xmlns:grok="http://namespaces.zope.org/grok"
+  ...     >
+  ...     <grok:grok package="grok.tests.scan.stoneage.cave"/>
+  ... </configure>''', context=context)
+
+  >>> from grok.tests.scan.stoneage.cave import Cave
+  >>> cave = Cave()
+  
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> from zope import component
+
+  >>> view = component.getMultiAdapter((cave, request), name='index')
+  >>> print view()
+  <html>
+  <body>
+  <h1>A comfy cave</h1>
+  </body>
+  </html>
+"""

Added: grok/trunk/src/grok/tests/scan/directivepackage.py
===================================================================
--- grok/trunk/src/grok/tests/scan/directivepackage.py	2006-10-17 10:45:36 UTC (rev 70738)
+++ grok/trunk/src/grok/tests/scan/directivepackage.py	2006-10-17 11:11:16 UTC (rev 70739)
@@ -0,0 +1,38 @@
+"""
+  >>> import grok
+  >>> from zope.configuration import xmlconfig
+  >>> context = xmlconfig.file('meta.zcml', grok)
+
+  >>> ignored = xmlconfig.string('''
+  ... <configure
+  ...     xmlns="http://namespaces.zope.org/zope"
+  ...     xmlns:grok="http://namespaces.zope.org/grok"
+  ...     >
+  ...     <grok:grok package="grok.tests.scan.stoneage"/>
+  ... </configure>''', context=context)
+
+  >>> from grok.tests.scan.stoneage.cave import Cave
+  >>> from grok.tests.scan.stoneage.hunt.mammoth import Mammoth
+  >>> manfred = Mammoth()
+  >>> cave = Cave()
+  
+  >>> from zope.publisher.browser import TestRequest
+  >>> request = TestRequest()
+  >>> from zope import component
+
+  >>> view = component.getMultiAdapter((cave, request), name='index')
+  >>> print view()
+  <html>
+  <body>
+  <h1>A comfy cave</h1>
+  </body>
+  </html>
+  
+  >>> view = component.getMultiAdapter((manfred, request), name='index')
+  >>> print view()
+  <html>
+  <body>
+  <h1>ME GROK HUNT MAMMOTH!</h1>
+  </body>
+  </html>
+"""
\ No newline at end of file



More information about the Checkins mailing list