TCL-enriched templated plain-text docs #324
sgbeal
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Many years ago, inspired by a capability of the Fossil SCM, i implemented a feature in my home-brew scripting engine which processed plain-text documents with minimal markup which embeds code from that language. That scripting engine currently generates many of the static pages on my web site and i thought it would be interesting to explore replacing that with jimtcl.
To that end, i reimplemented the templating engine in TCL, making sure it works in both canonical TCL and JimTCL (the end goal being to use the latter, with a copy embedded in my web site's tree, but i'm still a number of steps away from that), which looks a little something like...
When run as-is it says:
The reason for the "compilation" step is because this was initially envisioned for producing web-based output, where it is sometimes useful to generate, e.g. table rows via a template. The template is compiled one time and then eval'd once per table row, updating the vars which the template references before eval'ing it for each row.
Forewarning: being only a few minutes old, it very likely has an outstanding bug or three.
Edit: the current canonical home of this script, updated significantly from the copy shown above:
https://fossil.wanderinghorse.net/r/www-wh/file/site-tools/tcl.d/tmplish.tcl
PS: TCL is not my native language!
Edit: the API has since been restructured to use a namespace and optionally take its content from a file, but i'll leave the initial implementation here because it's simpler to read. See the link above for the latest code.
Beta Was this translation helpful? Give feedback.
All reactions