3 ms·
Plain shell is pretty good for templating, and it's the most available language on Unix. You have here docs for long literals, and you can choose to use $var e
by chubot 7y ago
Plain shell is pretty good for templating, and it's the most available language on Unix. You have here docs for long literals, and you can choose to use $var expansion or not with EOF or 'EOF' (yes it's a confusing syntax).
You have loops and conditionals, and functions that take parameters to modularize it (e.g. a function for each table row).
Sequential composition "concatenates" stdout. At the end you redirect it all like this, which is inconvenient in other languages:
top-level-function > out.html
----
For example, I generate this page with shell:
http://www.oilshell.org/releases.html http://www.oilshell.org/releases.html
And it's separated into 3-4 functions here:
https://github.com/oilshell/oil/blob/master/devtools/release.sh#L809 https://github.com/oilshell/oil/blob/master/devtools/release...
----
Shell falls down when you have to generate complex logic as with tables [1], but m4 also falls down there.
I actually experimented with many different methods in order to help me design the Oil language.
This is generated with awk, and it has some advantages over shell:
https://www.oilshell.org/release/0.8.pre3/test/spec.wwz/osh.html https://www.oilshell.org/release/0.8.pre3/test/spec.wwz/osh....
These two are generated with Python:
https://www.oilshell.org/release/0.8.pre3/test/spec.wwz/alias.html https://www.oilshell.org/release/0.8.pre3/test/spec.wwz/alia...
https://www.oilshell.org/release/0.8.pre3/test/wild.wwz/ https://www.oilshell.org/release/0.8.pre3/test/wild.wwz/
So I hope Oil will do better than shell, awk, and Python.
-----
Shell needs to be better for escaping. Template languages like Jinja do better there. I put m4 in the "70's-style macro processing bucket" which is generally sloppy about escaping.
I use Python for escaping here, but I do it with O(1) processes and not one process for every tiny fragment that needs to be escaped!
Git Log in HTML: A Harder Problem and A Safe Solution http://www.oilshell.org/blog/2017/09/29.html http://www.oilshell.org/blog/2017/09/29.html