[Zope3-checkins] CVS: Zope3/src/zope/app/pagetemplate - meta.zcml:1.1 metaconfigure.py:1.1 talesapi.py:1.1 configure.zcml:1.3

Matt Hamilton matth@netsight.co.uk
Tue, 15 Apr 2003 14:52:58 -0400


Update of /cvs-repository/Zope3/src/zope/app/pagetemplate
In directory cvs.zope.org:/tmp/cvs-serv2345/src/zope/app/pagetemplate

Modified Files:
	configure.zcml 
Added Files:
	meta.zcml metaconfigure.py talesapi.py 
Log Message:
Extended TALES namespace functionality to Zope3.  You can now use 
TALES expressions such as foo/zope:title within ZPT.

Currently only a single function 'title' has been created within
talesapi.py, now we need to work out which functionality we want to 
expose ;-)  Probably look through the ZQR and places like that.




=== Added File Zope3/src/zope/app/pagetemplate/meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>

  <directives namespace="http://namespaces.zope.org/tales">

    <directive name="namespace" handler=".metaconfigure.namespace" >
       <description>Define a new tales namespace
     
       A namespace is defined by providing a prefix and an interface. A
       handler for the namespace will be obtained by looking up an adapter for the
       given interface.
       </description>

       <attribute name="prefix" required="yes">
         <description>The prefix used in tales expressions. 

         For example, if the prefix is "dc", then a tales expression would
         look like: ``foo/bar/dc:title``.
         </description>
       </attribute>

       <attribute name="interface" required="yes">
         <description>The namespace interface

         This is an interface that the namespace must provide.
         we'll get the namespace by getting an adapter for this interface.
         </description>
       </attribute>

    </directive>

  </directives>

</zopeConfigure>


=== Added File Zope3/src/zope/app/pagetemplate/metaconfigure.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""ZCML configuration directives for configuring the default zope: namespace in TALES.

$Id: metaconfigure.py,v 1.1 2003/04/15 18:52:57 matth Exp $
"""

from zope.app.pagetemplate.engine import Engine
from zope.configuration.action import Action
from zope.app.component.metaconfigure import resolveInterface
from zope.testing.cleanup import addCleanUp
from zope.component import getAdapter

def namespace(_context, prefix, interface):
    interface = resolveInterface(_context, interface)
    return [Action(
        discriminator = ("tales:namespace", prefix),
        callable = Engine.registerFunctionNamespace,
        args = (prefix, lambda ob: getAdapter(ob, interface)),
        )]

addCleanUp(Engine.namespaces.clear)


=== Added File Zope3/src/zope/app/pagetemplate/talesapi.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Implementation of the Zope TALES API


$Id: talesapi.py,v 1.1 2003/04/15 18:52:57 matth Exp $
"""

from zope.app.interfaces.talesapi import IZopeTalesAPI
from zope.app.interfaces.dublincore import IZopeDublinCore
from zope.component import queryAdapter

class ZopeTalesAPI(object):

    __implements__ = IZopeTalesAPI

    def __init__(self, context):
        self.context = context

    def title(self):
        a = queryAdapter(self.context, IZopeDublinCore)
        if a is None:
            raise AttributeError, 'title'
        return a.title


=== Zope3/src/zope/app/pagetemplate/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/pagetemplate/configure.zcml:1.2	Wed Mar 12 05:11:13 2003
+++ Zope3/src/zope/app/pagetemplate/configure.zcml	Tue Apr 15 14:52:57 2003
@@ -1,7 +1,19 @@
-<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+<zopeConfigure xmlns='http://namespaces.zope.org/zope'
+               xmlns:tales='http://namespaces.zope.org/tales'>
 
   <content class=".viewpagetemplatefile.BoundPageTemplate">
     <allow attributes="__call__ __str__ __name__" />
   </content>
+
+  <adapter
+      for="*"
+      provides="zope.app.interfaces.talesapi.IZopeTalesAPI"
+      factory=".talesapi.ZopeTalesAPI" 
+      />
+
+  <tales:namespace 
+      prefix="zope"
+      interface="zope.app.interfaces.talesapi.IZopeTalesAPI"
+      />
 
 </zopeConfigure>