A fast indentation-preserving template engine.
Project description
Overview
Example
import fett
fett.Template('''{{ for customer in customers }}
{{ if i even }}
Even: {{ customer.name }}
{{ else }}
Odd: {{ customer.name }}
{{ end }}
{{ else }}
No customers :(
{{ end }}''').render({'customers': [
{'name': 'Bob'},
{'name': 'Elvis'},
{'name': 'Judy'}
]})
Syntax
Tag Format |
Description |
---|---|
{{ <expression> }} |
|
{{ if <expression> }} |
|
{{ for <expression> in <expression> }} |
|
{{ else }} |
|
{{ end }} |
Block termination |
{{ # <comment> }} |
Spaces between tag opening/closing delimiters are optional.
Expressions
An expression is given for Substitutions, Conditionals, and Loops.
Expressions take the following form:
<name>[.<subfield>...] [<filter> [<filter2>...]]
You can use filters to modify a single value in simple ways. For example, the loop iteration counter i counts from 0, but users often wish to count from 1. You can obtain a count-from-1 value with the expression i inc.
The full list of available filters follows.
Filter Name |
Effect |
---|---|
odd |
Returns true iff its input is representable as an odd integer. |
even |
Returns true iff its input is representable as an even integer. |
car |
Returns the first element of a list. |
cdr |
Returns all but the first element of a list. |
len |
Returns the length of a list. |
strip |
Returns the input string with surrounding whitespace removed. |
inc |
Increments a value representable as an integer by one. |
not |
Returns the inverse of a boolean. |
Substitutions
Conditionals
Loops
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file fett-0.1.0.tar.gz
.
File metadata
- Download URL: fett-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a05f2bb664135e43a96bffe63a832aa53a78b82f1785b76f7d74790840a8213 |
|
MD5 | c39247efd065e7f4563e2391635d703b |
|
BLAKE2b-256 | 230f66171dd41b93326104ffc244c05182b56363e3ff519f2afc0f893350c5a5 |
Comments