diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..513d73a0742bda8a072990e71e0153d89a537cb4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,12 @@ +- repo: git://github.com/pre-commit/pre-commit-hooks + sha: 97b88d9610bcc03982ddac33caba98bb2b751f5f + hooks: + - id: check-added-large-files + - id: check-json + - id: check-xml + - id: check-yaml + - id: check-merge-conflict +- repo: https://www.shore.co.il/git/shell-pre-commit/ + sha: 604fe77b53d3514d5ad0f66764c7783850bb6e98 + hooks: + - id: shell-lint diff --git a/MANIFEST.in b/MANIFEST.in index ad1d2d29eca8d9bbdf082e7faa9673946215135a..0866f4280301145eb0c8b08f20408f0f8d1f08f0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ recursive-include eb-prune *.py exclude .pre-commit-config.yaml -include README.rst +include *.rst include VERSION +include *.txt diff --git a/README.rst b/README.rst index 6ea622afeae82580d08cbad837b2876bc322e143..fb68c2cff54f7baf6c3dff63df3557ed6c3f5244 100644 --- a/README.rst +++ b/README.rst @@ -3,6 +3,15 @@ Template A CLI tool for generating files from Jinja2 templates and environment variables. +Example +------- + +.. code:: shell + + $ export name='John' + $ echo 'Hello {{ name if name is defined else 'world' }}. | template + Hello John. + TODO ---- diff --git a/VERSION b/VERSION index 8acdd82b765e8e0b8cd8787f7f18c7fe2ec52493..6c6aa7cb0918dc7a1cfa3635fb7f8792ac4cb218 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.1 +0.1.0 \ No newline at end of file diff --git a/setup.py b/setup.py index add19f13d84eafc9d927102aa773eaf5ec988d19..7a70257cf977beb39c3fc8f7942c7fef45b59d31 100644 --- a/setup.py +++ b/setup.py @@ -4,8 +4,8 @@ from setuptools import setup, find_packages setup( name='template', version=open('VERSION', 'r').read(), - description='A CLI tool for generating files from Jinja2 templates and - environment variables.', + description='''A CLI tool for generating files from Jinja2 templates and + environment variables.''', long_description=open('README.rst', 'r').read(), url='https://www.shore.co.il/git/template', author='Nimrod Adar', diff --git a/template/__init__.py b/template/__init__.py index 36045ba05b67b35d1ebfd46a55737d3025a548bc..c4817de2a1c4a7bddb6fca92791bee4b8232f712 100755 --- a/template/__init__.py +++ b/template/__init__.py @@ -3,21 +3,22 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) -from jinja2 import FileSystemLoader, DictLoader -from jinja2.environment import Environment +from jinja2 import Template from os import environ -from sys import stdin, argv +from sys import stdin def render(template): - env = Environment() - return env.from_string(template).render(environ) + t = Template(template) + return t.render(environ) + def usage(): raise NotImplemented + def main(): - template=stdin.read() + template = stdin.read() print(render(template)) if __name__ == '__main__': diff --git a/tests.sh b/tests.sh new file mode 100755 index 0000000000000000000000000000000000000000..7553718a3b3962703cb3426894af67821d7bab91 --- /dev/null +++ b/tests.sh @@ -0,0 +1,3 @@ +#!/bin/sh -e + +test "$(echo '{{ name }}' | name='Nimrod' template)" = "Nimrod" diff --git a/tox.ini b/tox.ini index c405c98ec9a8910b94a3bc5287e35e6039d84a8f..d2b00256d1a0ecf5d6b7f94678fe3a7c4b9df434 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,7 @@ commands = check-manifest --ignore tox.ini,tests* python setup.py check -m -r -s flake8 . + ./tests.sh [testenv:release] basepython = python