makoto kuwata wrote:
> Hi all,
> please give me a change to introduce Tenjin template engine.
> http://www.kuwata-lab.com/tenjin/
> 
> Tenjin is a very fast and powerful template engine.
> It allows you to embed any Python code in template file.
> Tenjin converts template file into Python script and evaluate it.
> I believe that Tenjin will fit web.py because it is small and
> lightweight.
> 
> Features:
> * Tenjin is about
>   - ten times faster than Templetor (= web.py's template engine)
>   - three times faster than Cheetah
>   - nine times faster than Django
>   - sixty times faster than Kid
> * Tenjin supports
>   - layout template
>   - partial template
>   - capturing part of template
>   - template encoding
> 
> 
> Install:
> 
> $ wget http://downloads.sourceforge.net/tenjin/pytenjin-0.6.0.tar.gz
> $ tar xzf pytenjin-0.6.0.tar.gz
> $ cd pytenjin-0.6.0/
> $ sudo python setup.py install
> 
> 
> Example:
> 
> templates/layout.pyhtml:
> --------------------
> <html>
>   <head>
>     <title>${title}</title>
>     <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8">
>   </head>
>   <body>
>     <h1>${title}</h1>
>     <div id="maincontent">
> #{_content}
>     </div>
> <?py include(':footer') ?>
>   </body>
> </html>
> --------------------
> 
> templates/item_list.pyhtml:
> --------------------
> <table>
> <?py i = 0 ?>
> <?py for item in items: ?>
> <?py     i += 1 ?>
> <?py     color = i % 2 and '#FFCCCC' or '#CCCCFF' ?>
>   <tr bgcolor="#{color}">
>     <td>#{i}</td>
>     <td>${item}</td>
>   </tr>
> <?py #endfor ?>
> </table>
> --------------------
> 
> templates/footer.pyhtml:
> --------------------
> <hr>
> <address>
>  <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
> </address>
> --------------------
> 
> main.py:
> --------------------
> import tenjin
> from tenjin.helpers import escape, to_str
> engine = tenjin.Engine(postfix='.pyhtml', path=['templates'],
>                        layout=':layout', cache=True)
> context = { 'title':'Example', 'items':['<AAA>','B&B','"CCC"'] }
> #web.header('Content-Type', 'text/html; charset=UTF-8')
> print engine.render(':item_list', context),
> --------------------
> 
> output:
> --------------------
> <html>
>   <head>
>     <title>Example</title>
>     <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8">
>   </head>
>   <body>
>     <h1>Example</h1>
>     <div id="maincontent">
> <table>
>   <tr bgcolor="#FFCCCC">
>     <td>1</td>
>     <td>&lt;AAA&gt;</td>
>   </tr>
>   <tr bgcolor="#CCCCFF">
>     <td>2</td>
>     <td>B&amp;B</td>
>   </tr>
>   <tr bgcolor="#FFCCCC">
>     <td>3</td>
>     <td>&quot;CCC&quot;</td>
>   </tr>
> </table>
> 
>     </div>
> <hr>
> <address>
>  <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
> </address>
>   </body>
> </html>
> --------------------
> 
> Tenjin has features which Templetor doesn't have yet.
> If you want faster and more powerful template engine than Templetor,
> try Tenjin.
> http://www.kuwata-lab.com/tenjin/
> 
> --
> makoto kuwata

Alright, I have a few comments on this thread (including some of the
replies). Let me start with the fundamental one:

In above e-mail you claim a lot of things concerning "speed". The way I
learned it; every, and I mean *every* such claim must be backed up by a
/significant/ amount of data to be at the very least credible. "About
ten times faster than Templetor" does not tell me anything, not anything
at all. I could write a specific PHP script that was optimized to be
dealt with cleanly be the Zend engine, write a crappy C equivalent that
is far from efficient and claim that "PHP is about as fast as C".

I do not know about the others on this mailing list, but when I read
these kind of things I want to know more:
- how did you test this?
- how did you benchmark? what program did you use for benchmarking?
- how often did you test this? (this is probably the most important one)
- which templates did you compare?
- what other programs were running while you ran the tests?
- what are the /exact/ results of your tests?

Those are just a few things that come to mind. Basically, if the tests
are not reproducible the results are worth pretty much nothing.

Anyhow, assuming that it truly is ten times faster than templetor, on
average. This leaves the issue that Tzury pointed out; its syntax. When
he said "the zen of python" he referred to Tim Peters' "The Zen of
Python" [1] (this has become some sort of an unspoken python rule over
the years). At least, that's what I assume he was talking about... One
of the important points mentioned in the zen of python is the first one;
"beautiful is better than ugly". I hate to include subjective arguments
in discussions like these but I have to say this: Tenjin's syntax is
just ugly. <?py, ?>, $, {, #, it all clutters the template. It makes it
hard to read and (most importantly) harder to distinguish the template
language from the actual HTML (or whatever you are writing). While I
agree that there are advantages to such a syntax you must keep in mind
that simplicity is probably the most important thing about web.py; it's
what it is all about. You simply can not take simplicity away from the
web.py without killing it. At least, that is how I see it.

This makes me wonder if maybe it is possible to merge the two...? If
Tenjin really is faster, how about incorporating some if its logic,
where possible, into the templetor engine, while keeping templetor's
syntax? That could produce interesting results :)

Anyway, I hope I have not offended you too much in saying this. I would
love to hear your thoughts on the matter.

Thanks for taking the time to tell us about Tenjin and doing the
benchmarks and the comparisons.


Greetings,

b^4

P.S.: What Anand meant by allowing untrusted users to write templates
was that with templetor you can create a "template sandbox", preventing
people from accessing restricted areas and calling prohibited
procedures. Enforcing resource-limitation is still up to the programmer
(for example: make a thread, start it, wait a number of seconds and if
it's not done kill it). There is a difference between a simple DOS and
an actual security vulnerability that allows remote exploitation of a
system.

P.P.S.: Anand, Tzury, I have been so bold to make some, perhaps
erroneous, assumptions about what you were trying to say; please forgive
me if I mistakenly misinterpreted your messages.

[1] http://www.python.org/doc/Humor.html#zen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to