]> Devi Nivas Git - chevron.git/commitdiff
update README
authorKay-Uwe (Kiwi) Lorenz <kiwi@franka.dyndns.org>
Sat, 28 Jul 2018 07:01:17 +0000 (09:01 +0200)
committerKay-Uwe (Kiwi) Lorenz <kiwi@franka.dyndns.org>
Sat, 28 Jul 2018 07:01:17 +0000 (09:01 +0200)
README.md

index a62545e9254db5a1a4128a86abad43e8afb8da1b..9cd855561b2027c84a627cd99376778b562d0c3d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -120,6 +120,33 @@ args = {
 chevron.render(**args)
 ```
 
+chevron supports lambdas
+```python
+import chevron
+
+def first(text, render):
+    # return only first occurance of items
+    result = render(text)
+    return [ x.strip() for x in result.split(" || ") if x.strip() ][0]
+
+def inject_x(text, render):
+    # inject data into scope
+    return render(text, {'x': 'data'})
+
+args = {
+    template: 'Hello, {{# first}} {{x}} || {{y}} || {{z}} {{/ first}}!  {{# inject_x}} {{x}} {{/ inject_x}}',
+
+    data: {
+        'y': 'foo',
+        'z': 'bar',
+        'first': first,
+        'inject_x': inject_x
+    }
+}
+
+chevron.render(**args)
+```
+
 INSTALL
 -------