Loading README.rst +30 −5 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ Template A CLI tool for generating files from Jinja2 templates and environment variables. Example ------- Examples -------- .. code:: shell Loading @@ -26,7 +26,32 @@ Example $ cat username John TODO ---- - Complex data types (process environment variables, Jinja filters). 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. - pprint: Pretty print variable. - combine: Combine 2 dictionaries. Example usage can be seen in :code:`tests.sh`. License ------- This software is licensed under the AGPL 3+ license (see the :code:`LICENSE.txt` file). Author ------ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/. VERSION +1 −1 Original line number Diff line number Diff line 0.2.0 No newline at end of file 0.3.0 No newline at end of file setup.py +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ setup( ], keywords='config configuration jinja template environment', packages=find_packages(), install_requires=['Jinja2'], install_requires=['Jinja2', 'PyYAML'], extras_require={ 'dev': ['tox'], }, entry_points={ Loading template/__init__.py +8 −3 Original line number Diff line number Diff line Loading @@ -3,15 +3,20 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) from jinja2 import Template from jinja2 import Environment from os import environ from sys import stdin, stdout import argparse from argparse import ArgumentParser import template.filters def render(template): t = Template(template) def render(template_string): env = Environment() # Add all functions in template.filters as Jinja filters. for tf in filter(lambda x: not x.startswith('_'), dir(template.filters)): env.filters[tf] = template.filters.__getattribute__(tf) t = env.from_string(template_string) return t.render(environ) Loading template/filters.py +13 −6 Original line number Diff line number Diff line Loading @@ -2,24 +2,31 @@ def to_yaml(value): raise NotImplemented from yaml import safe_dump return safe_dump(value) def to_json(value): raise NotImplemented from json import dumps return dumps(value) def from_json(value): raise NotImplemented from json import loads return loads(value) def from_yaml(value): raise NotImplemented from yaml import safe_load return safe_load(value) def pprint(value): raise NotImplemented from pprint import pformat return pformat(value) def combine(lefthand, righthand): raise NotImplemented combined = lefthand.copy() combined.update(righthand) return combined Loading
README.rst +30 −5 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ Template A CLI tool for generating files from Jinja2 templates and environment variables. Example ------- Examples -------- .. code:: shell Loading @@ -26,7 +26,32 @@ Example $ cat username John TODO ---- - Complex data types (process environment variables, Jinja filters). 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. - pprint: Pretty print variable. - combine: Combine 2 dictionaries. Example usage can be seen in :code:`tests.sh`. License ------- This software is licensed under the AGPL 3+ license (see the :code:`LICENSE.txt` file). Author ------ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/.
VERSION +1 −1 Original line number Diff line number Diff line 0.2.0 No newline at end of file 0.3.0 No newline at end of file
setup.py +1 −1 Original line number Diff line number Diff line Loading @@ -21,7 +21,7 @@ setup( ], keywords='config configuration jinja template environment', packages=find_packages(), install_requires=['Jinja2'], install_requires=['Jinja2', 'PyYAML'], extras_require={ 'dev': ['tox'], }, entry_points={ Loading
template/__init__.py +8 −3 Original line number Diff line number Diff line Loading @@ -3,15 +3,20 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) from jinja2 import Template from jinja2 import Environment from os import environ from sys import stdin, stdout import argparse from argparse import ArgumentParser import template.filters def render(template): t = Template(template) def render(template_string): env = Environment() # Add all functions in template.filters as Jinja filters. for tf in filter(lambda x: not x.startswith('_'), dir(template.filters)): env.filters[tf] = template.filters.__getattribute__(tf) t = env.from_string(template_string) return t.render(environ) Loading
template/filters.py +13 −6 Original line number Diff line number Diff line Loading @@ -2,24 +2,31 @@ def to_yaml(value): raise NotImplemented from yaml import safe_dump return safe_dump(value) def to_json(value): raise NotImplemented from json import dumps return dumps(value) def from_json(value): raise NotImplemented from json import loads return loads(value) def from_yaml(value): raise NotImplemented from yaml import safe_load return safe_load(value) def pprint(value): raise NotImplemented from pprint import pformat return pformat(value) def combine(lefthand, righthand): raise NotImplemented combined = lefthand.copy() combined.update(righthand) return combined