[Zope3-checkins] CVS: Zope3/src/zope/products/apidoc/viewmodule -
__init__.py:1.1 browser.py:1.1 configure.zcml:1.1
index.pt:1.1 menu.pt:1.1 skin_layer_usage.pt:1.1
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Jan 29 12:51:21 EST 2004
Update of /cvs-repository/Zope3/src/zope/products/apidoc/viewmodule
In directory cvs.zope.org:/tmp/cvs-serv11915/apidoc/viewmodule
Added Files:
__init__.py browser.py configure.zcml index.pt menu.pt
skin_layer_usage.pt
Log Message:
Here comes the new Zope 3 API Documentation tool. You can access it via
http://localhost:8080/++apidoc++/
There is really not much more to say here. Check it out and let me know what
you think.
=== Added File Zope3/src/zope/products/apidoc/viewmodule/__init__.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""View Documentation Module
$Id: __init__.py,v 1.1 2004/01/29 17:51:19 srichter Exp $
"""
from zope.app import zapi
from zope.interface import implements
from zope.products.apidoc.interfaces import IDocumentationModule
class ViewModule(object):
"""Represent the Documentation of all Views."""
implements(IDocumentationModule)
# See zope.products.apidoc.interfaces.IDocumentationModule
title = 'Presentations'
# See zope.products.apidoc.interfaces.IDocumentationModule
description = """
The Presentations (or Views) module is somewhat crazy, since a view or
resource cannot be identified by a single interface or name, but of four
to five pieces of information. Conclusively, the menu let's you select an
interface and a presentation type for which views should be found.
By default, the resulting views exclude views that have no required
interface ('None') or are registered to require
'zope.interface.Interface'. To see these additional views, click on
"Show all views".
Once you click on "Show" you will be presented with a list of all
applicable views. The views are sorted by layer. The views are mainly
identified by name, since this is what you use in a URL for
example. Information provided for each view include the required
interface, the presentation type and the permission. If possible, the
system also tries to extract some information from the factory, like the
view class, the template or resource.
Completely independent of all this, there is a link "Show Skins, Layers
and Usages" that brings you to a simple screen that shows the mapping of
the layers to skins and provides a list of available usages.
"""
def getSkins(self):
"""Get the names of all available skins."""
service = zapi.getService(self, 'Presentation')
return service.skins.keys()
def getLayersForSkin(self, skin):
"""Get the names of all available layers of a particular skin.
Returns a 'KeyError', if the skin does not exist.
"""
service = zapi.getService(self, 'Presentation')
return service.skins[skin]
def getSkinLayerMapping(self):
"""Return a dictionary with keys being skin names and the value are
tuples of layer names."""
service = zapi.getService(self, 'Presentation')
return service.skins
def getUsages(self):
"""Return a list of all available usages."""
service = zapi.getService(self, 'Presentation')
return service._usages.keys()
=== Added File Zope3/src/zope/products/apidoc/viewmodule/browser.py ===
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
#
##############################################################################
"""Views/Presentation Module Views
$Id: browser.py,v 1.1 2004/01/29 17:51:19 srichter Exp $
"""
from types import ClassType
from zope.app import zapi
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.app.publisher.browser.icon import IconViewFactory
from zope.interface import Interface
from zope.products.apidoc.utilities import getPythonPath, getPermissionIds
from zope.proxy import removeAllProxies
class Menu(object):
"""Views module Menu"""
def getPresentationTypes(self):
"""Get a list of presentation types."""
return [{'name': path.split('.')[-1], 'path': path}
for path in ['zope.publisher.interfaces.http.IHTTPRequest',
'zope.publisher.interfaces.browser.IBrowserRequest',
'zope.publisher.interfaces.xmlrpc.IXMLRPCRequest',
'zope.publisher.interfaces.ftp.IFTPRequest']
]
def getInterfaceIds(self):
"""Get a list of the ids of all interfaces registered with the
interface service."""
service = zapi.getService(self, 'Interfaces')
ids = service.searchInterfaceIds()
ids.sort()
return ids
class SkinLayerUsage(object):
"""View for skins, layers and usages."""
def getSkins(self):
return [{'name': skin, 'layers': layers}
for skin, layers in self.context.getSkinLayerMapping().items()]
def _getFactoryData(factory):
"""Squeeze some useful information out of the view factory"""
info = {'path': None, 'template': None, 'resource': None,
'referencable': False}
if hasattr(factory, '__name__') and \
factory.__name__.startswith('SimpleViewClass'):
info['path'] = factory.__module__ + '.SimpleViewClass'
info['template'] = factory.index.filename
elif isinstance(factory, (str, unicode, float, int, list, tuple)):
pass
elif factory.__module__.startswith('zope.app.publisher.browser.viewmeta'):
info['path'] = getPythonPath(factory.__bases__[0])
info['referencable'] = True
elif not hasattr(factory, '__name__'):
info['path'] = getPythonPath(factory.__class__)
info['referencable'] = True
elif type(factory) in (type, ClassType):
info['path'] = getPythonPath(factory)
info['referencable'] = True
else:
info['path'] = getPythonPath(factory)
info['referencable'] = True
if isinstance(factory, IconViewFactory):
info['resource'] = factory.rname
return info
class ViewsDetails(object):
"""View for Views"""
def __init__(self, context, request):
self.context = context
self.request = request
service = zapi.getService(context, 'Interfaces')
self.iface = service.getInterface(request['iface'])
self.type = service.getInterface(request['type'])
service = zapi.getService(context, 'Presentation')
self.views = service.getRegisteredMatching(object=self.iface,
request=self.type)
self.show_all = request.has_key('all')
def getViewsByLayers(self):
"""Generate the data structure that is used to create the list of
views."""
result = []
for layer, views in self.views.items():
entries = []
for required, provided, more_req, name, factories in views:
if self.show_all or \
not (required is None or required is Interface):
entry = {'name' : name,
'required' : getPythonPath(required),
'type' : getPythonPath(more_req[0]),
'factory' : _getFactoryData(factories[-1])
}
# Educated choice of the attribute name
entry.update(getPermissionIds('publishTraverse',
klass=factories[-1]))
entries.append(entry)
if entries:
entries.sort(lambda x, y: cmp(x['name'], y['name']))
result.append({'name': layer, 'views': entries})
return result
=== Added File Zope3/src/zope/products/apidoc/viewmodule/configure.zcml ===
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
<class class=".ViewModule">
<allow interface="zope.products.apidoc.interfaces.IDocumentationModule" />
<allow attributes="getSkins getLayersForSkin getSkinLayerMapping
getUsages"/>
</class>
<utility
provides="zope.products.apidoc.interfaces.IDocumentationModule"
factory=".ViewModule"
name="Views" />
<browser:page
for=".ViewModule"
permission="zope.View"
class=".browser.Menu"
name="menu.html"
template="menu.pt" />
<browser:page
for=".ViewModule"
permission="zope.View"
class=".browser.SkinLayerUsage"
name="skin_layer_usage.html"
template="skin_layer_usage.pt" />
<browser:page
for=".ViewModule"
permission="zope.View"
class=".browser.ViewsDetails"
name="index.html"
template="index.pt" />
</configure>
=== Added File Zope3/src/zope/products/apidoc/viewmodule/index.pt ===
<html metal:use-macro="views/apidoc_macros/details">
<body metal:fill-slot="contents"
tal:define="layers view/getViewsByLayers">
<h1 class="details-header">
<span tal:replace="view/type/__name__" /> views for
<span tal:replace="view/iface/__name__" />
</h1>
<span tal:repeat="layer layers">
<h2 class="details-section">
"<span tal:replace="layer/name" />" Layer
</h2>
<div class="indent">
<ul>
<li tal:repeat="View layer/views">
<b tal:content="View/name" /><br />
<div class="indent"><span class="small">
<i>required:</i>
<a href=""
tal:condition="View/required"
tal:attributes="href View/required"
tal:content="View/required" />
<span tal:condition="not:View/required">None</span>
<br />
<i>presentation type:</i>
<a href=""
tal:attributes="href View/type"
tal:content="View/type" />
<br />
<tal:omit-tag condition="View/factory/path">
<i>factory path:</i>
<a href=""
tal:condition="View/factory/referencable"
tal:attributes="href
string: ../Class/index.html?path=${View/factory/path}"
tal:content="View/factory/path" />
<span
tal:condition="not:View/factory/referencable"
tal:content="View/factory/path" />
<br />
</tal:omit-tag>
<tal:omit-tag condition="View/factory/template">
<i>template:</i>
<span tal:replace="View/factory/template" />
<br />
</tal:omit-tag>
<tal:omit-tag condition="View/factory/resource">
<i>resource:</i>
<a href=""
tal:attributes="href
string: /@@/${View/factory/resource}"
tal:content="View/factory/resource" />
<br />
</tal:omit-tag>
<span class="small"
tal:condition="python: View['read_perm'] and View['write_perm']">
<i>Permissions:</i>
<span tal:replace="View/read_perm">zope.View</span> (read),
<span tal:replace="View/write_perm">zope.View</span> (write)
</span>
</span></div>
</li>
</ul>
</div>
</span>
<p tal:condition="not: layers">
<em>There are no views for this interface and presentation type.</em>
</p>
</body>
</html>
=== Added File Zope3/src/zope/products/apidoc/viewmodule/menu.pt ===
<html metal:use-macro="views/apidoc_macros/menu">
<body>
<div metal:fill-slot="menu" class="small">
<form action="./index.html" target="main">
<p>
Enter the interface name:
<select name="iface"
style="font-size: 80%; width=95%" >
<option
tal:repeat="id view/getInterfaceIds"
tal:attributes="value id"
tal:content="id" />
</select>
</p>
<p>
Presentation Type:
<select name="type"
style="font-size: 80%; width=95%" >
<option
tal:repeat="type view/getPresentationTypes"
tal:attributes="value type/path"
tal:content="type/name" />
</select>
</p>
<p>
Show all views:
<input type="checkbox" name="all" value="all"/>
</p>
<input type="submit" name="SUBMIT" value="Show"
style="font-size: 80%; width=95%"/>
</form>
<a href="./skin_layer_usage.html" target="main">
Show Skins, Layers and Usages
</a>
</div>
</body>
</html>
=== Added File Zope3/src/zope/products/apidoc/viewmodule/skin_layer_usage.pt ===
<html metal:use-macro="views/apidoc_macros/details">
<body metal:fill-slot="contents">
<h1 class="details-header">
Skins, Layers & Usages
</h1>
<h2 class="details-section">Skin-Layer Tree</h2>
<div class="indent" tal:repeat="skin view/getSkins">
<h3 tal:content="skin/name">rotterdam</h3>
<div class="indent">
<ul>
<li tal:repeat="layer skin/layers"
tal:content="layer">
default
</li>
</ul>
</div>
</div>
<h2 class="details-section">Usages</h2>
<div class="indent">
<ul>
<li tal:repeat="usage context/getUsages"
tal:content="usage">
default
</li>
</ul>
</div>
</body>
</html>
More information about the Zope3-Checkins
mailing list