Skip to content
Snippets Groups Projects
Commit 6cea160b authored by nimrod's avatar nimrod
Browse files

- TOML filters (WIP).

parent b62fddbc
Branches
No related tags found
No related merge requests found
......@@ -42,6 +42,8 @@ The following Jinja filters were added:
- :code:`from_json`: Convert from json.
- :code:`pprint`: Pretty print variable.
- :code:`combine`: Combine 2 dictionaries.
- :code:`to_toml`: Convert to toml.
- :code:`from_toml`: Convert from toml.
Example usage can be seen in :code:`tests.sh`.
......
......@@ -21,7 +21,7 @@ setup(
],
keywords='config configuration jinja template environment',
packages=find_packages(),
install_requires=['Jinja2', 'PyYAML'],
install_requires=['Jinja2', 'PyYAML', 'toml'],
extras_require={
'dev': ['tox'], },
entry_points={
......
......@@ -30,3 +30,13 @@ def combine(default, override):
combined = default.copy()
combined.update(override)
return combined
def from_toml(value):
from toml import loads
return loads(value)
def to_toml(value):
from toml import dumps
return dumps(value)
......@@ -39,4 +39,12 @@ echo Testing combining dictionaries.
echo '{{ {"a": 1, "b": 2}|combine({"a": 11, "c": 33}) }}' > "$infile"
test "$(template $infile)" = "{'a': 11, 'c': 33, 'b': 2}"
echo Testing TOML parsing.
echo '{{ "[table]\n key = value" | from_toml }}' > "$infile"
test "$(template $infile)" = "table = {'key': 'value'}"
echo Testing TOML output.
echo "{{ {'key': [1, 2]} | to_toml }}" > "$infile"
test "$(template $infile)" = "key = [ 1, 2,]"
rm "$infile" "$outfile"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment