An open API service indexing awesome lists of open source software.

https://github.com/ncfavier/templa

A script-based template engine
https://github.com/ncfavier/templa

template-engine

Last synced: 4 months ago
JSON representation

A script-based template engine

Awesome Lists containing this project

README

        

# templa

A simple and *very* stupid [template engine](https://en.wikipedia.org/wiki/Template_processor).

It executes **scripts** embedded in **template files** and substitutes their output in-place.

## Principle

*templa* processes **template files** and generates **output files** according to the following principle:

Any segment of a file between a line that starts with `#!` (a *shebang*, possibly indented) and a line that ends with `!#` (or the end of the file) is considered an **embedded script**.

This embedded script is isolated in a temporary file, with the proper amount of indentation removed and the final `!#` stripped, and then executed. The standard output of that program is added to the output file, replacing the embedded script.

A literal `#!` can be escaped with `##!`.

## Example

#### Input
```html

Files



    #!/bin/bash
    for file in *; do
    printf '
  • %s
  • \n' "$file"
    done !#

```

#### Output
```html

Files



  • LICENSE

  • Makefile

  • README.md

  • templa

  • templates


```

----------

To see a live example, check out [`templates/README.md`](/templa/tree/templates/README.md).

## Installing

*templa* requires **Bash version 4** or later, as well as **GNU coreutils**. These should be present on most GNU/Linux systems.

Clone this repository on your system and copy the `templa` executable to some location in your PATH, e.g. `/usr/local/bin` or `~/.bin`.

## Using

Usage: templa [-qh] [-t target] templates...
Render the templates from TEMPLATES to the TARGET directory.

Options:
-t Choose the target directory. By default, the current directory is used.
If - is given, render everything to standard output.
-v Verbose mode, print file names to standard output before rendering them.
-q Quiet mode, don't print errors.
-h Show this help message.