[Zope3-checkins]
SVN: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/
Renamed pagelet to viewlet everywhere. Also renamed slot to
region, since
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Sep 18 07:11:10 EDT 2005
Log message for revision 38510:
Renamed pagelet to viewlet everywhere. Also renamed slot to region, since
slot is a reserved term for METAL and might thus be confusing.
Changed:
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/README.txt
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/__init__.py
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/configure.zcml
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/directives.txt
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/interfaces.py
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/meta.zcml
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metaconfigure.py
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metadirectives.py
D Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/pagelet.py
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tales.py
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_doc.py
D Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_pagelet.pt
A Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_viewlet.pt
A Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/viewlet.py
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-configure.zcml
U Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-meta.zcml
-=-
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/README.txt
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/README.txt 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/README.txt 2005-09-18 11:11:10 UTC (rev 38510)
@@ -1,11 +1,11 @@
========
-Pagelets
+Viewlets
========
This package provides a framework to develop componentized Web GUI
applications. Instead of describing the content of a page using a single
template or static system of templates and METAL macros, regions (called
-slots) can be defined and are filled dynamically with content based on the
+regions) can be defined and are filled dynamically with content based on the
setup of the application.
The Design
@@ -26,14 +26,14 @@
|_________|
|
|
- |* a view is composed of slots
+ |* a view is composed of regions
____v____
| |
- | ViewSlot |
+ | ViewRegion |
|__________|
|
|
- |* a slot contains a list of viewlets
+ |* a region contains a list of viewlets
____v____ _____________
| | | |
| Viewlet |------| ViewletType |
@@ -44,31 +44,31 @@
| |
____|____ ____|____
| | | |
- | Pagelet | | Portlet |
+ | Viewlet | | Portlet |
|_________| |_________|
Natively, Zope 3 allows us to associate one or more views to a given
object. Those views are either registered for the provided interfaces of the
object or the object itself. In a view, usually a template, one can define
-zero or more view slots. Upon rendering time, those view slots are populated
-with the viewlets that have been assigned to the slot.
+zero or more view regions. Upon rendering time, those view regions are populated
+with the viewlets that have been assigned to the region.
-The Difference betwen a Pagelet and a Portlet
+The Difference betwen a Viewlet and a Portlet
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-Let's start with the properties the two share. Pagelets and portlets are
+Let's start with the properties the two share. Viewlets and portlets are
designed to be parts of a view; they are specialized viewlets. In the Zope
world the difference is commonly seen as follows:
- * A pagelet of a view displays the underlying context.
+ * A viewlet of a view displays the underlying context.
* A portlet of a view displays data from different contexts.
-For example, the metadata pagelet displays the metadata of the underlying
+For example, the metadata viewlet displays the metadata of the underlying
context. A metadata portlet, on the other hand, could display the metadata of
all of the context's children (assuming the context is a container). In a
-second example, a calendar pagelet displays the calendar data of a content
+second example, a calendar viewlet displays the calendar data of a content
object that implements its own calendar, while a calendar portlet displays
global calendar data on different objects that may come from an utility.
@@ -76,15 +76,15 @@
Zope 3, since the adaption mechanism used for looking up views hides the data
retrieval from the user. Thus, let's slightly reword the definitions:
- * A pagelet of a view operates on the underlying context.
+ * A viewlet of a view operates on the underlying context.
* A portlet of a view operates on the underlying or on a different context.
-Rephrasing our examples, we have: The metadata pagelet displays the metadata
+Rephrasing our examples, we have: The metadata viewlet displays the metadata
of the view context by adapting it to ``IMetadata``. The portlet, on the other
hand, adapts to a context independent of the underlying view context.
-Therefore, a set of pagelets of the same type inside a particular views must
+Therefore, a set of viewlets of the same type inside a particular views must
always display similar content, while a set of portlets of the same type can
provide a wide range of contents from very different parts of the site.
@@ -92,34 +92,34 @@
Usage
-----
-This pagelet implementation supports pagelets of the first and second
+This viewlet implementation supports viewlets of the first and second
definition, but portlets only of the first. In the following text we use the
-term "pagelet" as defined in the second definition.
+term "viewlet" as defined in the second definition.
-Pagelets are responsible for a piece of content in a view. They can be used to
+Viewlets are responsible for a piece of content in a view. They can be used to
provide additionally information about an object that is not fully relevant
for the view's functionality, but provides useful information and/or links to
-the user. Pagelets are small, view-like components that are identified by the
+the user. Viewlets are small, view-like components that are identified by the
following set of interfaces they are registered for:
- * Layer: The layer in which the pagelet will be used.
+ * Layer: The layer in which the viewlet will be used.
* Content Type: The interface the context of the the view must provide. This
- is the ``for`` attribute of the view and pagelet directive.
+ is the ``for`` attribute of the view and viewlet directive.
* View: The interface the view must provide. By default this is
``IBrowserView`` and the default is commonly not changed.
- * Slot: The instance of the slot in which this pagelet can be placed.
+ * Region: The instance of the region in which this viewlet can be placed.
-Inside a pagetemplate the pagelets of a particular slot can be retrieved using
-the ``pagelets`` TALES namespace. The return value is a sequence of pagelet
-objects that can simply be called. The pagelets are selected by the four
-above-mentioned parameters and sorted by the weight of the pagelets::
+Inside a pagetemplate the viewlets of a particular region can be retrieved using
+the ``viewlets`` TALES namespace. The return value is a sequence of viewlet
+objects that can simply be called. The viewlets are selected by the four
+above-mentioned parameters and sorted by the weight of the viewlets::
<div class="row">
- <tal:repeat="pagelet pagelets:path.to.Slot">
- <tal:block replace="structure pagelet" />
+ <tal:repeat="viewlet viewlets:path.to.Region">
+ <tal:block replace="structure viewlet" />
</tal:repeat>
</div>
@@ -128,30 +128,30 @@
----------
Before we even start demonstrating the template, we need to register the
-`pagelets` TALES namespace:
+`viewlets` TALES namespace:
>>> from zope.app.pagetemplate import metaconfigure
- >>> from zope.app.pagelet import tales
- >>> metaconfigure.registerType('pagelets', tales.TALESPageletsExpression)
+ >>> from zope.app.viewlet import tales
+ >>> metaconfigure.registerType('viewlets', tales.TALESViewletsExpression)
-The first task will be to create a slot that we can use in a pagetemplate. A
-slot is simply an interface that simply needs to provide ``IPageletSlot``. The
+The first task will be to create a region that we can use in a pagetemplate. A
+region is simply an interface that simply needs to provide ``IViewletRegion``. The
interface is then registered as a utility providing the interface.
>>> import zope.interface
- >>> class IDemoSlot(zope.interface.Interface):
- ... '''A slot for demonstration purposes.'''
+ >>> class IDemoRegion(zope.interface.Interface):
+ ... '''A region for demonstration purposes.'''
- >>> from zope.app.pagelet import interfaces
- >>> zope.interface.directlyProvides(IDemoSlot, interfaces.IPageletSlot)
+ >>> from zope.app.viewlet import interfaces
+ >>> zope.interface.directlyProvides(IDemoRegion, interfaces.IViewletRegion)
>>> import zope.component
- >>> zope.component.provideUtility(IDemoSlot, interfaces.IPageletSlot,
- ... 'DemoSlot')
+ >>> zope.component.provideUtility(IDemoRegion, interfaces.IViewletRegion,
+ ... 'DemoRegion')
-The argument to the slot class is commonly used for documentations. Next we
-can create pagelets for this Now we can create a page template that uses this
-slot object to define a slot in the template:
+The argument to the region class is commonly used for documentations. Next we
+can create viewlets for this Now we can create a page template that uses this
+region object to define a region in the template:
>>> import os, tempfile
>>> temp_dir = tempfile.mkdtemp()
@@ -160,11 +160,11 @@
>>> open(zpt_filename, 'w').write('''
... <html>
... <body>
- ... <h1>Pagelet Demo</h1>
+ ... <h1>Viewlet Demo</h1>
... <div class="left-column">
... <div class="column-item"
- ... tal:repeat="pagelet pagelets:DemoSlot">
- ... <tal:block replace="structure pagelet" />
+ ... tal:repeat="viewlet viewlets:DemoRegion">
+ ... <tal:block replace="structure viewlet" />
... </div>
... </div>
... </body>
@@ -184,60 +184,60 @@
... zope.interface.Interface,
... name='demo.html')
-In the following step we will create a couple of pagelets that are used in the
-demo page. Pagelets are really views, except that they additionally adapt
-their view and slot. The first pagelet is a minimalistic implementation:
+In the following step we will create a couple of viewlets that are used in the
+demo page. Viewlets are really views, except that they additionally adapt
+their view and region. The first viewlet is a minimalistic implementation:
>>> from zope.app.publisher.browser import BrowserView
- >>> class Pagelet1(BrowserView):
+ >>> class Viewlet1(BrowserView):
... weight = 0
...
- ... def __init__(self, context, request, view, slot):
- ... super(Pagelet1, self).__init__(context, request)
+ ... def __init__(self, context, request, view, region):
+ ... super(Viewlet1, self).__init__(context, request)
...
... def __call__(self):
- ... return u'<h3>Pagelet 1 Content</h3>'
+ ... return u'<h3>Viewlet 1 Content</h3>'
>>> from zope.security.checker import NamesChecker, defineChecker
- >>> pageletChecker = NamesChecker(('__call__', 'weight'))
- >>> defineChecker(Pagelet1, pageletChecker)
+ >>> viewletChecker = NamesChecker(('__call__', 'weight'))
+ >>> defineChecker(Viewlet1, viewletChecker)
>>> from zope.interface import Interface, providedBy
>>> from zope.app.publisher.interfaces.browser import IBrowserView
>>> zope.component.provideAdapter(
- ... Pagelet1,
- ... (Interface, IDefaultBrowserLayer, IBrowserView, IDemoSlot),
- ... interfaces.IPagelet,
- ... name='pagelet1')
+ ... Viewlet1,
+ ... (Interface, IDefaultBrowserLayer, IBrowserView, IDemoRegion),
+ ... interfaces.IViewlet,
+ ... name='viewlet1')
-Let's now register a more typical pagelet. We first create a template:
+Let's now register a more typical viewlet. We first create a template:
- >>> plt_filename = os.path.join(temp_dir, 'pagelet2.pt')
+ >>> plt_filename = os.path.join(temp_dir, 'viewlet2.pt')
>>> open(plt_filename, 'w').write('''
... <div class="box">
- ... <tal:block replace="pagelet/title" />
+ ... <tal:block replace="viewlet/title" />
... </div>
... ''')
- >>> class Pagelet2Base(object):
+ >>> class Viewlet2Base(object):
... def title(self):
- ... return 'Pagelet 2 Content'
+ ... return 'Viewlet 2 Content'
-As you can see, the pagelet Python class is known as ``pagelet``, while the
+As you can see, the viewlet Python class is known as ``viewlet``, while the
view class is still available as ``view``. Next we build and register the
-pagelet using a special helper function:
+viewlet using a special helper function:
- >>> from zope.app.pagelet import pagelet
- >>> Pagelet2 = pagelet.SimplePageletClass(
- ... plt_filename, bases=(Pagelet2Base,), name='pagelet2', weight=1)
+ >>> from zope.app.viewlet import viewlet
+ >>> Viewlet2 = viewlet.SimpleViewletClass(
+ ... plt_filename, bases=(Viewlet2Base,), name='viewlet2', weight=1)
- >>> defineChecker(Pagelet2, pageletChecker)
+ >>> defineChecker(Viewlet2, viewletChecker)
>>> zope.component.provideAdapter(
- ... Pagelet2,
- ... (Interface, IDefaultBrowserLayer, IBrowserView, IDemoSlot),
- ... interfaces.IPagelet,
- ... name='pagelet2')
+ ... Viewlet2,
+ ... (Interface, IDefaultBrowserLayer, IBrowserView, IDemoRegion),
+ ... interfaces.IViewlet,
+ ... name='viewlet2')
Now all the setup is completed. Let's create a content object:
@@ -256,15 +256,15 @@
>>> print view().strip()
<html>
<body>
- <h1>Pagelet Demo</h1>
+ <h1>Viewlet Demo</h1>
<div class="left-column">
<div class="column-item">
- <h3>Pagelet 1 Content</h3>
+ <h3>Viewlet 1 Content</h3>
</div>
<div class="column-item">
<BLANKLINE>
<div class="box">
- Pagelet 2 Content
+ Viewlet 2 Content
</div>
<BLANKLINE>
</div>
@@ -274,40 +274,40 @@
Note that if we turn the weight around,
- >>> Pagelet1.weight = 1
- >>> Pagelet2._weight = 0
+ >>> Viewlet1.weight = 1
+ >>> Viewlet2._weight = 0
the order of the left column in the page template shoudl change:
>>> print view().strip()
<html>
<body>
- <h1>Pagelet Demo</h1>
+ <h1>Viewlet Demo</h1>
<div class="left-column">
<div class="column-item">
<BLANKLINE>
<div class="box">
- Pagelet 2 Content
+ Viewlet 2 Content
</div>
<BLANKLINE>
</div>
<div class="column-item">
- <h3>Pagelet 1 Content</h3>
+ <h3>Viewlet 1 Content</h3>
</div>
</div>
</body>
</html>
-Looking up a pagelet by name
+Looking up a viewlet by name
----------------------------
-In some cases you want to be able to look up a particular pagelet for a slot,
+In some cases you want to be able to look up a particular viewlet for a region,
given a context and a view. For this use case, you can simply use a second
-TALES namespace called ``pagelet`` that selects the pagelet using the
-expression ``<path to slot>/<pagelet name>``.
+TALES namespace called ``viewlet`` that selects the viewlet using the
+expression ``<path to region>/<viewlet name>``.
- >>> metaconfigure.registerType('pagelet', tales.TALESPageletExpression)
+ >>> metaconfigure.registerType('viewlet', tales.TALESViewletExpression)
Since everything else is already setup, we can simply register a new view:
@@ -315,10 +315,10 @@
>>> open(zpt_filename2, 'w').write('''
... <html>
... <body>
- ... <h1>Pagelet Demo</h1>
+ ... <h1>Viewlet Demo</h1>
... <div class="left-column">
... <div class="column-item">
- ... <tal:block replace="structure pagelet:DemoSlot/pagelet1" />
+ ... <tal:block replace="structure viewlet:DemoRegion/viewlet1" />
... </div>
... </div>
... </body>
@@ -337,14 +337,14 @@
>>> print view().strip()
<html>
<body>
- <h1>Pagelet Demo</h1>
+ <h1>Viewlet Demo</h1>
<div class="left-column">
<div class="column-item">
- <h3>Pagelet 1 Content</h3>
+ <h3>Viewlet 1 Content</h3>
</div>
</div>
</body>
</html>
-Note that this namespace returns the rendered pagelet and not the pagelet
-view, like the ``pagelets`` TALES namespace.
+Note that this namespace returns the rendered viewlet and not the viewlet
+view, like the ``viewlets`` TALES namespace.
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/__init__.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/__init__.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/__init__.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Pagelet exceptions
+"""Viewlet exceptions
$Id$
"""
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/configure.zcml
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/configure.zcml 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/configure.zcml 2005-09-18 11:11:10 UTC (rev 38510)
@@ -4,16 +4,16 @@
i18n_domain="zope"
>
- <interface interface=".interfaces.ITALESPageletsExpression" />
+ <interface interface=".interfaces.ITALESViewletsExpression" />
<tales:expressiontype
- name="pagelets"
- handler=".tales.TALESPageletsExpression"
+ name="viewlets"
+ handler=".tales.TALESViewletsExpression"
/>
- <interface interface=".interfaces.ITALESPageletExpression" />
+ <interface interface=".interfaces.ITALESViewletExpression" />
<tales:expressiontype
- name="pagelet"
- handler=".tales.TALESPageletExpression"
+ name="viewlet"
+ handler=".tales.TALESViewletExpression"
/>
</configure>
\ No newline at end of file
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/directives.txt
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/directives.txt 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/directives.txt 2005-09-18 11:11:10 UTC (rev 38510)
@@ -1,41 +1,41 @@
=========================
-The ``pagelet`` Directive
+The ``viewlet`` Directive
=========================
-The pagelet directive allows you to quickly register a new paglet without much
+The viewlet directive allows you to quickly register a new paglet without much
hassle, like it was shown in the `README.txt` file. Here is a sample
directive::
>>> from zope.configuration import xmlconfig
>>> context = xmlconfig.string('''
... <configure i18n_domain="zope">
- ... <include package="zope.app.pagelet" file="meta.zcml" />
+ ... <include package="zope.app.viewlet" file="meta.zcml" />
... </configure>
... ''')
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet"
... for="*"
- ... slot=".test_doc.ITestSlot"
- ... template="test_pagelet.pt"
+ ... region=".test_doc.ITestRegion"
+ ... template="test_viewlet.pt"
... permission="zope.Public"
... />
... </configure>
... ''', context=context)
As you can see, the directive looks very similar to the page directive and you
-are right. The pagelet directive does not permit you to specify a `menu` and
-`title`, since it is not sensible to have a menu item for a pagelet. However,
-it does support two more qualifying attributes, `view` and `slot`. While view
-is nearly never specified (very common default), the `slot` attribute *must*
+are right. The viewlet directive does not permit you to specify a `menu` and
+`title`, since it is not sensible to have a menu item for a viewlet. However,
+it does support two more qualifying attributes, `view` and `region`. While view
+is nearly never specified (very common default), the `region` attribute *must*
be specified. An optional `weight` attribute (not shown above) allows you to
-change the position of a particular pagelet relative to the others. The
+change the position of a particular viewlet relative to the others. The
default value is zero.
-If we now look into the adapter registry, we will find the pagelet:
+If we now look into the adapter registry, we will find the viewlet:
>>> class Content(object):
... pass
@@ -48,81 +48,81 @@
>>> view = BrowserView(content, request)
>>> import zope.interface
- >>> from zope.app.pagelet.tests.test_doc import ITestSlot
- >>> class Slot(object):
+ >>> from zope.app.viewlet.tests.test_doc import ITestRegion
+ >>> class Region(object):
... pass
- >>> slot = Slot()
- >>> zope.interface.directlyProvides(slot, ITestSlot)
+ >>> region = Region()
+ >>> zope.interface.directlyProvides(region, ITestRegion)
>>> import zope.component
- >>> from zope.app.pagelet.interfaces import IPagelet
- >>> pagelet = zope.component.getMultiAdapter(
- ... (content, request, view, slot), IPagelet, name='testpagelet')
- >>> pagelet()
- u'<div>testpagelet macro content</div>\n'
+ >>> from zope.app.viewlet.interfaces import IViewlet
+ >>> viewlet = zope.component.getMultiAdapter(
+ ... (content, request, view, region), IViewlet, name='testviewlet')
+ >>> viewlet()
+ u'<div>testviewlet macro content</div>\n'
-Let's now ensure that we can also specify a pagelet class:
+Let's now ensure that we can also specify a viewlet class:
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet2"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet2"
... for="*"
- ... slot=".test_doc.ITestSlot"
- ... template="test_pagelet.pt"
- ... class=".test_doc.TestPagelet"
+ ... region=".test_doc.ITestRegion"
+ ... template="test_viewlet.pt"
+ ... class=".test_doc.TestViewlet"
... permission="zope.Public"
... />
... </configure>
... ''', context=context)
- >>> pagelet = zope.component.getMultiAdapter(
- ... (content, request, view, slot), IPagelet, name='testpagelet2')
- >>> pagelet()
- u'<div>testpagelet macro content</div>\n'
+ >>> viewlet = zope.component.getMultiAdapter(
+ ... (content, request, view, region), IViewlet, name='testviewlet2')
+ >>> viewlet()
+ u'<div>testviewlet macro content</div>\n'
Okay, so the template-driven cases wrok. But just specifying a class should
also work:
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet3"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet3"
... for="*"
- ... slot=".test_doc.ITestSlot"
- ... class=".test_doc.TestPagelet2"
+ ... region=".test_doc.ITestRegion"
+ ... class=".test_doc.TestViewlet2"
... permission="zope.Public"
... />
... </configure>
... ''', context=context)
- >>> pagelet = zope.component.getMultiAdapter(
- ... (content, request, view, slot), IPagelet, name='testpagelet3')
- >>> pagelet()
+ >>> viewlet = zope.component.getMultiAdapter(
+ ... (content, request, view, region), IViewlet, name='testviewlet3')
+ >>> viewlet()
u'called'
It should also be possible to specify an alternative attribute of the class to
-be rendered upon calling the pagelet:
+be rendered upon calling the viewlet:
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet4"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet4"
... for="*"
- ... slot=".test_doc.ITestSlot"
- ... class=".test_doc.TestPagelet"
+ ... region=".test_doc.ITestRegion"
+ ... class=".test_doc.TestViewlet"
... attribute="doSomething"
... permission="zope.Public"
... />
... </configure>
... ''', context=context)
- >>> pagelet = zope.component.getMultiAdapter(
- ... (content, request, view, slot), IPagelet, name='testpagelet4')
- >>> pagelet()
+ >>> viewlet = zope.component.getMultiAdapter(
+ ... (content, request, view, region), IViewlet, name='testviewlet4')
+ >>> viewlet()
u'something'
@@ -133,10 +133,10 @@
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet"
- ... slot=".test_doc.ITestSlot"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet"
+ ... region=".test_doc.ITestRegion"
... permission="zope.Public"
... />
... </configure>
@@ -151,11 +151,11 @@
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet"
- ... slot=".test_doc.ITestSlot"
- ... template="test_pagelet.pt"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet"
+ ... region=".test_doc.ITestRegion"
+ ... template="test_viewlet.pt"
... attribute="faux"
... permission="zope.Public"
... />
@@ -171,11 +171,11 @@
>>> context = xmlconfig.string('''
... <configure xmlns="http://namespaces.zope.org/browser" i18n_domain="zope"
- ... package="zope.app.pagelet.tests">
- ... <pagelet
- ... name="testpagelet"
- ... slot=".test_doc.ITestSlot"
- ... class=".test_doc.TestPagelet"
+ ... package="zope.app.viewlet.tests">
+ ... <viewlet
+ ... name="testviewlet"
+ ... region=".test_doc.ITestRegion"
+ ... class=".test_doc.TestViewlet"
... attribute="faux"
... permission="zope.Public"
... />
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/interfaces.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/interfaces.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/interfaces.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Pagelet interfaces
+"""Viewlet interfaces
$Id$
"""
@@ -29,26 +29,26 @@
from zope.app.publisher.interfaces.browser import IBrowserView
-class PageletSlotLookupError(ComponentLookupError):
- """Pagelet slot object not found."""
+class ViewletRegionLookupError(ComponentLookupError):
+ """Viewlet region object not found."""
-class IPageletSlot(IInterface):
- """Marker interface for pagelet slots.
+class IViewletRegion(IInterface):
+ """Marker interface for viewlet regions.
- The pagelet slot is used as a part ot the key for to register and
- collect pagelets.
+ The viewlet region is used as a part ot the key for to register and
+ collect viewlets.
"""
-class IPagelet(IBrowserView):
- """Interface for custom pagelet adapters.
+class IViewlet(IBrowserView):
+ """Interface for custom viewlet adapters.
- Pagelets can be used in a page template as a piece of content rendered
- with it's own python view class. Yes with pagelets you can use more then
- one views in a pageltemplate. This let's pagelets act as portlets. The
- pagelet view can support content independent information where you can
- access in every page template on which the pagelet is registered.
+ Viewlets can be used in a page template as a piece of content rendered
+ with it's own python view class. Yes with viewlets you can use more then
+ one views in a pageltemplate. This let's viewlets act as portlets. The
+ viewlet view can support content independent information where you can
+ access in every page template on which the viewlet is registered.
The meta directive set the 'weight' attribute to the class attribute
'_weight'. If you whould like to use the settings from the meta directive
@@ -58,43 +58,43 @@
class attribute '_template'.
"""
- view = Attribute('The view the pagelet is used in.')
+ view = Attribute('The view the viewlet is used in.')
- slot = Attribute('The slot in which the pagelet is placed.')
+ region = Attribute('The region in which the viewlet is placed.')
weight = Int(
title=_(u'weight'),
description=_(u"""
- Key for sorting pagelets if the pagelet collector is supporting
+ Key for sorting viewlets if the viewlet collector is supporting
this sort mechanism."""),
required=False,
default=0)
-class ITALESPageletsExpression(ITALESExpression):
- """TAL namespace for getting a list of pagelets.
+class ITALESViewletsExpression(ITALESExpression):
+ """TAL namespace for getting a list of viewlets.
- To call pagelets in a view use the the following syntax in a page
+ To call viewlets in a view use the the following syntax in a page
template::
- <tal:block repeat="pagelet pagelets:path.to.my.ISlot">
- <tal:block replace="structure pagelet" />
+ <tal:block repeat="viewlet viewlets:path.to.my.IRegion">
+ <tal:block replace="structure viewlet" />
</tal:block>
- where ``path.to.my.ISlot`` is a slot object that provides
- ``pagelet.interfaces.IPageletSlot``.
+ where ``path.to.my.IRegion`` is a region object that provides
+ ``viewlet.interfaces.IViewletRegion``.
"""
-class ITALESPageletExpression(ITALESExpression):
- """TAL namespace for getting a single pagelet.
+class ITALESViewletExpression(ITALESExpression):
+ """TAL namespace for getting a single viewlet.
- To call a named pagelet in a view use the the following syntax in a page
+ To call a named viewlet in a view use the the following syntax in a page
template::
- <tal:block replace="structure pagelet:path.to.my.ISlot/name" />
+ <tal:block replace="structure viewlet:path.to.my.IRegion/name" />
- where ``path.to.my.ISlot`` is a slot object that provides
- ``pagelet.interfaces.IPageletSlot`` and ``name`` is the name of the page
+ where ``path.to.my.IRegion`` is a region object that provides
+ ``viewlet.interfaces.IViewletRegion`` and ``name`` is the name of the page
template .
"""
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/meta.zcml
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/meta.zcml 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/meta.zcml 2005-09-18 11:11:10 UTC (rev 38510)
@@ -4,9 +4,9 @@
<meta:directives namespace="http://namespaces.zope.org/browser">
<meta:directive
- name="pagelet"
- schema=".metadirectives.IPageletDirective"
- handler=".metaconfigure.pagelet"
+ name="viewlet"
+ schema=".metadirectives.IViewletDirective"
+ handler=".metaconfigure.viewlet"
/>
</meta:directives>
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metaconfigure.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metaconfigure.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metaconfigure.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Pagelet metadconfigure
+"""Viewlet metadconfigure
$Id$
"""
@@ -29,13 +29,13 @@
from zope.app.publisher.browser import viewmeta
from zope.app.publisher.interfaces.browser import IBrowserView
-from zope.app.pagelet.interfaces import IPageletSlot, IPagelet
-from zope.app.pagelet.pagelet import SimplePageletClass
-from zope.app.pagelet.pagelet import SimpleAttributePagelet
+from zope.app.viewlet.interfaces import IViewletRegion, IViewlet
+from zope.app.viewlet.viewlet import SimpleViewletClass
+from zope.app.viewlet.viewlet import SimpleAttributeViewlet
-def pagelet(_context, name, permission,
- slot, for_=Interface, layer=IDefaultBrowserLayer, view=IBrowserView,
+def viewlet(_context, name, permission,
+ region, for_=Interface, layer=IDefaultBrowserLayer, view=IBrowserView,
class_=None, template=None, attribute='__call__', weight=0,
allowed_interface=None, allowed_attributes=None):
@@ -75,8 +75,8 @@
"The provided class doesn't have the specified attribute "
)
if template:
- # Create a new class for the pagelet template and class.
- new_class = SimplePageletClass(
+ # Create a new class for the viewlet template and class.
+ new_class = SimpleViewletClass(
template, bases=(class_, ), weight=weight)
else:
if not hasattr(class_, 'browserDefault'):
@@ -90,14 +90,14 @@
cdict['__name__'] = name
cdict['__page_attribute__'] = attribute
new_class = type(class_.__name__,
- (class_, SimpleAttributePagelet), cdict)
+ (class_, SimpleAttributeViewlet), cdict)
if hasattr(class_, '__implements__'):
classImplements(new_class, IBrowserPublisher)
else:
- # Create a new class for the pagelet template alone.
- new_class = SimplePageletClass(template, name=name, weight=weight)
+ # Create a new class for the viewlet template alone.
+ new_class = SimpleViewletClass(template, name=name, weight=weight)
for attr_name in (attribute, 'browserDefault', '__call__',
'publishTraverse', 'weight'):
@@ -110,14 +110,14 @@
viewmeta._handle_for(_context, for_)
metaconfigure.interface(_context, view)
- metaconfigure.interface(_context, slot, IPageletSlot)
+ metaconfigure.interface(_context, region, IViewletRegion)
defineChecker(new_class, Checker(required))
- # register pagelet
+ # register viewlet
_context.action(
- discriminator = ('pagelet', for_, layer, view, slot, name),
+ discriminator = ('viewlet', for_, layer, view, region, name),
callable = metaconfigure.handler,
args = ('provideAdapter',
- (for_, layer, view, slot), IPagelet, name, new_class,
+ (for_, layer, view, region), IViewlet, name, new_class,
_context.info),)
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metadirectives.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metadirectives.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/metadirectives.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Pagelet metadirective
+"""Viewlet metadirective
$Id$
"""
@@ -23,28 +23,28 @@
from zope.app.publisher.browser import metadirectives
-class IPageletDirective(metadirectives.IPagesDirective,
+class IViewletDirective(metadirectives.IPagesDirective,
metadirectives.IViewPageSubdirective):
- """A directive to register a new pagelet.
+ """A directive to register a new viewlet.
- Pagelet registrations are very similar to page registrations, except that
- they are additionally qualified by the slot and view they are used for. An
+ Viewlet registrations are very similar to page registrations, except that
+ they are additionally qualified by the region and view they are used for. An
additional `weight` attribute is specified that is intended to coarsly
- control the order of the pagelets.
+ control the order of the viewlets.
"""
- slot = GlobalInterface(
- title=u"slot",
- description=u"The slot interface this pagelet is for.",
+ region = GlobalInterface(
+ title=u"region",
+ description=u"The region interface this viewlet is for.",
required=True)
view = GlobalInterface(
title=u"view",
- description=u"The interface of the view this pagelet is for. "
+ description=u"The interface of the view this viewlet is for. "
u"(default IBrowserView)""",
required=False)
weight = Int(
title=u"weight",
- description=u"Integer key for sorting pagelets in the same slot.",
+ description=u"Integer key for sorting viewlets in the same region.",
required=False)
Deleted: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/pagelet.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/pagelet.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/pagelet.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -1,90 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Pagelet implementation
-
-$Id: metaconfigure.py 38437 2005-09-10 01:59:07Z rogerineichen $
-"""
-__docformat__ = 'restructuredtext'
-
-import sys
-import zope.interface
-from zope.app.pagetemplate.simpleviewclass import simple
-from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-from zope.app.publisher.browser import BrowserView
-
-from zope.app.pagelet import interfaces
-
-
-class PageletPageTemplateFile(ViewPageTemplateFile):
-
- def pt_getContext(self, instance, request, **_kw):
- namespace = super(PageletPageTemplateFile, self).pt_getContext(
- instance, request, **_kw)
- namespace['view'] = instance.view
- namespace['pagelet'] = instance
- return namespace
-
-
-class SimplePagelet(BrowserView):
- """Pagelet adapter class used in meta directive as a mixin class."""
-
- zope.interface.implements(interfaces.IPagelet)
-
- _weight = 0
-
- def __init__(self, context, request, view, slot):
- super(SimplePagelet, self).__init__(context, request)
- self.view = view
- self.slot = slot
-
- def _getWeight (self):
- """The weight of the pagelet."""
- return self._weight
-
- # See zope.app.pagelet.interfaces.IPagelet
- weight = property(_getWeight)
-
-
-class SimpleAttributePagelet(SimplePagelet):
-
- def publishTraverse(self, request, name):
- raise NotFound(self, name, request)
-
- def __call__(self, *args, **kw):
- # If a class doesn't provide it's own call, then get the attribute
- # given by the browser default.
-
- attr = self.__page_attribute__
- if attr == '__call__':
- raise AttributeError("__call__")
-
- meth = getattr(self, attr)
- return meth(*args, **kw)
-
-
-def SimplePageletClass(template, offering=None, bases=(), name=u'', weight=0):
- # Get the current frame
- if offering is None:
- offering = sys._getframe(1).f_globals
-
- # Create the base class hierarchy
- bases += (SimplePagelet, simple)
-
- # Generate a derived view class.
- class_ = type("SimplePageletClass from %s" % template, bases,
- {'index' : PageletPageTemplateFile(template, offering),
- '_weight' : weight,
- '__name__' : name})
-
- return class_
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tales.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tales.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tales.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Pagelet tales expression registrations
+"""Viewlet tales expression registrations
$Id$
"""
@@ -27,61 +27,61 @@
from zope.app import zapi
-from zope.app.pagelet.interfaces import ITALESPageletExpression
-from zope.app.pagelet.interfaces import ITALESPageletsExpression
-from zope.app.pagelet.interfaces import IPageletSlot
-from zope.app.pagelet.interfaces import IPagelet
-from zope.app.pagelet.interfaces import PageletSlotLookupError
+from zope.app.viewlet.interfaces import ITALESViewletExpression
+from zope.app.viewlet.interfaces import ITALESViewletsExpression
+from zope.app.viewlet.interfaces import IViewletRegion
+from zope.app.viewlet.interfaces import IViewlet
+from zope.app.viewlet.interfaces import ViewletRegionLookupError
-def getSlot(str):
- """Get a slot from the string.
+def getRegion(str):
+ """Get a region from the string.
- This function will create the dummy slot implementation as well.
+ This function will create the dummy region implementation as well.
"""
- slot = zapi.queryUtility(IPageletSlot, name=str)
- if slot is None:
- raise PageletSlotLookupError(
- 'Pagelet slot interface not found.', str)
+ region = zapi.queryUtility(IViewletRegion, name=str)
+ if region is None:
+ raise ViewletRegionLookupError(
+ 'Viewlet region interface not found.', str)
- # Create a dummy slot instance for adapter lookup. This is not ultra
- # clean but puts the burden of filtering by slot on the adapter
+ # Create a dummy region instance for adapter lookup. This is not ultra
+ # clean but puts the burden of filtering by region on the adapter
# registry.
- class DummySlot(object):
- implements(slot)
- return DummySlot()
+ class DummyRegion(object):
+ implements(region)
+ return DummyRegion()
-class TALESPageletsExpression(StringExpr):
- """Collect pagelets via a TAL namespace called `pagelets`."""
+class TALESViewletsExpression(StringExpr):
+ """Collect viewlets via a TAL namespace called `viewlets`."""
- implements(ITALESPageletsExpression)
+ implements(ITALESViewletsExpression)
def __call__(self, econtext):
context = econtext.vars['context']
request = econtext.vars['request']
view = econtext.vars['view']
- # get the slot from the expression
- slot = getSlot(self._s)
+ # get the region from the expression
+ region = getRegion(self._s)
- # Find the pagelets
- pagelets = zapi.getAdapters((context, request, view, slot), IPagelet)
- pagelets = [pagelet for name, pagelet in pagelets
- if canAccess(pagelet, '__call__')]
- pagelets.sort(lambda x, y: cmp(x.weight, y.weight))
+ # Find the viewlets
+ viewlets = zapi.getAdapters((context, request, view, region), IViewlet)
+ viewlets = [viewlet for name, viewlet in viewlets
+ if canAccess(viewlet, '__call__')]
+ viewlets.sort(lambda x, y: cmp(x.weight, y.weight))
- return pagelets
+ return viewlets
-class TALESPageletExpression(StringExpr):
- """Collects a single pagelet via a TAL namespace called pagelet."""
+class TALESViewletExpression(StringExpr):
+ """Collects a single viewlet via a TAL namespace called viewlet."""
- implements(ITALESPageletExpression)
+ implements(ITALESViewletExpression)
def __init__(self, name, expr, engine):
if not '/' in expr:
- raise KeyError('Use `iface/pageletname` for defining the pagelet.')
+ raise KeyError('Use `iface/viewletname` for defining the viewlet.')
parts = expr.split('/')
if len(parts) > 2:
@@ -96,20 +96,20 @@
request = econtext.vars['request']
view = econtext.vars['view']
- # get the slot from the expression
- slot = getSlot(self._iface)
+ # get the region from the expression
+ region = getRegion(self._iface)
- # Find the pagelets
- pagelet = zapi.queryMultiAdapter(
- (context, request, view, slot), IPagelet, name=self._name)
+ # Find the viewlets
+ viewlet = zapi.queryMultiAdapter(
+ (context, request, view, region), IViewlet, name=self._name)
- if pagelet is None:
+ if viewlet is None:
raise ComponentLookupError(
- 'No pagelet with name `%s` found.' %self._name)
+ 'No viewlet with name `%s` found.' %self._name)
- if not canAccess(pagelet, '__call__'):
+ if not canAccess(viewlet, '__call__'):
raise Unauthorized(
- 'You are not authorized to access the pagelet '
+ 'You are not authorized to access the viewlet '
'called `%s`.' %self._name)
- return pagelet()
+ return viewlet()
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_doc.py
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_doc.py 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_doc.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""Pagelet tests
+"""Viewlet tests
$Id$
"""
@@ -23,29 +23,29 @@
from zope.testing.doctestunit import DocTestSuite, DocFileSuite
from zope.app.testing import setup
-from zope.app.pagelet import interfaces
+from zope.app.viewlet import interfaces
-class TestPagelet(object):
+class TestViewlet(object):
def doSomething(self):
return u'something'
-class TestPagelet2(object):
+class TestViewlet2(object):
def __call__(self):
return u'called'
-class ITestSlot(zope.interface.Interface):
- '''A slot for testing purposes.'''
-zope.interface.directlyProvides(ITestSlot, interfaces.IPageletSlot)
+class ITestRegion(zope.interface.Interface):
+ '''A region for testing purposes.'''
+zope.interface.directlyProvides(ITestRegion, interfaces.IViewletRegion)
def test_suite():
return unittest.TestSuite((
- DocTestSuite('zope.app.pagelet.tales'),
+ DocTestSuite('zope.app.viewlet.tales'),
DocFileSuite('../README.txt',
setUp=setup.placefulSetUp,
tearDown=setup.placefulTearDown(),
Deleted: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_pagelet.pt
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_pagelet.pt 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_pagelet.pt 2005-09-18 11:11:10 UTC (rev 38510)
@@ -1 +0,0 @@
-<div>testpagelet macro content</div>
Copied: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_viewlet.pt (from rev 38505, Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_pagelet.pt)
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_pagelet.pt 2005-09-17 13:48:05 UTC (rev 38505)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/tests/test_viewlet.pt 2005-09-18 11:11:10 UTC (rev 38510)
@@ -0,0 +1 @@
+<div>testviewlet macro content</div>
Copied: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/viewlet.py (from rev 38505, Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/pagelet.py)
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/pagelet.py 2005-09-17 13:48:05 UTC (rev 38505)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/viewlet.py 2005-09-18 11:11:10 UTC (rev 38510)
@@ -0,0 +1,90 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Viewlet implementation
+
+$Id: metaconfigure.py 38437 2005-09-10 01:59:07Z rogerineichen $
+"""
+__docformat__ = 'restructuredtext'
+
+import sys
+import zope.interface
+from zope.app.pagetemplate.simpleviewclass import simple
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.publisher.browser import BrowserView
+
+from zope.app.viewlet import interfaces
+
+
+class ViewletPageTemplateFile(ViewPageTemplateFile):
+
+ def pt_getContext(self, instance, request, **_kw):
+ namespace = super(ViewletPageTemplateFile, self).pt_getContext(
+ instance, request, **_kw)
+ namespace['view'] = instance.view
+ namespace['viewlet'] = instance
+ return namespace
+
+
+class SimpleViewlet(BrowserView):
+ """Viewlet adapter class used in meta directive as a mixin class."""
+
+ zope.interface.implements(interfaces.IViewlet)
+
+ _weight = 0
+
+ def __init__(self, context, request, view, region):
+ super(SimpleViewlet, self).__init__(context, request)
+ self.view = view
+ self.region = region
+
+ def _getWeight (self):
+ """The weight of the viewlet."""
+ return self._weight
+
+ # See zope.app.viewlet.interfaces.IViewlet
+ weight = property(_getWeight)
+
+
+class SimpleAttributeViewlet(SimpleViewlet):
+
+ def publishTraverse(self, request, name):
+ raise NotFound(self, name, request)
+
+ def __call__(self, *args, **kw):
+ # If a class doesn't provide it's own call, then get the attribute
+ # given by the browser default.
+
+ attr = self.__page_attribute__
+ if attr == '__call__':
+ raise AttributeError("__call__")
+
+ meth = getattr(self, attr)
+ return meth(*args, **kw)
+
+
+def SimpleViewletClass(template, offering=None, bases=(), name=u'', weight=0):
+ # Get the current frame
+ if offering is None:
+ offering = sys._getframe(1).f_globals
+
+ # Create the base class hierarchy
+ bases += (SimpleViewlet, simple)
+
+ # Generate a derived view class.
+ class_ = type("SimpleViewletClass from %s" % template, bases,
+ {'index' : ViewletPageTemplateFile(template, offering),
+ '_weight' : weight,
+ '__name__' : name})
+
+ return class_
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-configure.zcml
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-configure.zcml 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-configure.zcml 2005-09-18 11:11:10 UTC (rev 38510)
@@ -1 +1 @@
-<include package="zope.app.pagelet" />
\ No newline at end of file
+<include package="zope.app.viewlet" />
\ No newline at end of file
Modified: Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-meta.zcml
===================================================================
--- Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-meta.zcml 2005-09-17 23:31:28 UTC (rev 38509)
+++ Zope3/branches/srichter-viewlet-implementation/src/zope/app/viewlet/zope.app.pagelet-meta.zcml 2005-09-18 11:11:10 UTC (rev 38510)
@@ -1 +1 @@
-<include package="zope.app.pagelet" file="meta.zcml" />
+<include package="zope.app.viewlet" file="meta.zcml" />
More information about the Zope3-Checkins
mailing list