Skip to main content

A Simple Tool for Documenting Jinja2 Template-Files

Project description

Author: Hartmut Goebel <h.goebel@crazy-compilers.com>
Copyright: 2015 by Hartmut Goebel
Licence:GNU General Public Licence v3 or later (GPLv3+)

This tool allows you writing documentation directly into jinja2 template-files as comments. These comments will then be converted to text and the template-code goes into literal blocks.

This is some kind of literate programming, except that you do not write code into your text, but text into your code. This difference allows to use the template-file directly without any pre-processing.

Usage:

jinja2rst [-h] infile outfile

positional arguments:
  infile      jinja2-template-file to read (`-` for stdin)
  outfile     rst-file to write (`-` for stdout)

optional arguments:
  -h, --help  show this help message and exit

How it works

This script takes all lines beginning with # (and lines consisting of only a #) as text-lines. Everything else will be treated as “code”. The text-lines will get the # removed and the “code” will get spaces prepended.

Additionally at the start and at the end of a “code”-block, lines are added as required by reStructuredText. Also at the begin of a “code”-block, a :: is added if required.

Examples

You can find example jinja2-input, rst-output and generated html in the examples directory. You may also view the generated html online at https://rawgit.com/htgoebel/jinja2rst/develop/examples/main.html.

Project details


Release history Release notifications

This version

0.1

Download files

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

Files for jinja2rst, version 0.1
Filename, size & hash File type Python version Upload date
jinja2rst-0.1.tar.gz (21.0 kB) View hashes Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page