[Zope3-checkins] CVS: zopeproducts/zwiki - metaconfigure.py:1.1 meta.zcml:1.1
Stephan Richter
srichter@cbu.edu
Tue, 8 Apr 2003 00:14:23 -0400
Update of /cvs-repository/zopeproducts/zwiki
In directory cvs.zope.org:/tmp/cvs-serv5908
Added Files:
metaconfigure.py meta.zcml
Log Message:
Implemented a directive called 'sourcetype' that makes it trivial to
register new source types via ZCML.
=== Added File zopeproducts/zwiki/metaconfigure.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 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.
#
##############################################################################
"""Wiki configuration code
$Id: metaconfigure.py,v 1.1 2003/04/08 04:14:21 srichter Exp $
"""
from zope.interface import implements
from zope.configuration.interfaces import INonEmptyDirective
from zope.configuration.interfaces import ISubdirectiveHandler
from zope.configuration.action import Action
from zope.configuration.exceptions import ConfigurationError
from zope.app.component.metaconfigure import handler
from zopeproducts.zwiki.sourcetype import SourceTypes
class sourcetype:
__class_implements__ = INonEmptyDirective
__implements__ = ISubdirectiveHandler
def __init__(self, _context, interface, title=u''):
self.iface = _context.resolve(interface)
self.title = title
self.renderers = []
def renderer(self, _context, for_, factory):
if for_ == '*':
for_ = None
self.renderers.append((_context.resolve(for_),
_context.resolve(factory)))
return ()
def __call__(self):
actions = []
# register each renderer as a view
for iface, factory in self.renderers:
actions.append(Action(
discriminator = ('view', self.iface, None, iface, 'default'),
callable=handler,
args = ('Views', 'provideView',
self.iface, None, iface, factory, 'default')
)
)
# register source type in WikiSourceTypeRegistry
actions.append(Action(
discriminator = ('zwiki source type', self.title, self.iface),
callable=SourceTypes.provide,
args = (self.title, self.iface)
)
)
return actions
=== Added File zopeproducts/zwiki/meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
<directives namespace="http://namespaces.zope.org/wiki">
<directive name="sourcetype" handler=".metaconfigure.sourcetype">
<description>
The renderers directive specifies how a particular source text can
be rendered for various view types. It also generates a registry of
available source types.
</description>
<attribute name="for" required="yes">
<description>
The for attribute specifies a marker interface for specifying the
particular source type.
</description>
</attribute>
<attribute name="title" required="yes">
<description>
Provides a title for the source type.
</description>
</attribute>
<subdirective name="renderer">
<description>
Register a renderer for a paricular output interface, such as
IBrowserView.
</description>
<attribute name="for" required="yes">
<description>
Specifies the interface of the output type (i.e. browser) for
which this view is being registered.
</description>
</attribute>
<attribute name="factory" required="yes">
<description>
Specifies the factory that is used to create the view on the source.
</description>
</attribute>
</subdirective>
</directive>
</directives>
</zopeConfigure>