Author: | Adrian Perez <aperez@igalia.com>, initial concept and implementation by Andrés J. Díaz <ajdiaz@mundo-r.com>. This implementation shares no code with the original one. |
---|---|
Copyright: | 2008-2009 Igalia S.L. |
License: | GPL3 |
Abstract
Miminalistic template engine to be used from shell scripts. Can be used to dynamically generate any kind of text-based content, including (but not limited to) HTML.
Templates reuse the Bash parser, so the followgin constructs can be used inside the template text:
Variables are expanded from the ones defined in the environment, but only variables starting with a given prefix (var_ by default) will be seen by the templates. For example the following template:
Hello ${name}!
would use a variable named var_name when expanding it, for example using the following command:
var_name='Peter' template_expand < input.txt > output.txt
The final rendered result would be (as expected):
Hello, Peter!
template_expand [ prefix ]
Expands shell variables in lines given as input. Optionally a prefix can be specified (default is var_) so a reference to ${xyz} in the input will be expanded with the contents of ${var_xyz}. The template is read from the standard input and the expanded result dumped as standard output. Typical usage would be:
var_foo='This is foo' var_bar='This is bar' \
template_expand < input_template > expanded_output
template_expand_cgi [ prefix ]
Works exactly like template_expand, but adds automatically the variables specified by the CGI standard.