Commit 6cea160b authored by nimrod's avatar nimrod
Browse files

- TOML filters (WIP).

parent b62fddbc
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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`.

+1 −1
Original line number Diff line number Diff line
@@ -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={
+10 −0
Original line number Diff line number Diff line
@@ -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)
+8 −0
Original line number Diff line number Diff line
@@ -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"