[Checkins] SVN: five.grok/trunk/ The rest of the functional tests.
Lennart Regebro
regebro at gmail.com
Fri Jul 18 04:43:30 EDT 2008
Log message for revision 88472:
The rest of the functional tests.
Changed:
U five.grok/trunk/buildout.cfg
U five.grok/trunk/src/five/grok/components.py
U five.grok/trunk/src/five/grok/configure.zcml
A five.grok/trunk/src/five/grok/ftests/view/index.py
A five.grok/trunk/src/five/grok/ftests/view/layers.py
A five.grok/trunk/src/five/grok/ftests/view/macros.py
A five.grok/trunk/src/five/grok/ftests/view/view.py
U five.grok/trunk/src/five/grok/meta.py
-=-
Modified: five.grok/trunk/buildout.cfg
===================================================================
--- five.grok/trunk/buildout.cfg 2008-07-18 08:33:24 UTC (rev 88471)
+++ five.grok/trunk/buildout.cfg 2008-07-18 08:43:30 UTC (rev 88472)
@@ -61,4 +61,4 @@
recipe = zc.recipe.testrunner
eggs = five.grok
extra-paths = ${zope2:location}/lib/python
-defaults = ['--tests-pattern', '^f?tests$', '-v']
+defaults = ['--tests-pattern', '^ftests$', '-v']
Modified: five.grok/trunk/src/five/grok/components.py
===================================================================
--- five.grok/trunk/src/five/grok/components.py 2008-07-18 08:33:24 UTC (rev 88471)
+++ five.grok/trunk/src/five/grok/components.py 2008-07-18 08:43:30 UTC (rev 88472)
@@ -1,4 +1,5 @@
import sys, os
+import warnings
import martian
from zope import interface
Modified: five.grok/trunk/src/five/grok/configure.zcml
===================================================================
--- five.grok/trunk/src/five/grok/configure.zcml 2008-07-18 08:33:24 UTC (rev 88471)
+++ five.grok/trunk/src/five/grok/configure.zcml 2008-07-18 08:43:30 UTC (rev 88472)
@@ -1,7 +1,22 @@
<configure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:meta="http://namespaces.zope.org/meta"
+ xmlns:browser="http://namespaces.zope.org/browser"
xmlns:grok="http://namespaces.zope.org/grok">
- <grok:grok package=".meta" />
-
+ <grok:grok package=".meta" />
+
+ <browser:defaultView
+ for=".interfaces.IContext"
+ name="index"
+ />
+
+ <permission
+ id="zope.View"
+ title="View"
+ />
+
+ <include package="zope.app.basicskin" />
+ <include package="zope.app.rotterdam" />
+
</configure>
Added: five.grok/trunk/src/five/grok/ftests/view/index.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/index.py (rev 0)
+++ five.grok/trunk/src/five/grok/ftests/view/index.py 2008-07-18 08:43:30 UTC (rev 88472)
@@ -0,0 +1,37 @@
+"""
+ >>> from five.grok.ftests.view.index import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+The default view name for a model is 'index':
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>Hello, world!</h1>
+ <span>Blue</span>
+ <span>Blue</span>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ teeth = u"Blue"
+
+class Index(grok.View):
+ pass
+
+index = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello, world!</h1>
+<span tal:content="python:context.teeth">green</span>
+<span tal:content="context/teeth">green</span>
+</body>
+</html>
+""")
Property changes on: five.grok/trunk/src/five/grok/ftests/view/index.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: five.grok/trunk/src/five/grok/ftests/view/layers.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/layers.py (rev 0)
+++ five.grok/trunk/src/five/grok/ftests/view/layers.py 2008-07-18 08:43:30 UTC (rev 88472)
@@ -0,0 +1,64 @@
+"""
+ >>> from five.grok.ftests.view.layers import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/++skin++Basic/manfred/@@cavedrawings")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>Hello, world!</h1>
+ </body>
+ </html>
+
+ >>> browser.open("http://localhost/++skin++Rotterdam/manfred/@@moredrawings")
+ >>> print browser.contents
+ Pretty
+
+ >>> browser.open("http://localhost/++skin++myskin/manfred/@@evenmoredrawings")
+ >>> print browser.contents
+ Awesome
+
+"""
+from five import grok
+from zope.app.basicskin import IBasicSkin
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app.rotterdam import rotterdam
+from zope import interface
+
+grok.layer(IBasicSkin)
+
+class MySkinLayer(grok.IGrokLayer):
+ pass
+
+class MySkin(grok.Skin):
+ grok.layer(MySkinLayer)
+
+class Mammoth(grok.Model):
+ pass
+
+class CaveDrawings(grok.View):
+ pass
+
+cavedrawings = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello, world!</h1>
+</body>
+</html>
+""")
+
+class MoreDrawings(grok.View):
+ grok.layer(rotterdam)
+
+ def render(self):
+ return "Pretty"
+
+
+class EvenMoreDrawings(grok.View):
+ grok.layer(MySkinLayer)
+
+ def render(self):
+ return "Awesome"
Property changes on: five.grok/trunk/src/five/grok/ftests/view/layers.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: five.grok/trunk/src/five/grok/ftests/view/macros.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/macros.py (rev 0)
+++ five.grok/trunk/src/five/grok/ftests/view/macros.py 2008-07-18 08:43:30 UTC (rev 88472)
@@ -0,0 +1,116 @@
+"""
+ >>> from five.grok.ftests.view.macros import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred/@@painting")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>GROK MACRO!</h1>
+ <div>
+ GROK SLOT!
+ </div>
+ </body>
+ </html>
+
+Views without a template do not support macros:
+
+ >>> browser.open("http://localhost/manfred/@@dancing")
+ Traceback (most recent call last):
+ AttributeError: template
+
+If the view has an attribute with the same name as a macro, the macro
+shadows the view. XXX This should probably generate a warning at runtime.
+
+ >>> browser.open("http://localhost/manfred/@@grilldish")
+ >>> print browser.contents
+ <html>
+ Curry
+ </html>
+
+You can skip the "macro" part of the macro call, but this is deprecated:
+
+ >>> from five.grok.testing import warn
+ >>> import warnings
+ >>> saved_warn = warnings.warn
+ >>> warnings.warn = warn
+
+ >>> browser.open("http://localhost/manfred/@@burnt")
+ From five.grok.testing's warn():
+ ... DeprecationWarning: Calling macros directly on the view is deprecated. Please use context/@@viewname/macros/macroname
+ ...
+
+ >>> warnings.warn = saved_warn
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class DancingHall(grok.View):
+
+ def render(self):
+ return "A nice large dancing hall for mammoths."
+
+class Grilled(grok.View):
+
+ def update(self):
+ self.spices = "Pepper and salt"
+
+class Painting(grok.View):
+ pass
+
+painting = grok.PageTemplate("""\
+<html metal:use-macro="context/@@layout/macros/main">
+<div metal:fill-slot="slot">
+GROK SLOT!
+</div>
+</html>
+""")
+
+class Layout(grok.View):
+ pass
+
+layout = grok.PageTemplate("""\
+<html metal:define-macro="main">
+<body>
+<h1>GROK MACRO!</h1>
+<div metal:define-slot="slot">
+</div>
+</body>
+</html>""")
+
+class Dancing(grok.View):
+ pass
+
+dancing = grok.PageTemplate("""\
+<html metal:use-macro="context/@@dancinghall/macros/something">
+</html>
+""")
+
+class GrillDish(grok.View):
+ pass
+
+grilldish = grok.PageTemplate("""
+<html metal:use-macro="context/@@grilled/macros/spices">
+</html>""")
+
+class Burnt(grok.View):
+ pass
+
+burnt = grok.PageTemplate("""\
+<html metal:use-macro="context/@@grilled/spices">
+</html>""")
+
+class Grilled(grok.View):
+ pass
+
+grilled = grok.PageTemplate("""\
+<html metal:define-macro="spices">
+Curry
+</html>""")
+
Property changes on: five.grok/trunk/src/five/grok/ftests/view/macros.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: five.grok/trunk/src/five/grok/ftests/view/view.py
===================================================================
--- five.grok/trunk/src/five/grok/ftests/view/view.py (rev 0)
+++ five.grok/trunk/src/five/grok/ftests/view/view.py 2008-07-18 08:43:30 UTC (rev 88472)
@@ -0,0 +1,31 @@
+"""
+ >>> from five.grok.ftests.view.view import *
+ >>> id = getRootFolder()._setObject("manfred", Mammoth(id='manfred'))
+
+ >>> from Products.Five.testbrowser import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+ >>> browser.open("http://localhost/manfred/@@painting")
+ >>> print browser.contents
+ <html>
+ <body>
+ <h1>Hello, world!</h1>
+ </body>
+ </html>
+
+"""
+from five import grok
+
+class Mammoth(grok.Model):
+ pass
+
+class Painting(grok.View):
+ pass
+
+painting = grok.PageTemplate("""\
+<html>
+<body>
+<h1>Hello, world!</h1>
+</body>
+</html>
+""")
Property changes on: five.grok/trunk/src/five/grok/ftests/view/view.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: five.grok/trunk/src/five/grok/meta.py
===================================================================
--- five.grok/trunk/src/five/grok/meta.py 2008-07-18 08:33:24 UTC (rev 88471)
+++ five.grok/trunk/src/five/grok/meta.py 2008-07-18 08:43:30 UTC (rev 88472)
@@ -2,8 +2,9 @@
from martian import util
from martian.error import GrokError
from zope import interface, component
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-
+from zope.publisher.interfaces.browser import (IDefaultBrowserLayer,
+ IBrowserRequest,
+ IBrowserSkinType)
from five import grok
from Products.Five.security import protectClass
@@ -148,3 +149,16 @@
args=(module_info,)
)
return True
+
+class SkinGrokker(martian.ClassGrokker):
+ martian.component(grok.Skin)
+ martian.directive(grok.layer, default=IBrowserRequest)
+ martian.directive(grok.name, get_default=default_view_name)
+
+ def execute(self, factory, config, name, layer, **kw):
+ config.action(
+ discriminator=('skin', name),
+ callable=component.interface.provideInterface,
+ args=(name, layer, IBrowserSkinType)
+ )
+ return True
More information about the Checkins
mailing list