Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20535

ANN: pyTenjin 1.1.0 - a high-speed and full-featured template engine

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kwatch@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:ANN': 0.02; 'context': 0.04; 'lines.': 0.05; '(default': 0.07; 'pypy': 0.07; 'removes': 0.07; 'url:pypi': 0.08; 'python': 0.08; '-------': 0.09; 'i++)': 0.09; 'parameter.': 0.09; 'release.': 0.09; 'setup.py': 0.09; 'template.': 0.09; 'url:packages': 0.09; 'output': 0.10; '2.7': 0.13; '1.7': 0.16; '3.2.': 0.16; '\\n\\': 0.16; 'jython': 0.16; 'preprocessor': 0.16; 'skip:# 30': 0.16; 'subject:engine': 0.16; 'sudo': 0.16; 'url:tar': 0.16; '{})': 0.16; 'examples': 0.16; 'language': 0.16; 'converted': 0.18; 'simpler': 0.18; "user's": 0.18; 'template': 0.19; 'later': 0.19; 'received:209.85.212.46': 0.23; 'received:mail- vw0-f46.google.com': 0.23; 'changed': 0.23; 'converts': 0.23; 'enhancements': 0.23; 'optional': 0.23; 'pair': 0.23; 'sender:addr:gmail.com': 0.24; 'cache': 0.24; 'specify': 0.24; 'django': 0.25; 'code.': 0.26; 'code': 0.26; 'function': 0.27; 'import': 0.27; '(see': 0.28; 'message-id:@mail.gmail.com': 0.29; 'class': 0.29; 'example': 0.29; "skip:' 10": 0.29; 'lines': 0.30; 'pattern': 0.30; 'tar': 0.30; 'changes': 0.30; 'app': 0.31; 'received:209.85.212': 0.33; 'it.': 0.33; 'file': 0.34; 'skip:# 10': 0.34; '---------': 0.34; 'to:addr:python-list': 0.35; 'google': 0.35; 'url:python': 0.35; 'install': 0.35; 'beginning': 0.36; 'partial': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'skip:- 40': 0.38; 'received:209.85': 0.38; 'format': 0.38; 'should': 0.38; 'files': 0.39; 'skip:d 40': 0.39; 'url:org': 0.39; 'format.': 0.39; 'url:source': 0.39; 'received:209': 0.39; 'change': 0.40; 'to:addr:python.org': 0.40; 'release': 0.40; 'easy': 0.60; 'follow': 0.61; 'your': 0.61; 'virus:</script': 0.61; 'virus:<script': 0.61; 'engine': 0.65; 'skip:$ 10': 0.66; 'url:0': 0.67; 'fun!': 0.67; 'spaces': 0.73; 'client-side': 0.84; 'easy_install': 0.84; 'mechanism.': 0.84; 'template,': 0.84; 'or:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=j6wi8Z+tHnjCUVku6d4noVzuixrtj7r8vyUP6Xmnd4w=; b=dqJ9kdKcSiZ0IB4kkmJg+68jp9QdPjC+w4/f9T/fl9E21zD+f/xMis3IonFkP0+acM DOCjYEhPbzg0dPXviZPSVNPGgl70SFyTEjQQmk4nAnGi1WzfKcFMj0u1NOtvNkyNIY4u 0fLJHnqvNExzWd3ZLKbMvdh+YcctXmAAXDxSA=
MIME-Version 1.0
Sender kwatch@gmail.com
Date Fri, 17 Feb 2012 12:00:00 +0900
X-Google-Sender-Auth TZCU6CgcDmvEvWnMOhCqjhPqy3k
Subject ANN: pyTenjin 1.1.0 - a high-speed and full-featured template engine
From Makoto Kuwata <kwa@kuwata-lab.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5909.1329447603.27778.python-list@python.org> (permalink)
Lines 171
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1329447603 news.xs4all.nl 6899 [2001:888:2000:d::a6]:34878
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:20535

Show key headers only | View raw


I released pyTenjin 1.1.0.
http://pypi.python.org/pypi/Tenjin/
http://www.kuwata-lab.com/tenjin/


Overview of pyTenjin
--------------------

* Very fast: about 10 times faster than Django template engine
* Easy to learn: no need to learn template-original language
* Full-featured: nestable layout template, partial template, preprocessing, etc.
* Lightweight: only 2000 lines of code and very fast to import.
* Google App Engine supported


Documents
---------

* User's Guide
  http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html
* Examples
  http://www.kuwata-lab.com/tenjin/pytenjin-examples.html
* CHANGES
  http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt


Install
-------

    $ sudo easy_install Tenjin

Or:

    $ wget http://pypi.python.org/packages/source/T/Tenjin/Tenjin-1.1.0.tar.gz
    $ tar xzf Tenjin-1.1.0.tar.gz
    $ cd Tenjin-1.1.0/
    $ sudo python setup.py install


Example
-------

    ## views/example.pyhtml
    <?py #@ARGS title, items ?>
    <h2>${title}</h2>
    <table>
      <?py cycle = new_cycle('odd', 'even') ?>
      <?py for item in items: ?>
      <tr class="${cycle()}">
        <td>${item}</td>
      </tr>
      <?py #endfor ?>
    </table>

    ## main.py
    import tenjin
    #tenjin.set_template_encoding('utf-8')  # optional (default 'utf-8')
    from tenjin.helpers import *
    from tenjin.html import *
    engine = tenjin.Engine(path=['views'])
    context = {'title': 'Example', 'items': ['Haruhi', 'Mikuru', 'Yuki'] }
    output = engine.render('example.pyhtml', context)
    print(output)

    ## output
    $ python main.py
    <h2>Example</h2>
    <table>
      <tr class="odd">
        <td>Haruhi</td>
      </tr>
      <tr class="even">
        <td>Mikuru</td>
      </tr>
      <tr class="odd">
        <td>Yuki</td>
      </tr>
    </table>


Enhancements and Changes in this release
----------------------------------------

(See http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt for details.)

* [Change] !! IMPORTANT!! Default cache file format is changed from
  marshal format to text format.
  You should remove all cache files to use this release.

* [Enhance] Embedded pattern '${}' and '#{}' can contain pair of '{' and '}'. ::

      <p>${foo({'x':1})}</p>          # OK
      <p>${foo({}+{}+{})}</p>         # OK
      <p>${foo({'x':{'y':1}})}</p>    # NG

* [Enhance] New preprocessing mechanism. You can specify your own preprocessor
  class by 'pp' parameter.

* [Enhance] Add 'TrimPreprocessor' which removes spaces ad the
beginning of lines.
  You can reduce size of output by it.

* [Enhance] Add 'PrefixedLinePreprocessor' which converts ':: ...'
into '<?py ... ?>'.
  You may like ':: ...' because it is simpler than '<?py ... ?>'.

* [Enhance] Add 'JavaScriptPreprocessor' class which enables you to embed
  client-side javascript template code into server-side template.

  For example::

      <div id="placeholder">
        <!-- #JS: render_table(items) -->
        <table>
          <?js for (var i = 0, n = items.length; i < n; i++) { ?>
          <tr>
            <td>#{i}</td>
            <td>${items[i]}</td>
          </tr>
          <?js } ?>
        </table>
        <!-- #/JS -->
      </div>
      <script>#{tenjin.JS_FUNC}</script>
      <script>
        var html = render_table(["Haruhi", "Mikuru", "Yuki"]);
        document.getElementById('placehodler').innerHTML = html;
      </script>

  will be converted into::

      <div id="placeholder">
        <script>function render_table(items){var _buf='';
      _buf+='  <table>\n';
           for (var i = 0, n = items.length; i < n; i++) {
      _buf+='    <tr>\n\
            <td>'+_S(i)+'</td>\n\
            <td>'+_E(items[i])+'</td>\n\
          </tr>\n';
           }
      _buf+='  </table>\n';
        return _buf;};</script>
      </div>
      <script>#{tenjin.JS_FUNC}</script>
      <script>
        var html = render_table(["Haruhi", "Mikuru", "Yuki"]);
        document.getElementById('placehodler').innerHTML = html;
      </script>

  by JavaScriptPreprocessor.
  Notice that you should embed 'tenjin.JS_FUNC' to run client-side code.

  How to use it::

      pp = [ tenjin.JavaScriptPreprocessor() ]
      engine = tenjin.Engine(pp=pp)
      output = engine.render('example.pyhtml', {})
      print(html)

* [Enhance] Now supports Jython 2.5.2. (thanks to Lars Hupfeldt Nielsen)

* [Enhance] Now supports PyPy 1.7 or later officially.

* [Change] Template#convert() now converts "\r\n" into "\\r\n".
  This is necessary to follow change of language specification on
  Python 2.7 and 3.2.


Have fun!
--
makoto kuwata

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

ANN: pyTenjin 1.1.0 - a high-speed and full-featured template engine Makoto Kuwata <kwa@kuwata-lab.com> - 2012-02-17 12:00 +0900

csiph-web