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
- Host: GitHub
- URL: https://github.com/ncfavier/templa
- Owner: ncfavier
- License: isc
- Created: 2020-10-04T12:14:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-04T12:16:33.000Z (over 4 years ago)
- Last Synced: 2024-12-26T19:28:47.241Z (5 months ago)
- Topics: template-engine
- Language: Shell
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```htmlFiles
- %s \n' "$file"
#!/bin/bash
for file in *; do
printf '
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.