Skip to main content

A CLI tool for building plaintext artifacts by populating Jinja templates from YAML files.

Project description

Stenciler

stenciler is a CLI tool for building plaintext artifacts by populating Jinja templates from YAML files. You can use it in any case where you need to create one or more different plaintext formats with the same data, e.g. a resume in .txt and .tex formats.

Installation

pipx install stenciler

Example Usage

Here is an example use case. These files can also be found in the sample directory.

Say you need to build a sample resume in .txt and .tex formats. First, set up your data:

# resume.yaml
name: Marie Curie
summary: |
    Physicist, chemist, two-time Nobel Prize winner, enjoys long bicycle trips.
awards:
- name: Nobel Prize in Chemistry
  year: 1911
- name: Albert Medal
  year: 1910
- name: Davy Medal
  year: 1903
- name: Nobel Prize in Physics
  year: 1903

Now, set up your stencil. This yaml file should have a simple dictionary structure where the keys are file extensions (e.g. txt, tex) and the values are Jinja templates.

# stencil.yaml
txt: |
  Name:       {{ name }}

  SUMMARY
  ----------------------------------------------------------------------------------
  {{ summary | replace('\n', ' ') | wordwrap(80) }}

  AWARDS
  ----------------------------------------------------------------------------------
  {% for award in awards %}{{ award.name }}{{ " " * (78 - award.name.__len__()) }}{{ award.year}}
  {% endfor %}
tex: |
  \documentclass{article}
  \begin{document}
  {\huge\centering {{ name }}\\[-0.7\baselineskip]\hrulefill\par}

  \subsection*{Summary}
  {{ summary | replace('\n', ' ') | wordwrap(80) }}

  \subsection*{Education}
  {% for award in awards %}
  \noindent {{ award.name }} \hfill {{ award.year }}
  {% endfor %}

  \end{document}

Last, run stenciler to generate the output files:

stenciler --stencil stencil.yaml --data resume.yaml

Results:

# outputs/resume.txt
Name:       Marie Curie

SUMMARY
----------------------------------------------------------------------------------
Physicist, chemist, two-time Nobel Prize winner, enjoys long bicycle trips.

AWARDS
----------------------------------------------------------------------------------
Nobel Prize in Chemistry                                                      1911
Albert Medal                                                                  1910
Davy Medal                                                                    1903
Nobel Prize in Physics                                                        1903
# outputs/resume.tex
\documentclass{article}
\begin{document}
{\huge\centering Marie Curie\\[-0.7\baselineskip]\hrulefill\par}

\subsection*{Summary}
Physicist, chemist, two-time Nobel Prize winner, enjoys long bicycle trips.

\subsection*{Education}

\noindent Nobel Prize in Chemistry \hfill 1911

\noindent Albert Medal \hfill 1910

\noindent Davy Medal \hfill 1903

\noindent Nobel Prize in Physics \hfill 1903


\end{document}

Screenshot of compiled resume.pdf

Developer Setup

Set up your virtual environment:

python3 -m venv .venv

Assuming direnv, set up your .envrc:

# .envrc
PATH_add .venv/bin
PATH_add bin

chmod -R +x bin

Allow your env file and install requirements:

direnv allow
pip install -r dev-requirements.txt

Run the test script:

checks

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stenciler-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file stenciler-0.1.1.tar.gz.

File metadata

  • Download URL: stenciler-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.10

File hashes

Hashes for stenciler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9395b552410008c147194b2417df5c23443043d9e3f1fab7a5d8c403ff48e8b8
MD5 f442720dd60ab888fc9823fbe00024ca
BLAKE2b-256 f200cbc0060d847fae5a3af435ec29fb3d01b27c4ff6077a97171171cc5e5d6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page