blob: 120a004226dd30d5b0071a45f38310af57d06724 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
Pystache
========
Inspired by [ctemplate][1] and [et][2], 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
-------------
The different Mustache tags are documented at [mustache(5)][m5].
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][n] works great!
easy_install nose
cd pystache
nosetests
Author
------
context = { 'author': 'Chris Wanstrath', 'email': 'chris@ozmm.org' }
pystache.render("{{author}} :: {{email}}", context)
[1]: http://code.google.com/p/google-ctemplate/
[2]: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
[3]: http://google-ctemplate.googlecode.com/svn/trunk/doc/howto.html
[4]: http://github.com/defunkt/mustache#readme
[n]: http://somethingaboutorange.com/mrl/projects/nose/0.11.1/testing.html
[m5]: http://defunkt.github.com/mustache/mustache.5.html
|