==================================== Code Browser Presentation Components ==================================== This document describes the API of the views complementing the varius code browser documentation components. The views can be found in >>> from zope.app.apidoc.codemodule import browser We will also need the code browser documentation module: >>> from zope.component import getUtility >>> from zope.app.apidoc.interfaces import IDocumentationModule >>> cm = getUtility(IDocumentationModule, 'Code') The `zope` package is already registered and available with the code module. Module Details -------------- The module details are easily created, since we can just use the traversal process to get a module documentation object: >>> from zope.traversing.api import traverse >>> details = browser.module.ModuleDetails(None, None) >>> details.context = traverse(cm, ... 'zope/app/apidoc/codemodule/codemodule') >>> from zope.publisher.browser import TestRequest >>> details.request = TestRequest() `getDoc()` ~~~~~~~~~~ Get the doc string of the module formatted in STX or ReST. >>> print details.getDoc().strip()
Code Documentation Module
This module is able to take a dotted name of any class and display documentation for it.
`getEntries(columns=True)` ~~~~~~~~~~~~~~~~~~~~~~~~~~ Return info objects for all modules and classes in this module. >>> pprint(details.getEntries(False)) [{'isclass': True, 'isfunction': False, 'isinterface': False, 'ismodule': False, 'istextfile': False, 'iszcmlfile': False, 'name': 'CodeModule', 'path': 'zope.app.apidoc.codemodule.class_.CodeModule', 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/codemodule/CodeModule'}] `getBreadCrumbs()` ~~~~~~~~~~~~~~~~~~ Create breadcrumbs for the module path. We cannot reuse the the system's bread crumbs, since they go all the way up to the root, but we just want to go to the root module. >>> pprint(details.getBreadCrumbs()) [{'name': u'[top]', 'url': 'http://127.0.0.1'}, {'name': u'zope', 'url': 'http://127.0.0.1/zope'}, {'name': 'app', 'url': 'http://127.0.0.1/zope/app'}, {'name': 'apidoc', 'url': 'http://127.0.0.1/zope/app/apidoc'}, {'name': 'codemodule', 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule'}, {'name': 'codemodule', 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/codemodule'}] Class Details ------------- The class details are easily created, since we can just use the traversal process to get a class documentation object: >>> details = browser.class_.ClassDetails() >>> details.context = traverse( ... cm, 'zope/app/apidoc/codemodule/codemodule/CodeModule') >>> details.request = TestRequest() Now that we have the details class we can just access the various methods: `getBases()` ~~~~~~~~~~~~ Get all bases of this class. >>> pprint(details.getBases()) [{'path': 'zope.app.apidoc.codemodule.module.Module', 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/module/Module'}] `getKnownSubclasses()` ~~~~~~~~~~~~~~~~~~~~~~ Get all known subclasses of this class. >>> details.getKnownSubclasses() [] `_listClasses(classes)` ~~~~~~~~~~~~~~~~~~~~~~~ Prepare a list of classes for presentation. >>> import zope.app.apidoc.apidoc >>> import zope.app.apidoc.codemodule.codemodule >>> pprint(details._listClasses([ ... zope.app.apidoc.apidoc.APIDocumentation, ... zope.app.apidoc.codemodule.codemodule.Module])) [{'path': 'zope.app.apidoc.apidoc.APIDocumentation', 'url': 'http://127.0.0.1/zope/app/apidoc/apidoc/APIDocumentation'}, {'path': 'zope.app.apidoc.codemodule.module.Module', 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/module/Module'}] `getBaseURL()` ~~~~~~~~~~~~~~ Return the URL for the API Documentation Tool. Note that the following output is a bit different than usual, since we have not setup all path elements. >>> details.getBaseURL() 'http://127.0.0.1' `getInterfaces()` ~~~~~~~~~~~~~~~~~ Get all implemented interfaces (as paths) of this class. >>> pprint(details.getInterfaces()) [{'path': 'zope.app.apidoc.interfaces.IDocumentationModule', 'url': 'zope.app.apidoc.interfaces.IDocumentationModule'}, {'path': 'zope.location.interfaces.ILocation', 'url': 'zope.location.interfaces.ILocation'}, {'path': 'zope.app.apidoc.codemodule.interfaces.IModuleDocumentation', 'url': 'zope.app.apidoc.codemodule.interfaces.IModuleDocumentation'}, {'path': 'zope.app.container.interfaces.IReadContainer', 'url': 'zope.app.container.interfaces.IReadContainer'}] `getAttributes()` ~~~~~~~~~~~~~~~~~ Get all attributes of this class. >>> pprint(details.getAttributes()[1]) {'interface': {'path': 'zope.app.apidoc.interfaces.IDocumentationModule', 'url': 'zope.app.apidoc.interfaces.IDocumentationModule'}, 'name': 'title', 'read_perm': None, 'type': 'Message', 'type_link': 'zope/i18nmessageid/message/Message', 'value': "u'Code Browser'", 'write_perm': None} `getMethods()` ~~~~~~~~~~~~~~ Get all methods of this class. >>> pprint(details.getMethods()[-2:]) [{'doc': u'Setup module and class tree.
\n', 'interface': None, 'name': 'setup', 'read_perm': None, 'signature': '()', 'write_perm': None}, {'doc': u'', 'interface': {'path': 'zope.interface.common.mapping.IEnumerableMapping', 'url': 'zope.interface.common.mapping.IEnumerableMapping'}, 'name': 'values', 'read_perm': None, 'signature': '()', 'write_perm': None}] `getDoc()` ~~~~~~~~~~ Get the doc string of the class STX formatted. >>> print details.getDoc()[:-1]Represent the code browser documentation root
Function Details ---------------- This is the same deal as before, use the path to generate the function documentation component: >>> details = browser.function.FunctionDetails() >>> details.context = traverse(cm, ... 'zope/app/apidoc/codemodule/browser/tests/foo') >>> details.request = TestRequest() Here are the methods: `getDocString()` ~~~~~~~~~~~~~~~~ Get the doc string of the function in a rendered format. >>> details.getDocString() u'This is the foo function.
\n' `getAttributes()` ~~~~~~~~~~~~~~~~~ Get all attributes of this function. >>> attr = details.getAttributes()[0] >>> pprint(attr) {'name': 'deprecated', 'type': 'bool', 'type_link': '__builtin__/bool', 'value': 'True'} `getBaseURL()` ~~~~~~~~~~~~~~ Return the URL for the API Documentation Tool. Note that the following output is a bit different than usual, since we have not setup all path elements. >>> details.getBaseURL() 'http://127.0.0.1' Text File Details ----------------- This is the same deal as before, use the path to generate the text file documentation component: >>> details = browser.text.TextFileDetails() >>> details.context = traverse(cm, ... 'zope/app/apidoc/codemodule/README.txt') >>> details.request = TestRequest() Here are the methods: `renderedContent()` ~~~~~~~~~~~~~~~~~~~ Render the file content to HTML. >>> print details.renderedContent()[:48]Return a sequence-like...', 'interface': 'zope.interface.common.mapping.IEnumerableMapping', 'name': 'keys', 'read_perm': None, 'signature': '()', 'write_perm': None}, {'doc': u'', 'interface': 'zope.app.component.interfaces.IPossibleSite', 'name': 'setSiteManager', 'read_perm': None, 'signature': '(sm)', 'write_perm': None}, ...] The final methods deal with inspecting the objects data further. For exmaple, if we inspect a sequence, >>> from persistent.list import PersistentList >>> list = PersistentList(['one', 'two']) >>> from zope.interface.common.sequence import IExtendedReadSequence >>> zope.interface.directlyProvides(list, IExtendedReadSequence) >>> inspect2 = introspector.Introspector(list, request) we can first determine whether it really is a sequence >>> inspect2.isSequence() True and then get the sequence items: >>> pprint(inspect2.getSequenceItems()) [{'index': 0, 'value': "'one'", 'value_type': 'str', 'value_type_link': '__builtin__/str'}, {'index': 1, 'value': "'two'", 'value_type': 'str', 'value_type_link': '__builtin__/str'}] Similar functionality exists for a mapping. But we first have to add an item: >>> rootFolder['list'] = list Now let's have a look: >>> inspect.isMapping() True >>> pprint(inspect.getMappingItems()) [{'key': u'list', 'key_string': "u'list'", 'value': "['one', 'two']", 'value_type': 'ContainedProxy', 'value_type_link': 'zope/app/container/contained/ContainedProxy'}] The final two methods doeal with the introspection of the annotations. If an object is annotatable, >>> inspect.isAnnotatable() True then we can get an annotation mapping: >>> rootFolder.__annotations__ = {'my.list': list} >>> pprint(inspect.getAnnotationsInfo()) [{'key': 'my.list', 'key_string': "'my.list'", 'value': "['one', 'two']", 'value_type': 'PersistentList', 'value_type_link': 'persistent/list/PersistentList'}] And that's it. Fur some browser-based demonstration see ``introspector.txt``.