1
"""Example of using nevow.accessors.ObjectContainer to allow data directives to
2
look inside application types.
5
from nevow import accessors, inevow, loaders, rend, tags as T
6
from twisted.python.components import registerAdapter
9
"""An image consisting of a filename and some comments.
11
def __init__(self, filename, comments):
12
self.filename = filename
13
self.comments = comments
16
# Register the adapter so Nevow can access Image instance attributes.
17
registerAdapter(accessors.ObjectContainer, Image, inevow.IContainer)
20
# Just a list of images to render in the page.
22
Image('python.gif', ['Hisssssssss']),
23
Image('cat.gif', ['Meeow', 'Purrrrrrrr']),
27
class ImagePage(rend.Page):
28
"""A simple page that renders a list of images. We registered an adapter
29
earlier so that the data= directives inside the pattern can look inside
35
def render_images(self, ctx, data):
36
"""Render a list of images.
38
tag = T.div(data=images, render=rend.sequence)[
39
T.div(pattern='item')[
40
T.p(data=T.directive('filename'), render=T.directive('data')),
41
T.ul(data=T.directive('comments'), render=rend.sequence)[
42
T.li(pattern='item', render=T.directive('data')),
48
docFactory = loaders.stan( T.html[T.body[T.directive('images')]] )
52
"""Create the root resource of the example.