GithubHelp home page GithubHelp logo

bastienf / jinja-recurse Goto Github PK

View Code? Open in Web Editor NEW

This project forked from diginc/jinja-recurse

0.0 0.0 0.0 49 KB

Jinja Recursive Templating for the CLI

License: MIT License

Shell 2.30% Python 97.70%

jinja-recurse's Introduction

jinjarecurse CLI tool


PyPI GitHub Workflow Status GitHub PyPI - Downloads


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 and CHANGELOG.md.

jinja-recurse's People

Contributors

dependabot[bot] avatar diginc avatar kyluca avatar rugglcon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.