[Checkins] SVN: grok/branches/darrylcousins-branch/ Tidied up
mars.template and mars.layer. Added mars.macro without completion.
Darryl Cousins
darryl at darrylcousins.net.nz
Wed Jul 4 05:29:34 EDT 2007
Log message for revision 77392:
Tidied up mars.template and mars.layer. Added mars.macro without completion.
Changed:
U grok/branches/darrylcousins-branch/buildout.cfg
U grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/README.txt
U grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/directive.py
U grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/meta.py
A grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/directive.py
U grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/minimal.py
U grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/test_all.py
A grok/branches/darrylcousins-branch/mars.macro/
A grok/branches/darrylcousins-branch/mars.macro/setup.py
A grok/branches/darrylcousins-branch/mars.macro/src/
A grok/branches/darrylcousins-branch/mars.macro/src/mars/
A grok/branches/darrylcousins-branch/mars.macro/src/mars/__init__.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/README.txt
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/__init__.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/components.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.txt
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/interfaces.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.zcml
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/__init__.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/directive.py
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/ftesting.zcml
A grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/test_all.py
U grok/branches/darrylcousins-branch/mars.template/src/mars/template/README.txt
U grok/branches/darrylcousins-branch/mars.template/src/mars/template/directive.txt
U grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/directive.py
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/layout.py
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/minimal-ftesting.zcml
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/template.py
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/complex.pt
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/macro.pt
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/plain.pt
A grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/view.pt
U grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/test_all.py
-=-
Modified: grok/branches/darrylcousins-branch/buildout.cfg
===================================================================
--- grok/branches/darrylcousins-branch/buildout.cfg 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/buildout.cfg 2007-07-04 09:29:32 UTC (rev 77392)
@@ -1,5 +1,5 @@
[buildout]
-develop = . mars.layer mars.template
+develop = . mars.layer mars.template mars.macro
parts = app data instance test
find-links = http://download.zope.org/distribution/
@@ -12,6 +12,7 @@
martian
mars.layer
mars.template
+ mars.macro
recipe = zc.zope3recipes:app
site.zcml = <include package="zope.security" file="meta.zcml" />
<include package="zope.i18n" file="meta.zcml" />
@@ -89,5 +90,6 @@
martian
mars.layer
mars.template
+ mars.macro
defaults = ['--tests-pattern', '^f?tests$', '-v']
Modified: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/README.txt 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/README.txt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -19,9 +19,24 @@
Example Code
------------
- >>> import mars.layer
- >>> class IMyLayer(mars.layer.IMinimalLayer):
- ... pass
- >>> class MySkin(mars.layer.Skin):
- ... mars.layer.layer(IMyLayer)
+::
+ import mars.layer
+
+ class IMyLayer(mars.layer.IMinimalLayer):
+ pass
+
+ class MySkin(mars.layer.Skin):
+ mars.layer.layer(IMyLayer)
+
+Skin is available as http://localhost/++skin++myskin
+
+Directives
+----------
+
+Please see ``directive.txt``.
+
+Tests
+-----
+
+See test directory.
Modified: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/directive.py 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/directive.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -1,4 +1,4 @@
-from grok.directive import (InterfaceOrClassDirective,
+from martian.directive import (InterfaceOrClassDirective,
ClassOrModuleDirectiveContext)
layer = InterfaceOrClassDirective('mars.layer.layer',
Modified: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/meta.py 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/meta.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -20,6 +20,7 @@
None) or module_info.getAnnotation('mars.layer.layer',
None) or IBrowserRequest
name = grok.util.class_annotation(factory, 'grok.name', factory.__name__.lower())
+ #print '\nName: ', name, 'Factory: ', factory, '\n'
zope.component.interface.provideInterface(name, layer, IBrowserSkinType)
return True
Added: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/directive.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/directive.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,42 @@
+"""
+Test the claimed directives.
+
+ >>> import grok
+ >>> grok.grok('mars.layer.tests.directive')
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+
+ >>> skinURL = 'http://localhost/++skin++namedskin'
+
+Try opening page.htm which is registered in ftesting.zcml for
+z3c.layer.IMinimalBrowserLayer.
+
+ >>> browser.open(skinURL + '/page.html')
+ >>> print browser.contents
+ <BLANKLINE>
+ <html>
+ <head>
+ <title>testing</title>
+ </head>
+ <body>
+ <BLANKLINE>
+ test page
+ <BLANKLINE>
+ </body>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+
+"""
+import grok
+import mars.layer
+
+class IMyLayer(mars.layer.IMinimalLayer):
+ pass
+
+class MySkin(mars.layer.Skin):
+ grok.name('namedskin')
+ mars.layer.layer(IMyLayer)
+
Property changes on: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/minimal.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/minimal.py 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/minimal.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -37,6 +37,10 @@
class IMyLayer(mars.layer.IMinimalLayer):
pass
+# layer can be set on module level and will therefore be the layer
+# for all views, template and macros in the module
+mars.layer.layer(IMyLayer)
+
class MySkin(mars.layer.Skin):
- mars.layer.layer(IMyLayer)
+ pass
Modified: grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/test_all.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/test_all.py 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.layer/src/mars/layer/tests/test_all.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -8,14 +8,17 @@
functional.defineLayer('TestPageletLayer', 'pagelet-ftesting.zcml')
def test_suite():
+ suite = unittest.TestSuite()
dottedname = 'mars.layer.tests.%s'
- suite = unittest.TestSuite()
- test = FunctionalDocTestSuite(dottedname % 'minimal')
- test.layer = TestMinimalLayer
- suite.addTest(test)
+ for name in ['minimal', 'directive']:
+ test = FunctionalDocTestSuite(dottedname % name)
+ test.layer = TestMinimalLayer
+ suite.addTest(test)
+
test = FunctionalDocTestSuite(dottedname % 'pagelet')
test.layer = TestPageletLayer
suite.addTest(test)
+
return suite
Added: grok/branches/darrylcousins-branch/mars.macro/setup.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/setup.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/setup.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,33 @@
+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.macro',
+ 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 z3c.macro macros""",
+ long_description=(
+ read('src/mars/macro/README.txt')
+ ),
+ packages=find_packages('src'),
+ package_dir = {'': 'src'},
+ include_package_data = True,
+ zip_safe=False,
+ license='ZPL',
+ install_requires=['setuptools',
+ 'martian',
+ 'z3c.macro',
+ ],
+)
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/setup.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/__init__.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/__init__.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -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.macro/src/mars/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/README.txt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/README.txt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,31 @@
+==========
+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 z3c.macro based macros.
+
+Example Code
+------------
+
+::
+
+ Code
+
+Directives
+----------
+
+Please see ``directive.txt``.
+
+Tests
+-----
+
+See test directory.
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/README.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/__init__.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/__init__.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,3 @@
+from directive import macro, view, content_type
+from components import MacroFactory
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/components.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/components.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/components.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,2 @@
+class MacroFactory(object):
+ pass
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/components.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,11 @@
+from martian.directive import (InterfaceOrClassDirective,
+ SingleTextDirective,
+ ClassDirectiveContext)
+
+macro = SingleTextDirective('mars.macro.macro',
+ ClassDirectiveContext())
+view = InterfaceOrClassDirective('mars.macro.view',
+ ClassDirectiveContext())
+content_type = SingleTextDirective('mars.macro.content_type',
+ ClassDirectiveContext())
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.txt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.txt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,53 @@
+========================
+Mars Template Directives
+========================
+
+Directives specific to this package
+-----------------------------------
+
+* mars.macro.macro(name):
+ The name of the macro to be used. This allows us to reference
+ the named macro defined with metal:define-macro if we use a
+ different IMacroDirective name.
+
+* mars.macro.view(class_or_interface):
+ The view for which the macro should be used',
+ Default: IBrowserView
+
+* mars.macro.content_type(name):
+ The content type identifies the type of data.
+ Default: text/html
+
+Also the mars.layer directive may be used
+-----------------------------------------
+
+* mars.layer.layer(class_or_interface):
+ The layer for which the template should be available.
+ This directive can be used at module level
+ Default: zope.publisher.browser.interfaces.IDefaultBrowserLayer
+
+Relevant grok directives
+------------------------
+
+* grok.template(path):
+ This is used different to IGrokDirectives.template. It looks up the file
+ containing the page template using the path relative to the current module, if
+ not found it tries `path` as an absolute path, if not found GrokError is
+ raised. The file should end in extensions ``.pt`` or ``.html``.
+ **Required**
+
+* grok.name(name):
+ The macro name which this macro is registered for. The macro name can be the
+ same defined in metal:define-macro but does not have to be the same. If no
+ macro attribute is given the name is used as the name defined in
+ metal:define-macro. If you need to register a macro under a different name as
+ the defined one, you can use the macro attribute which have to reference the
+ metal.define-macro name. The TALES expression calls macros by this name and
+ returns the macro within the same name or with the name defined in the macro
+ attribute.
+ Default: or **Required**?
+
+* grok.context(class_or_interface):
+ The context for which the macro should be used. Usually should be
+ defined.
+ Default: zope.interface.Interface
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/directive.txt
___________________________________________________________________
Name: svn:keywords
+ Date Author
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/interfaces.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/interfaces.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/interfaces.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,23 @@
+import zope.interface
+
+class IMarsMacroDirectives(zope.interface.Interface):
+
+ def view(name):
+ """The name of the macro to be used. This allows us to reference
+ the named macro defined with metal:define-macro if we use a
+ different IMacroDirective name.
+ Default: empty
+ """
+
+ def macro(name):
+ """The name of the macro to be used. This allows us to reference
+ the named macro defined with metal:define-macro if we use a
+ different IMacroDirective name.
+ Default: empty
+ """
+
+ def content_type(name):
+ """The content type identifies the type of data.
+ Default: text/html
+ """
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/interfaces.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,64 @@
+import os
+
+import zope.component
+import zope.interface
+from zope.publisher.interfaces.browser import IBrowserView
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.pagetemplate.interfaces import IPageTemplate
+
+from z3c.macro.zcml import MacroFactory
+
+import martian
+from martian import util
+from martian.error import GrokError
+
+import grok
+from grok.util import check_adapts
+
+import mars.macro
+
+# TODO raise errors if anything missing?
+class MacroFactoryGrokker(martian.ClassGrokker):
+ component_class = mars.macro.MacroFactory
+
+ def grok(self, name, factory, context, module_info, templates):
+
+ view_context = util.determine_class_context(factory, context)
+
+ factory.module_info = module_info
+ factory_name = factory.__name__.lower()
+
+ # we need a path to the file containing the template
+ template_name = util.class_annotation(factory, 'grok.template',
+ factory_name)
+ filepath = os.path.join(os.path.dirname(module_info.path), template_name)
+ if not os.path.exists(filepath):
+ filepath = None
+ if os.path.exists(template_name):
+ 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"
+ % (factory.__name__),
+ factory)
+
+ contentType = util.class_annotation(factory,
+ 'mars.macro.content_type', 'text/html')
+ view_layer = util.class_annotation(factory, 'mars.layer.layer',
+ None) or module_info.getAnnotation('mars.layer.layer',
+ None) or IDefaultBrowserLayer
+
+ view_name = util.class_annotation(factory, 'grok.name', factory_name)
+ macro = util.class_annotation(factory, 'mars.macro.macro', view_name)
+ view = util.class_annotation(factory, 'mars.macro.view', IBrowserView)
+
+ factory = MacroFactory(filepath, macro, contentType)
+ #print '\nname:', view_name,'context:', view_context,'factory:', factory, '\n'
+ zope.component.provideAdapter(factory,
+ adapts=(view_context, view, view_layer),
+ provides=IMacroTemplate,
+ name=view_name)
+ return True
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.zcml (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/meta.zcml 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,2 @@
+<grok package=".meta" xmlns="http://namespaces.zope.org/grok" />
+
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/__init__.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/__init__.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/__init__.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1 @@
+#
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/directive.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/directive.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,15 @@
+"""
+Test the claimed directives.
+
+ >>> import grok
+ >>> grok.grok('mars.macro.tests.directive')
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+
+"""
+
+import grok
+import mars.macro
+
Property changes on: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/ftesting.zcml (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/ftesting.zcml 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,18 @@
+<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="z3c.layer.minimal.tests" file="ftesting.zcml" />
+
+ <include package="grok" />
+
+</configure>
+
+
Added: grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/test_all.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/test_all.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.macro/src/mars/macro/tests/test_all.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -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.macro.tests.%s'
+ for name in ['directive']:
+ 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.macro/src/mars/macro/tests/test_all.py
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: grok/branches/darrylcousins-branch/mars.template/src/mars/template/README.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/README.txt 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/README.txt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -11,4 +11,30 @@
This package uses martian to configure z3c.template based templates.
+Example Code
+------------
+::
+
+ class View(grok.View):
+
+ def render(self):
+ template = zope.component.getMultiAdapter(
+ (self, self.request), IPageTemplate)
+ return template(self)
+
+ class ViewTemplate(mars.template.TemplateFactory):
+ grok.template('templates/macro.pt')
+ grok.context(View)
+ mars.template.macro('mymacro')
+
+Directives
+----------
+
+Please see ``directive.txt``.
+
+Tests
+-----
+
+See test directory.
+
Modified: grok/branches/darrylcousins-branch/mars.template/src/mars/template/directive.txt
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/directive.txt 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/directive.txt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -25,6 +25,7 @@
* mars.layer.layer(class_or_interface):
The layer for which the template should be available.
+ This directive can be used at module level
Default: zope.publisher.browser.interfaces.IDefaultBrowserLayer
Relevant grok directives
@@ -42,7 +43,8 @@
Default: empty string
* grok.context(class_or_interface):
- The view for which the template should be available.
+ The view for which the template should be available. Usually should be
+ defined.
Default: module context
* grok.provides(interface):
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-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/meta.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -3,6 +3,7 @@
import zope.component
import zope.interface
from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.pagetemplate.interfaces import IPageTemplate
from z3c.template.template import TemplateFactory
@@ -26,22 +27,20 @@
factory.module_info = module_info
factory_name = factory.__name__.lower()
+ # we need a path to the file containing the template
template_name = util.class_annotation(factory, 'grok.template',
factory_name)
- template = templates.get(template_name)
- if not template:
- raise GrokError("No template found for %r. Please define a template"
- "to use."
- % (factory),
- factory)
- if factory_name != template_name:
- # grok.template is being used
- if templates.get(factory_name):
- raise GrokError("Multiple possible templates for template %r. It "
- "uses grok.template('%s'), but there is also "
- "a template called '%s'."
- % (factory, template_name, factory_name),
- factory)
+ filepath = os.path.join(os.path.dirname(module_info.path), template_name)
+ if not os.path.exists(filepath):
+ filepath = None
+ if os.path.exists(template_name):
+ 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"
+ % (factory.__name__),
+ factory)
provides = util.class_annotation(factory, 'grok.provides', self.provides)
macro = util.class_annotation(factory, 'mars.template.macro', None)
@@ -49,20 +48,12 @@
'mars.template.content_type', 'text/html')
view_layer = util.class_annotation(factory, 'mars.layer.layer',
None) or module_info.getAnnotation('mars.layer.layer',
- None) or IBrowserRequest
+ None) or IDefaultBrowserLayer
view_name = util.class_annotation(factory, 'grok.name', '')
-
- filename = template.__grok_location__
- if not os.path.exists(filename):
- raise GrokError("Inline templates are not supported for %s."
- " Please drop a tempate named %s in %s_templates."
- % (factory.__name__, factory_name, factory.module_info.name),
- factory)
- factory = TemplateFactory(filename, contentType, macro)
- templates.markAssociated(template_name)
+ factory = TemplateFactory(filepath, contentType, macro)
zope.interface.directlyProvides(factory, provides)
- print '\nname:', view_name,'context:', view_context,'factory:', factory, '\n'
+ #print '\nname:', view_name,'context:', view_context,'factory:', factory, '\n'
zope.component.provideAdapter(factory,
adapts=(view_context, view_layer),
provides=provides,
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/directive.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/directive.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/directive.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,70 @@
+"""
+Run through and test the available directives to template factories.
+
+ >>> import grok
+ >>> from mars.template.tests.directive import Mammoth
+ >>> grok.grok('mars.template.tests.directive')
+
+ >>> mammoth = getRootFolder()["mammoth"] = Mammoth()
+
+Layout views have a call method (TemplateViews do not necessarily) so we will
+use testbrowser.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+
+ >>> #browser.open("http://localhost/++skin++myskin/mammoth/@@view")
+ >>> browser.open("http://localhost/mammoth/@@view")
+ >>> print browser.contents
+ <body>
+ <div>Rendered content</div>
+ </body>
+
+"""
+# TODO add layer directive, when you have a view grokker to use
+
+
+import zope.component
+import zope.interface
+
+from z3c.template.interfaces import ILayoutTemplate
+
+import grok
+from grok.interfaces import IGrokView
+
+import mars.template
+import mars.layer
+
+class IMyLayer(mars.layer.IMinimalLayer):
+ pass
+
+class MySkin(mars.layer.Skin):
+ mars.layer.layer(IMyLayer)
+
+class IMyPageTemplate(zope.interface.Interface):
+ pass
+
+class Mammoth(grok.Model):
+ pass
+
+class View(grok.View):
+
+ def __call__(self):
+ template = zope.component.getMultiAdapter(
+ (self, self.request), IMyPageTemplate, name='complex')
+ return template(self)
+
+ def render(self):
+ return u'Rendered content'
+
+class ViewLayout(mars.template.LayoutFactory):
+ grok.template('templates/complex.pt') # required
+ grok.context(View) # define the adapted view
+ grok.name('complex') # view must use named adapter lookup
+ grok.provides(IMyPageTemplate) # view must use this interface to lookup
+ mars.template.macro('body') # define the macro to use
+ mars.template.content_type('text/html') # define the contentType
+ #mars.layer.layer(IMyLayer) # registered on this layer.
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/directive.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/layout.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/layout.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/layout.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,89 @@
+"""
+LayoutFactories allow use to define page templates in python code.
+
+ >>> import grok
+ >>> from mars.template.tests.layout import Mammoth
+ >>> grok.grok('mars.template.tests.layout')
+
+ >>> mammoth = getRootFolder()["mammoth"] = Mammoth()
+
+Layout views have a call method (TemplateViews do not necessarily) so we will
+use testbrowser.
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.handleErrors = False
+
+ >>> browser.open("http://localhost/mammoth/@@view")
+ >>> print browser.contents
+ <div>View template</div>
+
+Like TemplateFactories, LayoutFactories also support a `macro` directive (see z3c.template).
+
+ >>> browser.open("http://localhost/mammoth/@@macro")
+ >>> print browser.contents
+ <div>This is within the mymacro macro</div>
+
+And also allow the setting of the contentType. But I haven't got that to render yet.
+
+ >>> import zope.component
+ >>> from z3c.template.interfaces import ILayoutTemplate
+ >>> from mars.template.tests.layout import PlainText
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> plaintext = PlainText(mammoth, request)
+ >>> template = zope.component.getMultiAdapter(
+ ... (plaintext, request), ILayoutTemplate)
+ >>> print template.content_type
+ text/plain
+
+"""
+
+import zope.component
+
+from z3c.template.interfaces import ILayoutTemplate
+
+import grok
+
+import mars.template
+
+class Mammoth(grok.Model):
+ pass
+
+class LayoutView(grok.View):
+
+ def __call__(self):
+ template = zope.component.getMultiAdapter(
+ (self, self.request), ILayoutTemplate)
+ return template(self)
+
+ def render(self):
+ pass
+
+class View(LayoutView):
+ pass
+
+class ViewLayout(mars.template.LayoutFactory):
+ grok.template('templates/view.pt')
+ grok.context(View) # this is template for View
+
+class Macro(LayoutView):
+ pass
+
+class MacroLayout(mars.template.LayoutFactory):
+ grok.template('templates/macro.pt')
+ grok.context(Macro)
+ mars.template.macro('mymacro')
+
+class PlainText(LayoutView):
+ pass
+
+class PlainTextLayout(mars.template.LayoutFactory):
+ grok.template('templates/plain.pt')
+ grok.context(PlainText)
+ mars.template.content_type('text/plain')
+
+
+
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/layout.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/minimal-ftesting.zcml
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/minimal-ftesting.zcml (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/minimal-ftesting.zcml 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,16 @@
+<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="z3c.layer.minimal.tests" file="ftesting.zcml" />
+
+ <include package="grok" />
+
+</configure>
+
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/template.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/template.py (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/template.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,86 @@
+"""
+TemplateFactories allow use to define page templates in python code.
+
+ >>> import grok
+ >>> from mars.template.tests.template import Mammoth
+ >>> grok.grok('mars.template.tests.template')
+
+ >>> mammoth = Mammoth()
+ >>> import zope.component
+ >>> from zope.pagetemplate.interfaces import IPageTemplate
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest()
+ >>> from mars.template.tests.template import View
+ >>> view = View(mammoth, request)
+
+The template can then be looked up for the object that it is registered for
+using grok.context.
+
+ >>> template = zope.component.getMultiAdapter(
+ ... (view, request), IPageTemplate)
+ >>> print template
+ <zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object at ...>
+
+ >>> print view.render()
+ <div>View template</div>
+
+TemplateFactories support a `macro` directive (see z3c.template).
+
+ >>> from mars.template.tests.template import Macro
+ >>> macro = Macro(mammoth, request)
+ >>> print macro.render()
+ <div>This is within the mymacro macro</div>
+
+TemplateFactories also allow the setting of the contentType.
+
+ >>> from mars.template.tests.template import PlainText
+ >>> plaintext = PlainText(mammoth, request)
+ >>> template = zope.component.getMultiAdapter(
+ ... (plaintext, request), IPageTemplate)
+ >>> print template.content_type
+ text/plain
+
+"""
+
+import zope.component
+from zope.pagetemplate.interfaces import IPageTemplate
+
+import grok
+
+import mars.template
+
+class Mammoth(grok.Model):
+ pass
+
+class TemplateView(grok.View):
+
+ def render(self):
+ template = zope.component.getMultiAdapter(
+ (self, self.request), IPageTemplate)
+ return template(self)
+
+class View(TemplateView):
+ pass
+
+class ViewTemplate(mars.template.TemplateFactory):
+ grok.template('templates/view.pt')
+ grok.context(View) # this is template for View
+
+class Macro(TemplateView):
+ pass
+
+class MacroTemplate(mars.template.TemplateFactory):
+ grok.template('templates/macro.pt')
+ grok.context(Macro)
+ mars.template.macro('mymacro')
+
+class PlainText(TemplateView):
+ pass
+
+class PlainTextTemplate(mars.template.TemplateFactory):
+ grok.template('templates/plain.pt')
+ grok.context(PlainText)
+ mars.template.content_type('text/plain')
+
+
+
Property changes on: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/template.py
___________________________________________________________________
Name: svn:keywords
+ Id
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/complex.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/complex.pt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/complex.pt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,5 @@
+<html>
+<body metal:define-macro="body">
+<div tal:content="view/render" />
+</body>
+</html>
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/macro.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/macro.pt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/macro.pt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1,4 @@
+<div>This won't be rendered</div>
+<div metal:define-macro="mymacro">This is within the mymacro macro</div>
+<div>This won't be rendered</div>
+
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/plain.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/plain.pt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/plain.pt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1 @@
+Plain text
Added: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/view.pt
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/view.pt (rev 0)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/templates/view.pt 2007-07-04 09:29:32 UTC (rev 77392)
@@ -0,0 +1 @@
+<div>View template</div>
Modified: grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/test_all.py
===================================================================
--- grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/test_all.py 2007-07-04 07:42:43 UTC (rev 77391)
+++ grok/branches/darrylcousins-branch/mars.template/src/mars/template/tests/test_all.py 2007-07-04 09:29:32 UTC (rev 77392)
@@ -8,28 +8,21 @@
from martian.tests.test_all import globs, optionflags
functional.defineLayer('TestLayer', 'ftesting.zcml')
+functional.defineLayer('TestMinimalLayer', 'minimal-ftesting.zcml')
-def suiteFromPackage(name):
- files = resource_listdir(__name__, name)
+def test_suite():
suite = unittest.TestSuite()
- for filename in files:
- if not filename.endswith('.py'):
- continue
- if filename == '__init__.py':
- continue
- if filename == 'test_all.py':
- continue
+ dottedname = 'mars.template.tests.%s'
- dottedname = 'mars.template.tests.%s' % (filename[:-3])
- test = FunctionalDocTestSuite(dottedname)
+ for name in ['template', 'layout']:
+ test = FunctionalDocTestSuite(dottedname % name)
test.layer = TestLayer
-
suite.addTest(test)
- return suite
-def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(suiteFromPackage('.'))
+ test = FunctionalDocTestSuite(dottedname % 'directive')
+ test.layer = TestMinimalLayer
+ suite.addTest(test)
+
return suite
More information about the Checkins
mailing list