Better access to APIs in paths (was Re: [Zope3-dev] needing views
clues - template/title troubles)
Jim Fulton
jim@zope.com
Mon, 24 Feb 2003 14:55:43 -0500
Wow. This thread has gotten a great response. Let me see if I can
summarize the current proposal.
There will be namespaces of API components. So, for example, given the
namespace "dc" that has the name "title" in it, we can say:
context/dc:title
which looks up the title api in the dc namespace for the object given
by the context.
Note that "name:" at the beginning of a path refers to the
expression type, *not* a namespace.
In Python code, we could do:
api(context).dc.title
Namespace components are like adapters, in that they get instantiated for
specific objects and depend on particular interfaces. They don't need to
implement particular interfaces.
There is a mechanism for declaring namespaces in zpt. The syntaxes proposed
either use or echo xml namespaces:
<p tal:namespaces="dc http://namespaces.zope.org/dc">
The ZCML to register an API would look something like:
<api
namespace="zope"
name="title"
for="zope.app.interfaces.annotation.IAnnotatable"
factory="zope.app.dublincore.annotatableadapter.TitleAPI"
>
title meta-data attribute
The title API attribute provides access to the (unqualified)
Dublin-Core "Title" meta-data element.
</api.
Some people have suggested that namespaces are just adapters.
I think that this would be a bad idea as it would lead to very many
small namespaces.
User's objected stenuously to including xml namespace declarations in
their zpts. We eventually, removed the necessity for declaring namespaces
in HTML zpts. I don't think requiring namspace declarations for API
functions would be popular.
I suggest that it would be better to have very few namespaces. Perhaps
all of the standard apis should be in a standard, namspace. I wouldn't
have a dc namespace. I might have a "dc" name in the standard namespace.
I'd call the standard namespace "zope" or "api":
context/zope:title
or:
context/api:title
I prefer api.
I'd go so far as to allow the standard namespace to be spelled
with an empty string:
context/:title
An application framework could define it's own namespace:
context/plone:title
But I wouldn't make zpt authors declare the namespaces.
If we insist on making people declare namespaces, I would keep it simple,
as in:
<p tal:namespace="plone">
But I really don't think this is necessary.
Also note that this new syntax will be used in TALES outside of zpt.
For example, it would be useful to use these in simple stand-alone
TALES expressions where namespace declarations are inconventient or
impossible,
Jim
--
Jim Fulton mailto:jim@zope.com Python Powered!
CTO (888) 344-4332 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org