Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ANN: CherryTemplate-1.0.0 released

Reply
Thread Tools

ANN: CherryTemplate-1.0.0 released

 
 
Remi Delon
Guest
Posts: n/a
 
      11-18-2004
Hello everyone,

I'm happy to announce the first release of CherryTemplate, an easy and
powerful templating system in python.

Note that it is not "yet another templating system" because it used to
be part of CherryPy, but is now released as a standalone package.

Basically, you use it like this:

$ python
Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from cherrytemplate import renderTemplate
>>> name = "world"
>>> renderTemplate('Hello, <py-eval="name"/>')

'Hello, world'

The language only has a few tags: py-eval, py-exec, py-code, py-if,
py-for, py-include but it is quite powerful because most of python's
power is still available from the template:
- "py-for" allows you to do things like <py-for="i,j in [(0,0),
(1,2), (3,1)]">
- "py-code" allows you to insert full blocks of pure python code
inside your template (it takes care of the indentation for you)

CherryTemplate can also render external templates (ex:
renderTemplate(file = 'template.html')) and has full unicode support.

Once nice feature about it is that is uses generators to render your
template, so if you need to process a large amount of data you can
tell it to return a generator, and then you can loop through it. This
way it doesn't use up too much memory. Here is an example:

>>> template = '''<py-for="i in

range(5)">i:<py-eval="str(i)"/></py-for>'''
>>> result = renderTemplate(template, returnGenerator = True)
>>> for res in result: print repr(res)

'i:'
'0'
'i:'
'1'
'i:'
'2'
'i:'
'3'
'i:'
'4'
>>>


You can find more information (including the download link) on this
page: http://trac.cherrypy.org/cgi-bin/tra...CherryTemplate

Remi.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Win XP wireless network adapter gets released and then connects ba =?Utf-8?B?cGkyMmJ5Nw==?= Wireless Networking 1 08-01-2008 08:33 PM
Battlefield 2 New Patch Released (yet Again...) Silverstrand Front Page News 4 07-20-2005 04:33 PM
*Mozilla Firefox 1.0.4 Released* Roland Firefox 4 05-13-2005 03:05 PM
Firefox 1.0.1 released Z Firefox 2 02-26-2005 04:11 AM
ANN: Anyplace Control 2.6 released Yura Goncharuk Wireless Networking 0 09-28-2004 10:13 AM



Advertisments