Skip to content
Snippets Groups Projects
Select Git revision
  • master default
  • netaddr
  • ft/in-place
  • ft/run
  • v0.7.6
  • v0.7.5
  • v0.7.4
  • v0.7.3
  • v0.7.2
  • v0.7.1
  • v0.7.0
  • v0.6.6
  • v0.6.5
  • v0.6.4
  • v0.6.3
  • v0.6.2
  • v0.6.1
  • v0.6.0
  • v0.5.1
  • v0.5.0
  • v0.4.8
  • v0.4.7
  • v0.4.6
  • v0.4.4
24 results

template

  • Clone with SSH
  • Clone with HTTPS
  • Template

    https://travis-ci.org/adarnimrod/template.svg?branch=master

    A CLI tool for generating files from Jinja2 templates and environment variables. Tested on Python versions 2.7, 3.4 and later.

    Examples

    $ template -h
    usage: template [-h] [-o OUTPUT] [filename]
    
    A CLI tool for generating files from Jinja2 templates and environment
    variables.
    
    positional arguments:
      filename              Input filename
    
      optional arguments:
        -h, --help            show this help message and exit
          -o OUTPUT, --output OUTPUT
                                  Output to filename
    $ export name='John'
    $ echo 'Hello {{ name if name is defined else 'world' }}. | template
    Hello John.
    $ echo '{{ USER }}' > username.j2
    $ template --output username.txt username.j2
    $ cat username.txt
    John

    Jinja filters

    The following Jinja filters were added:

    • to_yaml: Convert to yaml.
    • from_yaml: Convert from yaml.
    • to_json: Convert to json.
    • from_json: Convert from json.
    • to_toml: Convert to toml.
    • from_toml: Convert from toml.
    • jmespath: Queries data using the JMESPath query language.

    Example usage can be seen in tests and for specific filters in the docstrings in template/filters.py.

    Testing

    Tests require Python 3.7, pipenv <https://docs.pipenv.org> and Bats <https://github.com/bats-core/bats-core>. Run the tests with the following commands:

    pipenv run lint  # Pre-commit hooks.
    pipenv run check  # Twine check.
    pipenv run doctest  # Doc tests.
    pipenv run bats  # Bats tests.

    Also, Travis CI is setup for this project so every push to this repository is checked with all supported Python versions.

    Release

    Release requires Python 3.7 and pipenv <https://docs.pipenv.org>. To bump the version run pipenv run bumpversion major|minor|patch to update the version and git commit and tag. Then run pipenv run upload to upload the new version to PyPI.

    License

    This software is licensed under the AGPL 3+ license (see the LICENSE.txt file).

    Author

    Nimrod Adar, contact me or visit my website. Patches are welcome via git send-email. The repository is located at: https://www.shore.co.il/git/.

    Pending tasks