https://github.com/i80and/fett
A fast indentation-preserving template engine
https://github.com/i80and/fett
templating templating-engine templating-language
Last synced: 6 months ago
JSON representation
A fast indentation-preserving template engine
- Host: GitHub
- URL: https://github.com/i80and/fett
- Owner: i80and
- License: mit
- Created: 2016-10-24T21:06:23.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T21:01:42.000Z (over 3 years ago)
- Last Synced: 2025-04-06T20:17:28.653Z (about 1 year ago)
- Topics: templating, templating-engine, templating-language
- Language: Python
- Homepage:
- Size: 47.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. |travis| image:: https://travis-ci.org/i80and/fett.svg?branch=master
:target: https://travis-ci.org/i80and/fett
=============
Fett |travis|
=============
Overview
--------
Example
-------
.. code-block:: python
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
========================================== ===========
``{{ }}`` Substitutions_
``{{ `foo` }}`` Substitutions_
``{{ format }}`` Metaformatting_
``{{ if }}`` Conditionals_
``{{ for in }}`` Loops_
``{{ else }}``
``{{ end }}`` Block termination
``{{ # }}`` Comments_
========================================== ===========
Spaces between tag opening/closing delimiters are optional.
Expressions
~~~~~~~~~~~
An **expression** is given for Substitutions_, Conditionals_, and Loops_.
Expressions take the following form:
[....] [ [...]]
Instead of specifying a field path, you can start an expression using
a string literal:
`` [ [...]]
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 filters:
=========== ======
Filter Name Effect
=========== ======
car Returns the first element of a list.
cdr Returns all but the first element of a list.
dec Decrements a value representable as an integer by one.
even Returns true iff its input is representable as an even integer.
escape Encodes `&`, `<`, `>`, `"`, and `'` characters with HTML entities.
inc Increments a value representable as an integer by one.
len Returns the length of a list.
not Returns the inverse of a boolean.
odd Returns true iff its input is representable as an odd integer.
negative Returns true iff its input is representable as an integer < 0.
positive Returns true iff its input is representable as an integer > 0.
split Splits a value into a list by whitespace.
strip Returns the input string with surrounding whitespace removed.
striptags Remove HTML tags from a value.
timesNegOne Returns int(input) * -1
zero Returns true iff the input is zero
=========== ======
=========== ======
Filter Name Effect
=========== ======
upperCase Returns a Unicode-aware uppercase version of the input.
lowerCase Returns a Unicode-aware lowercase version of the input.
=========== ======
===================== ======
Filter Name Effect
===================== ======
add(n) Increments a value representable as an integer by `n`.
minus(n) Decrements a value representable as an integer by `n`.
equal(value) Returns true iff a value equals the given value.
lessThan(n) Returns true iff n < the given value.
lessThanOrEqual(n) Returns true iff n <= the given value.
greaterThan(n) Returns true iff n > the given value.
greaterThanOrEqual(n) Returns true iff n >= the given value.
===================== ======
Substitutions
~~~~~~~~~~~~~
Metaformatting
~~~~~~~~~~~~~~
Conditionals
~~~~~~~~~~~~
Loops
~~~~~
Comments
~~~~~~~~