public
Description: Mustache in Python
Homepage:
Clone URL: git://github.com/defunkt/pystache.git
name age message
file .gitignore Thu Nov 12 22:42:03 -0800 2009 gitignore more stuff [defunkt]
file HISTORY.md Mon Nov 16 17:38:27 -0800 2009 who knows when 0.2.0 will drop! [defunkt]
file LICENSE Thu Nov 12 22:26:08 -0800 2009 MIT [defunkt]
file README.md Wed Nov 11 16:52:48 -0800 2009 whitespace [defunkt]
file TODO Fri Nov 13 15:32:52 -0800 2009 one more todo item! [defunkt]
directory examples/ Thu Nov 12 22:02:02 -0800 2009 section and tag names can include aesthetic whi... [defunkt]
directory pystache/ Tue Nov 17 01:29:11 -0800 2009 Be sure to cast value to a string for unescaped... [joshthecoder]
file setup.py Fri Nov 13 16:21:23 -0800 2009 0.1.1 [defunkt]
directory tests/ Mon Nov 16 17:37:58 -0800 2009 Allow using View instances as attributes. [joshthecoder]
README.md

Pystache

Inspired by ctemplate and et, Mustache is a framework-agnostic way to render logic-free views.

As ctemplates says, "It emphasizes separating logic from presentation: it is impossible to embed application logic in this template language."

Pystache is a Python implementation of Mustache. It has been tested with Python 2.6.1.

Documentation

For now check out the ctemplate or Mustache docs.

Use It

>>> import pystache
>>> pystache.render('Hi {{person}}!', {'person': 'Mom'})
'Hi Mom!'

You can also create dedicated view classes to hold your view logic.

Here's your simple.py:

import pystache
class Simple(pystache.View):
    def thing(self):
        return "pizza"

Then your template, simple.mustache:

Hi {{thing}}!

Pull it together:

>>> Simple().render()
'Hi pizza!'

Test It

nose works great!

easy_install nose
cd pystache
nosetests

Author

context = { 'author': 'Chris Wanstrath', 'email': 'chris@ozmm.org' }
pystache.render("{{author}} :: {{email}}", context)