[Checkins] SVN: five.grok/trunk/src/five/grok/ Inline template
support.
Lennart Regebro
regebro at gmail.com
Thu Jul 17 08:52:55 EDT 2008
Log message for revision 88435:
Inline template support.
Changed:
U five.grok/trunk/src/five/grok/__init__.py
A five.grok/trunk/src/five/grok/tests/view/inline.py
-=-
Modified: five.grok/trunk/src/five/grok/__init__.py
===================================================================
--- five.grok/trunk/src/five/grok/__init__.py 2008-07-17 12:49:51 UTC (rev 88434)
+++ five.grok/trunk/src/five/grok/__init__.py 2008-07-17 12:52:54 UTC (rev 88435)
@@ -7,7 +7,7 @@
from grokcore.component.directive import context, name, provides
from grokcore.component.decorators import subscribe
-from five.grok.components import View, Model
+from five.grok.components import View, Model, PageTemplate
from five.grok.directive import require, layer, template, templatedir
# I don't know why this is necessary:
Added: five.grok/trunk/src/five/grok/tests/view/inline.py
===================================================================
--- five.grok/trunk/src/five/grok/tests/view/inline.py (rev 0)
+++ five.grok/trunk/src/five/grok/tests/view/inline.py 2008-07-17 12:52:54 UTC (rev 88435)
@@ -0,0 +1,65 @@
+"""
+Templates can be specified in the same module as the view,
+using a variable named `viewname_pt`:
+
+ >>> grok.testing.grok(__name__)
+
+ >>> manfred = Mammoth()
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> from zope import component
+ >>> view = component.getMultiAdapter((manfred, request), name='cavepainting')
+ >>> print view()
+ <html>
+ <body>
+ <h1>Mammoth Cave Painting</h1>
+ <ul>
+ <li><zope.publisher.browser.TestRequest instance URL=http://127.0.0.1></li>
+ <li><five.grok.tests.view.inline.CavePainting object at 0x...></li>
+ <li><five.grok.tests.view.inline.Mammoth object at 0x...></li>
+ <li><zope.app.pagetemplate.engine.TraversableModuleImporter object at 0x...></li>
+ </ul>
+ </body>
+ </html>
+
+Note that the CavePainting instance is bound to the ``view`` name in
+the template. This shows that the association of inline PageTemplate
+and the view class is successful.
+
+Finding a template does not depend on the view name, but on the class
+name:
+
+ >>> view = component.getMultiAdapter((manfred, request), name='hunting')
+ >>> print view()
+ <html><body><h1>GROK HUNT MAMMOTH!</h1></body></html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class CavePainting(grok.View):
+ pass
+
+cavepainting = grok.PageTemplate("""\
+<html>
+<body>
+<h1 tal:content="string:Mammoth Cave Painting"/>
+<ul>
+ <li tal:content="structure python:repr(request)" />
+ <li tal:content="structure nocall:view" />
+ <li tal:content="structure nocall:context" />
+ <li tal:content="structure nocall:modules" />
+</ul>
+</body>
+</html>
+""")
+
+class Hunt(grok.View):
+ grok.name('hunting')
+
+hunt = grok.PageTemplate("""\
+<html><body><h1>GROK HUNT MAMMOTH!</h1></body></html>
+""")
+
Property changes on: five.grok/trunk/src/five/grok/tests/view/inline.py
___________________________________________________________________
Name: svn:keywords
+ Id
More information about the Checkins
mailing list