[Grok-dev] megrok.chameleon template engine

Uli Fouquet uli at gnufix.de
Sun Feb 22 14:02:40 EST 2009


Wichert Akkerman wrote:
> Previously Uli Fouquet wrote:
> > It provides support for chameleon-driven Zope page templates and also
> > for Genshi templates. Chameleon is the template engine also used by
> > repoze.bft and it (chameleon) is said to be faster than regular Zope
> > page templates.
> 
> By a factor of 12 currently if I remember correctly.

Hm, currently I cannot reproduce such speedup. Maybe my implementation
is really bad or we have a more general problem with template-handling
in Grok/Zope.

> > Note, that the package only works with Python2.5 (due to chameleon uses
> > Python2.5 expressions)!
> 
> Both chameleon.zpt and chameleon.genshi work fine with python 2.4, so I
> do not understand where this claim comes from.

Looks like I was fooled by some erromessages like this::

  ...
  Got chameleon.core 1.0b19.
  Getting distribution for 'sourcecodegen>=0.6.5'.
    File "build/bdist.linux-i686/egg/sourcecodegen/tests/py25plus.py",  
    line 13
      finally:
            ^
  SyntaxError: invalid syntax
  File 
 "/.../sourcecodegen-0.6.5-py2.4.egg/sourcecodegen/tests/py25plus.py",  
  line 13
      finally:
              ^
  SyntaxError: invalid syntax
  Got sourcecodegen 0.6.5.

And with a ubuntu standard python2.4 (with `python-lxml` installed) I
additionally get segmentation faults under 2.4. That's where this claim
comes from, but maybe it is `sourcecodegen`, which is to blame and:

In a clean virtualenv, however, the package builds correctly and all
tests pass. So for the logs: you can use `megrok.chameleon` also with
Python2.4.

> > `megrok.chameleon` registers the following new template filename
> > extensions:
> > 
> > * `.cpt`: Chameleon Page Template
> > 
> >   Those templates behave similar to regular Zope page templates 
> >   (.pt-files) but use Python expressions by default and support 
> >   Genshi-like variable substitutions. So you do not write::
> > 
> >       tal:replace='view/somevalue'
> > 
> >   anymore but instead::
> > 
> >       ${view.somevalue}
> 
> You can still use tal:replace as well of course: you can freely use both
> forms in the same file.

Yes, of course. But if you do, be aware, that your expression will be
evaluated as a Python-expression. So

   tal:replace='view/somevalue'

will _not_ work, while

   tal:replace='view.somevalue'

will.

You can also use macros and all that ZPT stuff. Please see the
`chameleon.zpt` description,

  http://pypi.python.org/pypi/chameleon.zpt

as `megrok.chameleon` only transfers its functionality into a grokked
environment.

Best regards,

-- 
Uli

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20090222/8383e515/attachment.bin 


More information about the Grok-dev mailing list