[Checkins] SVN: z3c.pt/trunk/src/z3c/pt/ These are functional tests for the template classes and should be labelled as such.

Malthe Borch mborch at gmail.com
Sat Aug 9 10:31:00 EDT 2008


Log message for revision 89574:
  These are functional tests for the template classes and should be labelled as such.

Changed:
  D   z3c.pt/trunk/src/z3c/pt/README.txt
  A   z3c.pt/trunk/src/z3c/pt/template.txt
  U   z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py

-=-
Deleted: z3c.pt/trunk/src/z3c/pt/README.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/README.txt	2008-08-09 13:01:51 UTC (rev 89573)
+++ z3c.pt/trunk/src/z3c/pt/README.txt	2008-08-09 14:30:59 UTC (rev 89574)
@@ -1,181 +0,0 @@
-z3c.pt
-======
-
-This document demonstrates the high-level API of the package including
-error handling.
-
-
-Overview
---------
-
-Two types of TAL page template classes are provided:
-
-``PageTemplate``, ``PageTemplateFile``
-       These classes allow passing of arguments directly to the
-       template namespace.
-
-``ViewPageTemplate``, ``ViewPageTemplateFile``
-       These classes should be initialized as properties in a
-       view class and provide a set of default arguments to the
-       template.
-
-Templates structured as plain text are supported:
-
-``TextTemplate``, ``TextTemplateFile``
-       These classes work like their page template counterparts,
-       except they work with plain text documents, extending
-       to CSS stylesheets, javascript files and other non-XML
-       document. Only expression interpolation is supported.
-
-``ViewTextTemplate``, ``ViewTextTemplateFile``
-       See above.
-
-       
-Page template classes
----------------------
-
-Initialized with a string:
-
-  >>> from z3c.pt import PageTemplate
-  >>> template = PageTemplate("""\
-  ... <div xmlns="http://www.w3.org/1999/xhtml"
-  ...      xmlns:tal="http://xml.zope.org/namespaces/tal"
-  ...      xmlns:py="http://genshi.edgewall.org">
-  ...   <py:match path="xmlns:greeting">Hello ${select('@name')[0]}!</py:match>
-  ...   <greeting name="World" />
-  ... </div>
-  ... """)
-
-  >>> print template()
-  <div>
-    Hello World!
-  <BLANKLINE>
-  </div>
-
-Providing the path to a template file:
-
-  >>> from z3c.pt import PageTemplateFile
-  >>> from z3c.pt import tests
-  >>> path = tests.__path__[0]
-  >>> template = PageTemplateFile(path+'/helloworld.pt')
-  >>> print template()
-  <div>
-    Hello World!
-  <BLANKLINE>
-  </div>
-
-Keyword-parameters are passed on to the template namespace as-is.
-
-
-View template classes
----------------------
-
-View template classes are provided for templates on the file system
-and for inline templates. The following symbols are defined for the
-template:
-
-* view
-* context
-* request
-* options
-
-Keyword-parameters are passed on to the template in a dictionary bound
-to the symbol ``options``.
-
-  >>> from z3c.pt import ViewPageTemplate, ViewPageTemplateFile
-  
-  >>> class ViewPageTemplateView(object):
-  ...     view_page_template_file = ViewPageTemplateFile(path+'/view.pt')
-  ...     view_page_template = ViewPageTemplate(open(path+'/view.pt').read())
-  ...     request = u'request'
-  ...     context = u'context'
-
-  >>> view = ViewPageTemplateView()
-
-File system:
-  
-  >>> print view.view_page_template_file(test=u'test')
-  <div>
-    <span>&lt;ViewPageTemplateView object at ...&gt;</span>
-    <span>context</span>
-    <span>request</span>
-    <span>test</span>
-  </div>
-
-Inline:
-  
-  >>> print view.view_page_template(test=u'test')
-  <div>
-    <span>&lt;ViewPageTemplateView object at ...&gt;</span>
-    <span>context</span>
-    <span>request</span>
-    <span>test</span>
-  </div>
-
-  
-Text template classes
----------------------
-
-  >>> from z3c.pt import ViewTextTemplate, ViewTextTemplateFile
-  
-  >>> class ViewTextTemplateView(object):
-  ...     view_text_template_file = ViewTextTemplateFile(path+'/view.css')
-  ...     view_text_template = ViewTextTemplate(open(path+'/view.css').read())
-  ...     request = u'request'
-  ...     context = u'context'
-
-  >>> view = ViewTextTemplateView()
-
-  >>> print view.view_text_template_file(color=u'#ccc')
-  #region {
-      background: #ccc;
-  }
-
-  >>> print view.view_text_template(color=u'#ccc')
-  #region {
-      background: #ccc;
-  }
-
-
-Error handling
---------------
-
-When an exception is raised which does not expose a bug in the TAL
-translation machinery, we expect the exception to contain the part of
-the template source that caused the exception.
-
-Exception while evaluating expression:
-
-  >>> from z3c.pt import PageTemplate
-  >>> PageTemplate("""\
-  ... <div xmlns="http://www.w3.org/1999/xhtml"
-  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
-  ...   <span tal:content="range()" />
-  ... </div>""").render()
-  Traceback (most recent call last):
-    ...
-  TypeError: range expected at least 1 arguments, got 0
-
-Exception while evaluating definition:
-
-  >>> from z3c.pt import PageTemplate
-  >>> PageTemplate("""\
-  ... <div xmlns="http://www.w3.org/1999/xhtml"
-  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
-  ...   <span tal:define="dummy range()" />
-  ... </div>""").render()
-  Traceback (most recent call last):
-    ...
-  TypeError: range expected at least 1 arguments, got 0
-
-Exception while evaluating interpolation:
-
-  >>> from z3c.pt import PageTemplate
-  >>> PageTemplate("""\
-  ... <div xmlns="http://www.w3.org/1999/xhtml"
-  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
-  ...   <span>${range()}</span>
-  ... </div>""").render()
-  Traceback (most recent call last):
-    ...
-  TypeError: range expected at least 1 arguments, got 0

Added: z3c.pt/trunk/src/z3c/pt/template.txt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.txt	                        (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/template.txt	2008-08-09 14:30:59 UTC (rev 89574)
@@ -0,0 +1,165 @@
+Template classes
+================
+
+This section demonstrates the high-level template classes.
+
+z3c.pt.pagetemplate.PageTemplate
+--------------------------------
+
+  >>> from z3c.pt import PageTemplate
+
+  >>> print PageTemplate("""\
+  ... <div xmlns="http://www.w3.org/1999/xhtml">
+  ...   Hello World!
+  ... </div>""")()
+  <div>
+    Hello World!
+  </div>
+
+z3c.pt.pagetemplate.PageTemplateFile
+------------------------------------
+
+  >>> from z3c.pt import PageTemplateFile
+  >>> from z3c.pt import tests
+  >>> path = tests.__path__[0]
+  >>> print PageTemplateFile(path+'/helloworld.pt')()
+  <div>
+    Hello World!
+  </div>
+
+z3c.pt.pagetemplate.ViewPageTemplate
+------------------------------------
+
+  >>> from z3c.pt import ViewPageTemplate
+  
+  >>> class ViewPageTemplateView(object):
+  ...     __call__ = ViewPageTemplate(open(path+'/view.pt').read())
+  ...     request = u'request'
+  ...     context = u'context'
+
+  >>> view = ViewPageTemplateView()
+    
+  >>> print view(test=u'test')
+  <div>
+    <span>&lt;ViewPageTemplateView object at ...&gt;</span>
+    <span>context</span>
+    <span>request</span>
+    <span>test</span>
+  </div>
+
+z3c.pt.pagetemplate.ViewPageTemplateFile
+----------------------------------------
+
+  >>> from z3c.pt import ViewPageTemplateFile
+  
+  >>> class ViewPageTemplateView(object):
+  ...     __call__ = ViewPageTemplateFile(path+'/view.pt')
+  ...     request = u'request'
+  ...     context = u'context'
+
+  >>> view = ViewPageTemplateView()
+
+  >>> print view(test=u'test')
+  <div>
+    <span>&lt;ViewPageTemplateView object at ...&gt;</span>
+    <span>context</span>
+    <span>request</span>
+    <span>test</span>
+  </div>
+
+z3c.pt.texttemplate.ViewTextTemplate
+------------------------------------
+
+  >>> from z3c.pt import ViewTextTemplate
+  
+  >>> class ViewTextTemplateView(object):
+  ...     __call__ = ViewTextTemplate(open(path+'/view.css').read())
+  ...     request = u'request'
+  ...     context = u'context'
+
+  >>> view = ViewTextTemplateView()
+
+  >>> print view(color=u'#ccc')
+  #region {
+      background: #ccc;
+  }
+
+z3c.pt.texttemplate.ViewTextTemplateFile
+----------------------------------------
+
+  >>> from z3c.pt import ViewTextTemplateFile
+  
+  >>> class ViewTextTemplateView(object):
+  ...     __call__ = ViewTextTemplateFile(path+'/view.css')
+  ...     request = u'request'
+  ...     context = u'context'
+
+  >>> view = ViewTextTemplateView()
+
+  >>> print view(color=u'#ccc')
+  #region {
+      background: #ccc;
+  }
+
+Compiler integration
+--------------------
+
+Certain constructs require close collaboration between the template
+compiler and the page template classes.
+
+py:match integration
+
+  >>> print PageTemplate("""\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:py="http://genshi.edgewall.org">
+  ...   <py:match path="xmlns:greeting">Hello ${select('@name')[0]}!</py:match>
+  ...   <greeting name="World" />
+  ... </div>
+  ... """)()
+  <div>
+    Hello World!
+  <BLANKLINE>
+  </div>
+
+Error handling
+--------------
+
+When an exception is raised which does not expose a bug in the TAL
+translation machinery, we expect the exception to contain the part of
+the template source that caused the exception.
+
+Exception while evaluating expression:
+
+  >>> from z3c.pt import PageTemplate
+  >>> PageTemplate("""\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
+  ...   <span tal:content="range()" />
+  ... </div>""").render()
+  Traceback (most recent call last):
+    ...
+  TypeError: range expected at least 1 arguments, got 0
+
+Exception while evaluating definition:
+
+  >>> from z3c.pt import PageTemplate
+  >>> PageTemplate("""\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
+  ...   <span tal:define="dummy range()" />
+  ... </div>""").render()
+  Traceback (most recent call last):
+    ...
+  TypeError: range expected at least 1 arguments, got 0
+
+Exception while evaluating interpolation:
+
+  >>> from z3c.pt import PageTemplate
+  >>> PageTemplate("""\
+  ... <div xmlns="http://www.w3.org/1999/xhtml"
+  ...      xmlns:tal="http://xml.zope.org/namespaces/tal">
+  ...   <span>${range()}</span>
+  ... </div>""").render()
+  Traceback (most recent call last):
+    ...
+  TypeError: range expected at least 1 arguments, got 0

Modified: z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py	2008-08-09 13:01:51 UTC (rev 89573)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_doctests.py	2008-08-09 14:30:59 UTC (rev 89574)
@@ -14,7 +14,7 @@
     zope.configuration.xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
 
 def test_suite():
-    filesuites = ('README.txt', 'translation.txt', 'i18n.txt', 'codegen.txt')
+    filesuites = ('template.txt', 'translation.txt', 'i18n.txt', 'codegen.txt')
     testsuites = ('z3c.pt.translation', 'z3c.pt.clauses', 'z3c.pt.expressions')
 
     return unittest.TestSuite(



More information about the Checkins mailing list