Metadata-Version: 2.1
Name: jinjarecurse
Version: 0.0.2
Summary: Jinja Recursive Templating from the CLI
Home-page: https://github.com/diginc/Jinja-Recurse
Author: diginc
Author-email: adam@diginc.us
License: MIT
Keywords: jinja templater
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Topic :: Utilities
Classifier: License :: OSI Approved :: MIT License
Description-Content-Type: text/markdown
Requires-Dist: docopt (==0.6.2)
Requires-Dist: jinja2 (==2.11.3)
Requires-Dist: markupsafe (==1.1.1)
Requires-Dist: pathlib2 (==2.3.5)
Requires-Dist: pyyaml (==5.4)
Requires-Dist: six (==1.15.0)

# jinjarecurse CLI tool
_________________
![PyPI](https://img.shields.io/pypi/v/jinjarecurse?color=blue)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/diginc/jinja-recurse/Upload%20Python%20Package)
![GitHub](https://img.shields.io/github/license/diginc/jinja-recurse)
![PyPI - Downloads](https://img.shields.io/pypi/dm/jinjarecurse)
_________________

Jinja Recursive Templating for the CLI.  Recursively template one file or many
folders of many files like a config management languages allow, without the
whole config management language.  Useful if you're switching from managing an
application from config management to just docker and need some simple
templating logic.

## Installation

```
pip install jinjarecurse
```

## Example Usage

```
$ jinjarecurse --help
 jinjarecurse (CLI)

Usage:
    jinjarecurse --vars=VARS_FILE --input=INPUT_PATH --output=OUTPUT_PATH

Options:
    -v <file>, --vars   <file>
    -i <file>, --input  <file>
    -o <file>, --output <file>
```

### Single file

Given a config file containing your variables e.g. `vars.yaml`:

```
#comment: not available
root: /
number: 1
dictionary:
    street: 123 North Ave
    city: New York
    state: New York
list:
    - ABC
    - DEF
    - HJK
layer_1:
    layer_2:
        layer_3: last
```

And an input file jinja2 template e.g. `i_file`:

```
# Top level
{{root}}
{{number}}
{{dictionary}}
{{list}}
{{layer_1}}

# Nested data

{{dictionary.street}}
{{dictionary.city}}
{{dictionary.state}}
{{layer_1.layer_2.layer_3}}
```

You can populate it and specify an output filepath e.g. `o_file`:

```
$ jinjarecurse -v example/vars.yaml -i example/i_file -o example/o_file
WARNING: example/o_file (output) exists and any conflicting files will be overwritten
Writing from example/i_file to example/o_file
```

Contents of the output file e.g. `o_file`:

```
# Top level
/
1
{'street': '123 North Ave', 'city': 'New York', 'state': 'New York'}
['ABC', 'DEF', 'HJK']
{'layer_2': {'layer_3': 'last'}}

# Nested data

123 North Ave
New York
New York
last
```

### Directory

You can also template an entire directory e.g. `i_dir` at once. Note the
output files in the output directory will maintain the filenames from the
input directory:

```
$ jinjarecurse -v example/vars.yaml -i example/i_dir -o example/o_dir
Writing from example/i_dir/i_file to example/o_dir/i_file
Writing from example/i_dir/i_file_1 to example/o_dir/i_file_1
Writing from example/i_dir/i_file_2 to example/o_dir/i_file_2
```

## Tests

To run the unit tests, first install the dependencies:

```
$ pipenv install --dev .
```

Then invoke pytest:

```
$ pipenv run py.test -vvvs
```

## Changelog

Please see the [Releases](https://github.com/diginc/Jinja-Recurse/releases)
and [CHANGELOG.md](https://github.com/diginc/Jinja-Recurse/blob/master/CHANGELOG.md).


