[Checkins] SVN: zope.app.pagetemplate/trunk/ * Moved ``namedtemplate`` from ``zope.formlib`` here as it is more
Michael Howitz
mh at gocept.com
Mon May 18 15:49:20 EDT 2009
Log message for revision 100104:
* Moved ``namedtemplate`` from ``zope.formlib`` here as it is more
about a page template engine than a formular library. This also
breaks some dependencies on ``zope.formlib``.
* Added doctests to long_description to show up on pypi.
Changed:
U zope.app.pagetemplate/trunk/CHANGES.txt
U zope.app.pagetemplate/trunk/buildout.cfg
U zope.app.pagetemplate/trunk/setup.py
U zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml
A zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py
A zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt
A zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt
A zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py
-=-
Modified: zope.app.pagetemplate/trunk/CHANGES.txt
===================================================================
--- zope.app.pagetemplate/trunk/CHANGES.txt 2009-05-18 19:30:41 UTC (rev 100103)
+++ zope.app.pagetemplate/trunk/CHANGES.txt 2009-05-18 19:49:19 UTC (rev 100104)
@@ -1,15 +1,20 @@
-Changes
-=======
+=========
+ Changes
+=========
-3.5.1 (unreleased)
+3.6.0 (unreleased)
------------------
-* ...
+* Moved ``namedtemplate.*`` from ``zope.formlib`` here as it is more
+ about a page template engine than a formular library. This also
+ breaks some dependencies on ``zope.formlib``.
+* Added doctests to long_description to show up on pypi.
+
3.5.0 (2009-02-01)
------------------
-* Use `zope.container` instead of `zope.app.container`.
+* Use ``zope.container`` instead of ``zope.app.container``.
3.4.1 (2008-07-30)
------------------
Modified: zope.app.pagetemplate/trunk/buildout.cfg
===================================================================
--- zope.app.pagetemplate/trunk/buildout.cfg 2009-05-18 19:30:41 UTC (rev 100103)
+++ zope.app.pagetemplate/trunk/buildout.cfg 2009-05-18 19:49:19 UTC (rev 100104)
@@ -1,8 +1,12 @@
[buildout]
develop = .
-parts = test
-find-links = http://download.zope.org/distribution/
+parts = test importchecker
[test]
recipe = zc.recipe.testrunner
-eggs = zope.app.pagetemplate [test]
+eggs = zope.app.pagetemplate [test]
+
+[importchecker]
+recipe = zc.recipe.egg
+eggs = importchecker
+arguments = "${buildout:directory}/src"
Modified: zope.app.pagetemplate/trunk/setup.py
===================================================================
--- zope.app.pagetemplate/trunk/setup.py 2009-05-18 19:30:41 UTC (rev 100103)
+++ zope.app.pagetemplate/trunk/setup.py 2009-05-18 19:49:19 UTC (rev 100104)
@@ -1,16 +1,27 @@
from setuptools import setup, find_packages
+import os.path
-long_description = (open('README.txt').read() +
- '\n\n' +
- open('CHANGES.txt').read())
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+version = '3.6.0dev'
+
+
setup(name='zope.app.pagetemplate',
- version = '3.5.1dev',
+ version=version,
url='http://pypi.python.org/pypi/zope.app.pagetemplate',
author='Zope Corporation and Contributors',
author_email='zope-dev at zope.org',
description='PageTemplate integration for Zope 3',
- long_description=long_description,
+ long_description=(
+ read('README.txt')
+ + '\n\n.. contents::\n\n' +
+ read('src', 'zope', 'app', 'pagetemplate', 'tests', 'test_nested.txt')
+ + '\n\n' +
+ read('src', 'zope', 'app', 'pagetemplate', 'namedtemplate.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
license='ZPL 2.1',
classifiers=['Environment :: Web Environment',
'Intended Audience :: Developers',
@@ -18,7 +29,6 @@
'Programming Language :: Python',
'Framework :: Zope3',
],
-
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['zope', 'zope.app'],
Modified: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml 2009-05-18 19:30:41 UTC (rev 100103)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/configure.zcml 2009-05-18 19:49:19 UTC (rev 100104)
@@ -8,7 +8,7 @@
for="*"
provides="zope.traversing.interfaces.IPathAdapter"
factory=".talesapi.ZopeTalesAPI"
- name="zope"
+ name="zope"
/>
<class class=".talesapi.ZopeTalesAPI">
@@ -20,11 +20,11 @@
for="*"
provides="zope.traversing.interfaces.IPathAdapter"
factory=".urlquote.URLQuote"
- name="url"/>
+ name="url"/>
<class class=".urlquote.URLQuote">
<allow attributes="quote quote_plus unquote unquote_plus"/>
- </class>
+ </class>
<class class="zope.tales.tales.Iterator">
<allow interface="zope.tales.interfaces.ITALESIterator" />
@@ -60,4 +60,11 @@
factory="zope.app.publication.traversers.NoTraverser"
/>
+ <!-- TALES namespace allows view/template:default etc -->
+ <adapter
+ for="*"
+ factory=".namedtemplate.NamedTemplatePathAdapter"
+ name="template"
+ />
+
</configure>
Copied: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py (from rev 100071, zope.formlib/trunk/src/zope/formlib/namedtemplate.py)
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py (rev 0)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.py 2009-05-18 19:49:19 UTC (rev 100104)
@@ -0,0 +1,76 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+from zope import component, interface
+import zope.traversing.interfaces
+
+class INamedTemplate(interface.Interface):
+ """A template that is looked up by name
+ """
+
+class NamedTemplateImplementation:
+
+ def __init__(self, descriptor, view_type=None):
+ try:
+ descriptor.__get__
+ except AttributeError:
+ raise TypeError(
+ "NamedTemplateImplementation must be passed a descriptor."
+ )
+ self.descriptor = descriptor
+ interface.implementer(INamedTemplate)(self)
+
+ if view_type is not None:
+ component.adapter(view_type)(self)
+
+ def __call__(self, instance):
+ return self.descriptor.__get__(instance, instance.__class__)
+
+
+class implementation:
+
+ def __init__(self, view_type=None):
+ self.view_type = view_type
+
+ def __call__(self, descriptor):
+ return NamedTemplateImplementation(descriptor, self.view_type)
+
+
+class NamedTemplate(object):
+
+ def __init__(self, name):
+ self.__name__ = name
+
+ def __get__(self, instance, type=None):
+ if instance is None:
+ return self
+ return component.getAdapter(instance, INamedTemplate, self.__name__)
+
+ def __call__(self, instance, *args, **kw):
+ self.__get__(instance)(*args, **kw)
+
+
+# TODO need test
+class NamedTemplatePathAdapter(object):
+
+ interface.implements(zope.traversing.interfaces.IPathAdapter)
+
+ def __init__(self, context):
+ self.context = context
+
+ def __getitem__(self, name):
+ return component.getAdapter(self.context, INamedTemplate, name)
Copied: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt (from rev 100071, zope.formlib/trunk/src/zope/formlib/namedtemplate.txt)
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt (rev 0)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/namedtemplate.txt 2009-05-18 19:49:19 UTC (rev 100104)
@@ -0,0 +1,73 @@
+===============
+Named Templates
+===============
+
+We often want to be able to define view logic and view templates
+independently. We'd like to be able to change the template used by a
+form without being forced to modify the form.
+
+Named templates provide templates that are registered as named view
+adapters. To define a named template, use the `NamedTemplateImplementation`
+constructor:
+
+ >>> from zope.app.pagetemplate import ViewPageTemplateFile
+ >>> from zope.app.pagetemplate.namedtemplate import (
+ ... NamedTemplateImplementation)
+ >>> sample = ViewPageTemplateFile('tests/namedtemplate.pt')
+ >>> sample = NamedTemplateImplementation(sample)
+
+Let's define a view that uses the named template. To use a named
+template, use the NamedTemplate constructor, and give a template name:
+
+ >>> from zope.app.pagetemplate.namedtemplate import NamedTemplate
+ >>> class MyView:
+ ... def __init__(self, context, request):
+ ... self.context = context
+ ... self.request = request
+ ...
+ ... __call__ = NamedTemplate('sample')
+
+Normally, we'd register a named template for a view interface, to
+allow it to be registered for multiple views. We'll just register it
+for our view class.
+
+ >>> from zope import component
+ >>> component.provideAdapter(sample, [MyView], name='sample')
+
+Now, with this in place, we should be able to use our view:
+
+ >>> class MyContent:
+ ... def __init__(self, name):
+ ... self.name = name
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> print MyView(MyContent('bob'), TestRequest())(x=42)
+ <html><body>
+ Hello bob
+ The URL is http://127.0.0.1
+ The positional arguments were ()
+ The keyword argument x is 42
+ </body></html>
+ <BLANKLINE>
+
+The view type that a named template is to be used for can be supplied
+when the named template is created:
+
+ >>> class MyView:
+ ... def __init__(self, context, request):
+ ... self.context = context
+ ... self.request = request
+ ...
+ ... __call__ = NamedTemplate('sample2')
+
+ >>> sample = ViewPageTemplateFile('tests/namedtemplate.pt')
+ >>> sample = NamedTemplateImplementation(sample, MyView)
+ >>> component.provideAdapter(sample, name='sample2')
+ >>> print MyView(MyContent('bob'), TestRequest())(x=42)
+ <html><body>
+ Hello bob
+ The URL is http://127.0.0.1
+ The positional arguments were ()
+ The keyword argument x is 42
+ </body></html>
+ <BLANKLINE>
Copied: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt (from rev 100071, zope.formlib/trunk/src/zope/formlib/sample.pt)
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt (rev 0)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/namedtemplate.pt 2009-05-18 19:49:19 UTC (rev 100104)
@@ -0,0 +1,6 @@
+<html><body>
+Hello <span tal:replace="context/name" />
+The URL is <span tal:replace="request/URL" />
+The positional arguments were <span tal:replace="args" />
+The keyword argument x is <span tal:replace="options/x" />
+</body></html>
Copied: zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py (from rev 100071, zope.formlib/trunk/src/zope/formlib/tests.py)
===================================================================
--- zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py (rev 0)
+++ zope.app.pagetemplate/trunk/src/zope/app/pagetemplate/tests/test_namedtemplate.py 2009-05-18 19:49:19 UTC (rev 100104)
@@ -0,0 +1,37 @@
+##############################################################################
+#
+# Copyright (c) 2005-2009 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+import os
+import os.path
+import zope.component.testing
+import zope.traversing.adapters
+
+
+def pageSetUp(test):
+ zope.component.testing.setUp(test)
+ zope.component.provideAdapter(
+ zope.traversing.adapters.DefaultTraversable,
+ [None],
+ )
+
+
+def test_suite():
+ from zope.testing import doctest
+ return doctest.DocFileSuite(
+ os.path.join(os.pardir, 'namedtemplate.txt'),
+ setUp=pageSetUp, tearDown=zope.component.testing.tearDown,
+ )
More information about the Checkins
mailing list