[Checkins] SVN: grok/branches/darrylcousins-branch/ Added mars.viewlet. All mars.* tests pass but they could certainly be improved upon.

Darryl Cousins darryl at darrylcousins.net.nz
Thu Jul 5 07:39:13 EDT 2007


Log message for revision 77453:
  Added mars.viewlet. All mars.* tests pass but they could certainly be improved upon.

Changed:
  U   grok/branches/darrylcousins-branch/buildout.cfg
  U   grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt
  U   grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt
  U   grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py
  U   grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py
  U   grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py
  U   grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/template.py
  U   grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/test_all.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/
  A   grok/branches/darrylcousins-branch/mars.viewlet/setup.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/__init__.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/README.txt
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/__init__.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/components.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.txt
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/interfaces.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.zcml
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/__init__.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/ftesting.zcml
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/index.pt
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/test_all.py
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.pt
  A   grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.py

-=-
Modified: grok/branches/darrylcousins-branch/buildout.cfg
===================================================================
--- grok/branches/darrylcousins-branch/buildout.cfg	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/buildout.cfg	2007-07-05 11:39:13 UTC (rev 77453)
@@ -1,5 +1,5 @@
 [buildout]
-develop = . mars.layer mars.template mars.macro mars.view mars.contentprovider
+develop = . mars.layer mars.template mars.macro mars.view mars.contentprovider mars.viewlet
 parts = app data instance test
 find-links = http://download.zope.org/distribution/
 
@@ -14,6 +14,7 @@
        mars.template
        mars.macro
        mars.view
+       mars.viewlet
        mars.contentprovider
 recipe = zc.zope3recipes:app
 site.zcml = <include package="zope.security" file="meta.zcml" />
@@ -94,6 +95,7 @@
        mars.template
        mars.macro
        mars.view
+       mars.viewlet
        mars.contentprovider
 defaults = ['--tests-pattern', '^f?tests$', '-v']
 

Modified: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/README.txt	2007-07-05 11:39:13 UTC (rev 77453)
@@ -13,8 +13,22 @@
 
 ::
 
-    Code
+ class Index(mars.view.LayoutView):
+     pass
 
+ class IndexLayout(mars.template.LayoutFactory):
+     grok.template('index.pt')
+     grok.context(Index)
+
+ class Title(mars.contentprovider.ContentProvider):
+
+     def render(self):
+         return self.context.title
+
+Template for index may be::
+
+ <tal:block tal:content="structure provider:title" />
+
 Directives
 ----------
 

Modified: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/directive.txt	2007-07-05 11:39:13 UTC (rev 77453)
@@ -1,6 +1,6 @@
-========================
-Mars Template Directives
-========================
+===============================
+Mars ContentProvider Directives
+===============================
 
 The mars.layer directive may be used
 -----------------------------------------

Modified: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/meta.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -11,8 +11,6 @@
     
     def register(self, factory, module_info):
 
-#        print '\nname:', self.view_name,'context:', self.view_context,'factory:', factory,\
-#              'layer:', self.view_layer, 'provides', self.provides, '\n'
         zope.component.provideAdapter(factory,
                                  adapts=(self.view_context, self.view_layer, IBrowserView),
                                  provides=self.provides,

Modified: grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.contentprovider/src/mars/contentprovider/tests/contentprovider.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -22,9 +22,6 @@
 import mars.template
 import mars.contentprovider
 
-class Mammoth(grok.Model):
-    title = u'Manfred'
-
 class IMySkinLayer(mars.layer.IMinimalLayer):
     pass
 
@@ -34,6 +31,9 @@
 class MySkin(mars.layer.Skin):
     pass
 
+class Mammoth(grok.Model):
+    title = u'Manfred'
+
 class Index(mars.view.LayoutView):
     pass
 

Modified: grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -38,8 +38,8 @@
                 filepath = template_name
         if filepath is None:
             raise GrokError("No template found for %s."
-                            " Please use grok.template to define path to file."
-                            " containing the template"
+                            " Please use grok.template to define path to the"
+                            " file containing the template"
                             % (factory.__name__),
                             factory)
 

Modified: grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/template.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/template.py	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/template.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -15,6 +15,7 @@
   >>> from zope.publisher.browser import TestRequest
   >>> request = TestRequest()
   >>> view = Painting(mammoth, request)
+  >>> from zope.publisher.interfaces.browser import IBrowserView
 
 Since a template is not yet registered, rendering the view will fail:
 

Modified: grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/test_all.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/test_all.py	2007-07-05 10:49:22 UTC (rev 77452)
+++ grok/branches/darrylcousins-branch/mars.view/src/mars/view/tests/test_all.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -9,7 +9,7 @@
 def test_suite():
     suite = unittest.TestSuite()
     dottedname = 'mars.view.tests.%s'
-    for name in ['layout']:
+    for name in ['layout', 'template']:
         test = FunctionalDocTestSuite(dottedname % name)
         test.layer = TestLayer
         suite.addTest(test)

Added: grok/branches/darrylcousins-branch/mars.viewlet/setup.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/setup.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/setup.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,34 @@
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup(
+    name='mars.viewlet',
+    version='0.1',
+    author='Darryl Cousins',
+    author_email='darryl.cousins at tfws.org.nz',
+    url='http://www.tfws.org.nz/martian',
+    description="""\
+Martian is a library that allows the embedding of configuration
+information in Python code. Martian can then grok the system and
+do the appropriate configuration registrations.
+
+This package uses martian to define viewlets and viewlet managers""",
+    long_description=(
+        read('src/mars/viewlet/README.txt')
+        ),
+    packages=find_packages('src'),
+    package_dir = {'': 'src'},
+    include_package_data = True,
+    zip_safe=False,
+    license='ZPL',
+    install_requires=['setuptools',
+                      'martian',
+                      'zope.viewlet',
+                      'z3c.viewlet',
+                     ],
+)
+
+


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/setup.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/__init__.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/__init__.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,7 @@
+try:
+    # Declare this a namespace package if pkg_resources is available.
+    import pkg_resources
+    pkg_resources.declare_namespace('mars')
+except ImportError:
+    pass
+


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/README.txt	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/README.txt	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,29 @@
+==========
+Mars Macro
+==========
+
+Martian is a library that allows the embedding of configuration
+information in Python code. Martian can then grok the system and
+do the appropriate configuration registrations.
+
+z3c packages bring significant clarity and a pattern for forms, view and
+templates.
+
+This package uses martian to configure viewlets and viewletmanagers.
+
+Example Code
+------------
+
+Please see ./tests/viewlet.py
+
+Directives
+----------
+
+Please see ``directive.txt``.
+
+Tests
+-----
+
+See test directory.
+
+


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/README.txt
___________________________________________________________________
Name: svn:keywords
   + Date Author

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/__init__.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/__init__.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,2 @@
+from directive import manager, view
+from components import Viewlet, ViewletManager


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/components.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/components.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/components.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,61 @@
+import zope.interface
+from zope.component.interfaces import ComponentLookupError
+from zope.publisher.browser import BrowserView
+from zope.publisher.publish import mapply
+from zope.viewlet.interfaces import IViewlet, IViewletManager
+
+from z3c.viewlet.manager import WeightOrderedViewletManager
+
+from martian import util
+
+from mars.view.components import TemplateViewBase
+
+class Viewlet(TemplateViewBase, BrowserView):
+    zope.interface.implements(IViewlet)
+
+    def __init__(self, context, request, view, manager):
+        self.__parent__ = self.view = view
+        self.context = context
+        self.request = request
+        self.manager = manager
+
+class ViewletManager(WeightOrderedViewletManager, TemplateViewBase):
+    zope.interface.implements(IViewletManager)
+
+    def __init__(self, context, request, view):
+        self.__updated = False
+        self.__parent__ = self.view = view
+        self.context = context
+        self.request = request
+
+    def render(self):
+        """Allows template rendering before falling back to the viewlets"""
+        template = getattr(self, 'template', None)
+        if template is not None:
+            return template(self)
+        else:
+            try:
+                template = zope.component.getMultiAdapter(
+                    (self, self.request), self._template_interface, 
+                    name=self._template_name)
+                return template(self)
+            except ComponentLookupError:
+                return u'\n'.join([viewlet.render() for viewlet in self.viewlets])
+
+    def update_manager(self):
+        super(ViewletManager, self).update()
+
+
+    def filter(self, viewlets):
+        """Sort out all content providers
+
+        ``viewlets`` is a list of tuples of the form (name, viewlet).
+        """
+# this is the original for z.v.manager.py but I would get ForbiddenAttribute: ('render'
+# for the viewlets, I need to go a step and create security checkers on viewlets
+# as on Views
+        # Only return viewlets accessible to the principal
+        #import zope.security
+        #return [(name, viewlet) for name, viewlet in viewlets
+        #                        if zope.security.canAccess(viewlet, 'render')]
+        return [(name, viewlet) for name, viewlet in viewlets]


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/components.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,7 @@
+from martian.directive import (InterfaceOrClassDirective,
+                               ClassDirectiveContext)
+
+manager = InterfaceOrClassDirective('mars.viewlet.manager',
+                           ClassDirectiveContext())
+view = InterfaceOrClassDirective('mars.viewlet.view',
+                           ClassDirectiveContext())


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.txt	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.txt	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,43 @@
+=======================
+Mars Viewlet Directives
+=======================
+
+Directives specific to this package
+-----------------------------------
+
+* mars.viewlet.manager(class_or_interface):
+  The manager for which the viewlet is registered.
+  Default: IViewletManager (?)
+
+* mars.viewlet.view(class_or_interface):
+  The view for which the viewlet is registered.
+  Default: zope.publisher.interfaces.browser.IBrowserView
+
+
+The mars.layer directive may be used
+-----------------------------------------
+
+* mars.layer.layer(class_or_interface):
+  The layer for which the template should be available.
+  Default: zope.publisher.browser.interfaces.IDefaultBrowserLayer
+
+Relevant grok directives
+------------------------
+
+* grok.name(name):
+  Name of the view, available in url as object/@@viewname.
+  Default: factory.__name__.lower()
+
+* grok.context(class_or_interface):
+  The view for which the template should be available. Usually should be
+  defined.
+  Default: module context
+
+* grok.template(name):
+  If defined the template will be looked up as a `named adapter`. Should only be
+  defined if a template has been registered as a named adapter.
+  Default: ''
+
+* grok.provides(class_or_interface):
+  Interface the class is looked up as, probably wouldn't be used.
+  Default: zope.interface.Interface


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/directive.txt
___________________________________________________________________
Name: svn:keywords
   + Date Author

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/interfaces.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/interfaces.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/interfaces.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,13 @@
+import zope.interface
+
+class IMarsViewletDirectives(zope.interface.Interface):
+
+    def manager(class_or_interface):
+        """The manager for which the viewlet is registered
+        Default: zope.viewlet.interfaces.IViewletManager
+        """
+
+    def view(class_or_interface):
+        """The view for which the viewlet is registered
+        Default: zope.publisher.browser.interfaces.IBrowserView
+        """


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/interfaces.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,44 @@
+import zope.component
+from zope.publisher.interfaces.browser import IBrowserView
+
+from zope.viewlet.interfaces import IViewlet, IViewletManager
+
+from martian import util
+
+import mars.viewlet
+from mars.view.meta import ViewGrokkerBase
+
+class ViewletManagerGrokker(ViewGrokkerBase):
+    component_class = mars.viewlet.ViewletManager
+    provides = IViewletManager
+    
+    def register(self, factory, module_info):
+
+#        print '\nname:', self.view_name,'context:', self.view_context,'factory:', factory,\
+#              'layer:', self.view_layer, 'provides', self.provides, '\n'
+        zope.component.provideAdapter(factory,
+                     adapts=(self.view_context, self.view_layer, IBrowserView),
+                     provides=self.provides,
+                     name=self.view_name)
+
+
+class ViewletGrokker(ViewGrokkerBase):
+    component_class = mars.viewlet.Viewlet
+
+    def register(self, factory, module_info):
+
+        manager = util.class_annotation(factory, 'mars.viewlet.manager',
+                       None) or module_info.getAnnotation('mars.viewlet.manager',
+                       None) or IViewletManager # IViewletManager?
+
+        view = util.class_annotation(factory, 'mars.viewlet.view',
+                       None) or IBrowserView
+#        print '\nname:', self.view_name,'context:', self.view_context,'factory:', factory,\
+#              'layer:', self.view_layer, 'manager', manager, 'view: ', view,'\n'
+        zope.component.provideAdapter(factory,
+                                 adapts=(self.view_context, self.view_layer, 
+                                         view, manager),
+                                 provides=IViewlet,
+                                 name=self.view_name)
+
+


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.zcml	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/meta.zcml	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,2 @@
+<grok package=".meta" xmlns="http://namespaces.zope.org/grok" />
+

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/__init__.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/__init__.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1 @@
+#


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/ftesting.zcml	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/ftesting.zcml	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,21 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+           xmlns:meta="http://namespaces.zope.org/meta"
+           xmlns:browser="http://namespaces.zope.org/browser"
+           i18n_domain="zope"
+           package="mars.template.tests">
+
+  <include package="grok" file="meta.zcml" />
+  <include package="mars.template" file="meta.zcml" />
+  <include package="mars.layer" file="meta.zcml" />
+  <include package="mars.macro" file="meta.zcml" />
+  <include package="mars.view" file="meta.zcml" />
+  <include package="mars.viewlet" file="meta.zcml" />
+
+  <include package="z3c.layer.minimal.tests" file="ftesting.zcml" />
+
+  <include package="zope.contentprovider" />
+  <include package="grok" />
+
+</configure>
+
+

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/index.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/index.pt	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/index.pt	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,11 @@
+<html>
+<body>
+<div id="leftcolumn">
+<tal:block tal:content="structure provider:leftcolumn" />
+</div>
+<div id="rightcolumn">
+<tal:block tal:content="structure provider:rightcolumn" />
+</div>
+</body>
+</html>
+

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/test_all.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/test_all.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/test_all.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,22 @@
+import unittest
+from pkg_resources import resource_listdir
+
+from grok.ftests.test_grok_functional import FunctionalDocTestSuite
+
+from zope.app.testing import functional
+functional.defineLayer('TestLayer', 'ftesting.zcml')
+
+def test_suite():
+    suite = unittest.TestSuite()
+    dottedname = 'mars.viewlet.tests.%s'
+    for name in ['viewlet']:
+        test = FunctionalDocTestSuite(dottedname % name)
+        test.layer = TestLayer
+        suite.addTest(test)
+
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/test_all.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.pt	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.pt	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1 @@
+<div>Second viewlet content</div>

Added: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.py	                        (rev 0)
+++ grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.py	2007-07-05 11:39:13 UTC (rev 77453)
@@ -0,0 +1,89 @@
+"""
+
+  >>> import grok
+  >>> grok.grok('mars.viewlet.tests.viewlet')
+  >>> from mars.viewlet.tests.viewlet import Mammoth
+  >>> getRootFolder()["manfred"] = Mammoth()
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+  >>> browser.handleErrors = False
+  >>> skinURL = 'http://localhost/++skin++myskin'
+  >>> browser.open(skinURL + "/manfred/@@index")
+  >>> print browser.contents
+  <html>
+  <body>
+  <div id="leftcolumn">
+  <div>First viewlet content</div>
+  <div>Second viewlet content</div>
+  <BLANKLINE>
+  </div>
+  <div id="rightcolumn">
+  Right column content
+  </div>
+  </body>
+  </html>
+
+"""
+import grok
+import mars.layer
+import mars.viewlet
+import mars.view
+import mars.template
+
+### This the context of the views
+class Mammoth(grok.Model):
+    title = u'Manfred'
+
+### define a layer that will be used for all views in this module
+class IModuleLayer(mars.layer.IMinimalLayer):
+    pass
+
+mars.layer.layer(IModuleLayer)
+
+### this skin uses the defined layer
+class MySkin(mars.layer.Skin):
+    pass
+
+### the page that we are looking at
+class Index(mars.view.LayoutView):
+    pass
+
+### the template for index page
+class IndexLayout(mars.template.LayoutFactory):
+    grok.template('index.pt') # required
+    grok.context(Index) # required
+
+### a manager registered for Mammoth and IModuleLayer
+class RightColumn(mars.viewlet.ViewletManager):
+
+    def render(self):
+        return u'Right column content'
+
+### a second manager registered for Mammoth and IModuleLayer
+class LeftColumn(mars.viewlet.ViewletManager):
+    """Joins output of viewlets"""
+    pass
+
+### viewlets for leftcolumn manager
+class FirstViewlet(mars.viewlet.Viewlet):
+    """A simple viewlet"""
+    grok.context(Mammoth)
+    mars.viewlet.manager(LeftColumn)
+    mars.viewlet.view(Index) # not required
+    weight = 0
+
+    def render(self):
+        return u'<div>First viewlet content</div>'
+
+### the second of which uses a template
+class SecondViewlet(mars.viewlet.Viewlet):
+    """A viewlet that has its own template"""
+    grok.context(Mammoth)
+    mars.viewlet.manager(LeftColumn)
+    weight = 1
+
+class SecondViewletTemplate(mars.template.TemplateFactory):
+    grok.template('viewlet.pt')
+    grok.context(SecondViewlet)
+


Property changes on: grok/branches/darrylcousins-branch/mars.viewlet/src/mars/viewlet/tests/viewlet.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Checkins mailing list