[Checkins] SVN: megrok.chameleon/branches/ulif-z3c.pt-less/src/megrok/chameleon/README.txt Update docs, fix typos.
Uli Fouquet
uli at gnufix.de
Wed Mar 3 05:35:41 EST 2010
Log message for revision 109594:
Update docs, fix typos.
Changed:
U megrok.chameleon/branches/ulif-z3c.pt-less/src/megrok/chameleon/README.txt
-=-
Modified: megrok.chameleon/branches/ulif-z3c.pt-less/src/megrok/chameleon/README.txt
===================================================================
--- megrok.chameleon/branches/ulif-z3c.pt-less/src/megrok/chameleon/README.txt 2010-03-03 10:16:43 UTC (rev 109593)
+++ megrok.chameleon/branches/ulif-z3c.pt-less/src/megrok/chameleon/README.txt 2010-03-03 10:35:41 UTC (rev 109594)
@@ -6,7 +6,7 @@
:Test-Layer: functional
With `megrok.chameleon` you can use templates parsed and rendered by
-`chameleon`. Currently Zope page templates and Genshi templates are
+`Chameleon`_. Currently Zope page templates and Genshi templates are
supported.
Chameleon Zope page templates
@@ -31,15 +31,15 @@
Beside this, most rules for regular Zope page templates apply also to
chameleon page templates.
-See the `chameleon.zpt`_ page for more information.
+See the `Chameleon`_ page for more information.
-.. _chameleon.zpt: http://pypi.python.org/pypi/chameleon.zpt
+.. _Chameleon: http://chameleon.repoze.org/docs/latest/zpt.html
Prerequisites
-------------
Before we can see the templates in action, we care for correct
-registration and set some used variables::
+registration and set some used variables:
>>> import os
>>> testdir = os.path.join(os.path.dirname(__file__), 'tests')
@@ -48,7 +48,7 @@
We register everything. Before we can grok our fixture, we have to
grok the `megrok.chameleon` package. This way the new template types
-are registered with the framework::
+are registered with the framework:
>>> import grokcore.view
>>> grokcore.view.testing.grok('megrok.chameleon')
@@ -62,7 +62,7 @@
>>> manfred = Mammoth()
>>> getRootFolder()['manfred'] = manfred
-Furthermore we prepare for getting the different views on manfred::
+Furthermore we prepare for getting the different views on manfred:
>>> from zope.publisher.browser import TestRequest
>>> from zope.component import getMultiAdapter
@@ -71,7 +71,7 @@
Simple templates
----------------
-We prepared a plain cavepainting view. The template looks like this::
+We prepared a plain cavepainting view. The template looks like this:
>>> cavepainting_cpt = os.path.join(template_dir, 'cavepainting.cpt')
>>> print open(cavepainting_cpt, 'rb').read()
@@ -81,7 +81,7 @@
</body>
</html>
-The rendered view looks like this::
+The rendered view looks like this:
>>> view = getMultiAdapter((manfred, request),
... name='cavepainting')
@@ -97,7 +97,7 @@
A template can access variables like ``view``, ``context`` and its
methods and attributes. The ``food`` view does exactly this. The
-template looks like this::
+template looks like this:
>>> food_cpt = os.path.join(template_dir, 'food.cpt')
>>> print open(food_cpt, 'rb').read()
@@ -114,7 +114,7 @@
</body>
</html>
-The rendered view looks like this::
+The rendered view looks like this:
>>> view = getMultiAdapter((manfred, request), name='food')
>>> print view()
@@ -174,7 +174,7 @@
* ``static``
the static dir of the application
-as we can see, when we look at the ``vars.cpt`` from our fixture::
+as we can see, when we look at the ``vars.cpt`` from our fixture:
>>> cpt_file = os.path.join(template_dir, 'vars.cpt')
>>> print open(cpt_file, 'rb').read()
@@ -199,7 +199,7 @@
</body>
</html>
-and render it::
+and render it:
>>> view = getMultiAdapter((manfred, request), name='vars')
>>> print view()
@@ -244,7 +244,7 @@
inline = components.ChameleonPageTemplate(
"<html><body>ME GROK HAS INLINES! ${view.sometext}</body></html>")
-If we render this view we get::
+If we render this view we get:
>>> view = getMultiAdapter((manfred, request), name='inline')
>>> print view()
@@ -253,31 +253,33 @@
TAL expressions
---------------
+Starting with ``megrok.chameleon`` 0.5 we deploy the all-in-one
+`Chameleon`_ package.
+
What TAL/TALES expressions in templates are supported depends mainly
-from the installed version of `chameleon.zpt`.
+from the installed version of `Chameleon`, while we support some
+additional, Zope-related TALES expressions.
A list of all supported expressions and statements can be found at the
-`chameleon.zpt documentation <http://chameleon.repoze.org/docs/zpt/>`_.
+`chameleon.zpt documentation
+<http://chameleon.repoze.org/docs/latest/zpt.html>`_. The additional
+TALES expressions provided by ``megrok.chameleon`` are:
-Furthermore `megrok.chameleon` currently comes with support for
-`z3c.pt`, a package that supports the more Zope specific expressions
-often used in page templates.
+* ``exists``
+ Tell whether a name exists in the templates' namespace.
-These include, for instance, support for viewlets, etc. The set of
-additional language constructs supported with this package can be seen
-at the `z3c.pt documentation
-<http://chameleon.repoze.org/docs/z3c/>`_. Please note, that
-`megrok.chameleon` templates (a.k.a. CPT templates), different to
-`z3c.pt` still use Python expressions by default.
+* ``not``
+ Evaluate the trailing expression to a boolean value and invert it.
-.. warning:: `z3c.pt` support might be factored out in future.
+* ``path``
+ Handle the trailing expression as a path and not as a
+ Python expression.
- While it is nice to have support for all the additional expressions
- provided by `z3c.pt`, using this package means a lot of more
- dependencies which might be unwanted in certain cases.
+* ``provider``
+ Support for viewlet providers.
- We therefore think about factoring additional z3c.pt support out to
- a separate package in not too far future.
+.. warning:: `z3c.pt` support has been dropped with
+ ``megrok.chameleon`` 0.5.
In our ``app.py`` we defined a special view for showing some special
expressions. This also includes a viewlet::
@@ -302,25 +304,10 @@
def render(self):
return 'Hello from viewlet'
+Now we can make use of the TALES expressions ``not:``, ``path:``,
+``exists:`` and ``provider:`` in the ``expressions.cpt`` template of
+our fixture:
-At least the following TAL/TALES expressions are supported by time of
-writing this:
-
-* ``exists``
- Tell whether a name exists in the templates' namespace.
-
-* ``not``
- Evaluate the trailing expression to a boolean value and invert it.
-
-* ``path``
- Handle the trailing expression as a path and not as a
- Python expression.
-
-* ``provider``
- Support for viewlet providers.
-
-as we can see, when we look at the ``expressions.cpt`` from our fixture::
-
>>> cpt_file = os.path.join(template_dir, 'expressions.cpt')
>>> print open(cpt_file, 'rb').read()
<html>
@@ -348,7 +335,7 @@
</body>
</html>
-and render it::
+and render it:
>>> view = getMultiAdapter((manfred, request), name='expressions')
>>> print view()
@@ -462,7 +449,7 @@
</html>
-Clean up::
+Clean up:
>>> del getRootFolder()['manfred']
@@ -472,11 +459,16 @@
* Macros are referenced differently. See appropriate section above.
+* Expressions are parsed in ``Python-mode`` by default. This means,
+ instead of ``tal:content="view/value"`` you must use
+ ``tal:content="view.value"``. Every occurence of TAL-expressions
+ starting with ``python:`` now can be shortened by skipping this
+ marker.
Chameleon Genshi templates
==========================
-Chameleon provides supprt for Genshi templates which can be used from
+Chameleon provides support for Genshi templates which can be used from
grok writing templates with the ``.cg`` filename extension.
Genshi text templates can be used with the ``.cgt`` filename
@@ -495,7 +487,7 @@
-------------
Before we can see the templates in action, we care for correct
-registration and set some used variables::
+registration and set some used variables:
>>> import os
>>> testdir = os.path.join(os.path.dirname(__file__), 'tests')
@@ -504,19 +496,19 @@
We register everything. Before we can grok our fixture, we have to
grok the `megrok.chameleon` package. This way the new template types
-are registered with the framework::
+are registered with the framework:
>>> grokcore.view.testing.grok('megrok.chameleon')
>>> grokcore.view.testing.grok('megrok.chameleon.tests.genshi_fixture')
We create a mammoth, which should provide us a bunch of Genshi driven
-views and put it in the database to setup location info::
+views and put it in the database to setup location info:
>>> from megrok.chameleon.tests.genshi_fixture.app import Mammoth
>>> manfred = Mammoth()
>>> getRootFolder()['manfred'] = manfred
-Furthermore we prepare for getting the different views on manfred::
+Furthermore we prepare for getting the different views on manfred:
>>> from zope.publisher.browser import TestRequest
>>> from zope.component import getMultiAdapter
@@ -526,7 +518,7 @@
Simple templates
----------------
-We prepared a plain cavepainting view. The template looks like this::
+We prepared a plain cavepainting view. The template looks like this:
>>> cavepainting_cg = os.path.join(template_dir, 'cavepainting.cg')
>>> print open(cavepainting_cg, 'rb').read()
@@ -536,7 +528,7 @@
</body>
</html>
-The rendered view looks like this::
+The rendered view looks like this:
>>> view = getMultiAdapter((manfred, request),
... name='cavepainting')
@@ -553,7 +545,7 @@
A template can access variables like ``view``, ``context`` and its
methods and attributes. The ``food`` view does exactly this. The
-template looks like this::
+template looks like this:
>>> food_cg = os.path.join(template_dir, 'food.cg')
>>> print open(food_cg, 'rb').read()
@@ -565,7 +557,7 @@
</body>
</html>
-The rendered view looks like this::
+The rendered view looks like this:
>>> view = getMultiAdapter((manfred, request), name='food')
>>> print view()
@@ -582,7 +574,7 @@
-------------------------
With genshi support we can also include other templates. The
-``gatherer`` view looks like this::
+``gatherer`` view looks like this:
>>> gatherer_cg = os.path.join(template_dir, 'gatherer.cg')
>>> print open(gatherer_cg, 'rb').read()
@@ -594,14 +586,14 @@
</html>
Apparently here we include a template called ``berries.cg``. It looks
-like this::
+like this:
>>> berries_cg = os.path.join(template_dir, 'berries.cg')
>>> print open(berries_cg, 'rb').read()
<strong>Lovely blueberries!</strong>
-When we render the former template, we get::
+When we render the former template, we get:
>>> view = getMultiAdapter((manfred, request), name='gatherer')
>>> print view()
@@ -616,7 +608,7 @@
--------------
Also genshi text templates are supported. We have a template that
-looks like so::
+looks like so:
>>> hunter_cgt = os.path.join(template_dir, 'hunter.cgt')
>>> print open(hunter_cgt, 'rb').read()
@@ -625,7 +617,7 @@
Note, that this template has the ``.cgt`` (= **c**\ ameleon **g**\ enshi
**t**\ ext template) file extension.
-If we render it, all expressions are substituted::
+If we render it, all expressions are substituted:
>>> view = getMultiAdapter((manfred, request), name='hunter')
>>> print view()
More information about the checkins
mailing list