- commit
- 4f66dad2e097c08893fece897dd5df0ca340b497
- parent
- a152365910da464c1fdedd97e7a0d326115e45f5
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2021-07-04 12:49
expand README
Diffstat
| M | README.md | 45 | ++++++++++++++++++++++++++++++++++++++++++++- |
1 files changed, 44 insertions, 1 deletions
diff --git a/README.md b/README.md
@@ -1 +1,44 @@1 -1 Yet another mustache implementation.-1 1 Yet another [mustache](http://mustache.github.io/mustache.5.html) implementation. -1 2 -1 3 # Usage -1 4 -1 5 ``` -1 6 import stache -1 7 from html import escape -1 8 -1 9 template = stache.get_template('foo.html') -1 10 html = stache.render(template, {'title': 'my first website'}, escape) -1 11 -1 12 template = stache.parse('{{#foo}}{{bar}}{{/foo}}') -1 13 output = stache.render(template, {'foo': True, 'bar': 'Hello world!'}, lambda x: x) -1 14 ``` -1 15 -1 16 # Supported features -1 17 -1 18 - variables: `{{foo}}` -1 19 - safe variables: `{{&foo}}` -1 20 - sections: `{{#foo}}{{bar}}{{/foo}}` -1 21 - inverted sections: `{{^foo}}{{bar}}{{/foo}}` -1 22 - partials: `{{>path/to/file.html}}` -1 23 - comments: `{{! ignore me }}` -1 24 - lambdas: -1 25 -1 26 ```python -1 27 def highlight(nodes, context, escape): -1 28 text = stache.render(nodes, context, lambda x: x) -1 29 return pygments.highlight(text) -1 30 -1 31 template = stache.parse('{{#highlight}}{{code}}{{/highlight}}') -1 32 output = stache.render(template, {'code': …, 'highlight': highlight}, escape) -1 33 ``` -1 34 - context inheritance: you access variables from the outer contexts (unless they are shadowed) -1 35 - lines with standalone template tags are removed from the output -1 36 -1 37 # Not supported -1 38 -1 39 - changing delimiters -1 40 - `.` to access the current context object: `{{.}}` -1 41 - `.` to go down the context hierarchy: `{{foo.bar}}` -1 42 - `{{{foo}}}` for safe variables (use `{{&foo}}` instead) -1 43 - multi line comments -1 44 - partials are not indented