[Zope3-checkins] CVS: Zope3/src/zope/app/apidoc/servicemodule -
browser.py:1.3
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Mar 28 18:41:02 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/apidoc/servicemodule
In directory cvs.zope.org:/tmp/cvs-serv22784/src/zope/app/apidoc/servicemodule
Modified Files:
browser.py
Log Message:
Added tests.
The service implementations return a path and a partial URL for class.
=== Zope3/src/zope/app/apidoc/servicemodule/browser.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/apidoc/servicemodule/browser.py:1.2 Wed Feb 25 17:26:46 2004
+++ Zope3/src/zope/app/apidoc/servicemodule/browser.py Sun Mar 28 18:41:00 2004
@@ -22,10 +22,33 @@
from zope.app.apidoc.ifacemodule.browser import InterfaceDetails
from zope.app.apidoc.utilities import getPythonPath
-__metaclass__ = type
+class Menu(object):
+ """Menu View Helper Class
-class Menu:
- """Menu View Helper Class"""
+ 'node' is a 'zope.app.tree.node.Node' instance.
+
+ Examples::
+
+ >>> from zope.component.interfaces import IUtilityService
+ >>> from zope.component.utility import GlobalUtilityService
+ >>> from zope.app.tree.node import Node
+ >>> from zope.app.apidoc.servicemodule import ServiceModule, Service
+ >>> from zope.app.apidoc.tests import Root
+
+ >>> servicemod = ServiceModule()
+ >>> servicemod.__name__ = 'Services'
+ >>> servicemod.__parent__ = Root()
+ >>> service = Service(servicemod, 'Utilities', IUtilityService,
+ ... [GlobalUtilityService])
+ >>> menu = Menu()
+
+ >>> node = Node(service)
+ >>> menu.getMenuTitle(node)
+ 'Utilities'
+
+ >>> menu.getMenuLink(node)
+ './Utilities/index.html'
+ """
def getMenuTitle(self, node):
"""Return the title of the node that is displayed in the menu."""
@@ -36,18 +59,56 @@
return './'+ zapi.name(node.context) + '/index.html'
-class ServiceDetails:
- """View for a Service in the API Documentation"""
+class ServiceDetails(object):
+ """View for a Service in the API Documentation
+
+ Example::
+
+ >>> import pprint
+ >>> pprint = pprint.PrettyPrinter(width=69).pprint
+ >>> from zope.component.interfaces import IUtilityService
+ >>> from zope.component.utility import GlobalUtilityService
+ >>> from zope.publisher.browser import TestRequest
+ >>> from zope.app.tree.node import Node
+ >>> from zope.app.apidoc.servicemodule import ServiceModule, Service
+ >>> from zope.app.apidoc.tests import Root
+
+ >>> servicemod = ServiceModule()
+ >>> servicemod.__name__ = 'Services'
+ >>> servicemod.__parent__ = Root()
+ >>> service = Service(servicemod, 'Utilities', IUtilityService,
+ ... [GlobalUtilityService()])
+ >>> details = ServiceDetails()
+ >>> details.context = service
+ >>> details.request = TestRequest()
+
+ >>> iface = details.interface()
+ >>> iface.getId()
+ 'zope.component.interfaces.IUtilityService'
+
+ >>> impl = details.implementations()
+ >>> impl = [i.items() for i in impl]
+ >>> impl = [i for i in impl if i.sort() is None]
+ >>> impl.sort()
+ >>> pprint(impl)
+ [[('path', 'zope.component.utility.GlobalUtilityService'),
+ ('url', 'zope/component/utility/GlobalUtilityService')]]
+ """
def interface(self):
"""Get the details view of the interface the service provides."""
iface = LocationProxy(self.context.interface,
self.context,
getPythonPath(self.context.interface))
- return InterfaceDetails(iface, self.request)
+ details = InterfaceDetails()
+ details.context = iface
+ details.request = self.request
+ return details
def implementations(self):
"""Retrieve a list of implementations of this service."""
impl = map(removeAllProxies, self.context.implementations)
impl = map(lambda x: x.__class__, self.context.implementations)
- return map(getPythonPath, impl)
+ return [{'path': getPythonPath(klass),
+ 'url': getPythonPath(klass).replace('.', '/')}
+ for klass in impl]
More information about the Zope3-Checkins
mailing list