My blogging software composes the
"single page" article by
a head HTML skeletton then adding
the articles and then
tail HTML skeletton.
The code is ugly.
To improve the code I concluded I need to use templates.
I searched the web, looked at Python template libraries, at ERB, at jinja2 and other stuff.
There are a few problems with those solutions:
- you have to pick up new conventions
- you have to cross languages. Passing values from shell to other languages requires coding
- if you have variables that are indented in the template and those variables contain multiple lines then only the first line will be indented. You have to resort to further steps to correctly indent variables containing multiple lines.
- some of the solutions are not in Debian and thus incur maintenance cost
My requirements are quite simple, but when using third party templating commands, the additional required machinery gets quite voluminous.
So I though about and looked at templating solutions made with "standard" Unix tools.
A kind of a template is a shell
cat << EOT Hello my name is $NAME EOT
Variables and expressions in the
get evaluated. However
contained within a shell script. I wanted a
heredocs however can be ripped out
of the shell script and sourced, which
makes them standalone:
$ cat heredoc.template cat << EOT Hello my name is $NAME EOT $ NAME=Peter source heredoc.template
Now the only thing remaining to get rid of is the opening and closing ceremony, in order to make the templates displayable and editable in the target programms, in this case in web browsers.
The final step can be found here.
Tomáš Pospíšek, 2017-02-18