summary refs log tree commit diff stats
path: root/ht.sh
diff options
context:
space:
mode:
Diffstat (limited to 'ht.sh')
-rwxr-xr-xht.sh60
1 files changed, 0 insertions, 60 deletions
diff --git a/ht.sh b/ht.sh deleted file mode 100755 index 7f20255..0000000 --- a/ht.sh +++ /dev/null
@@ -1,60 +0,0 @@
1#!/bin/sh
2# ht.sh
3# *.ht -> *html
4
5# config
6header_file=header.htm
7footer_file=footer.htm
8meta_file=meta.sh
9
10print() {
11 printf '%s\n' "$*"
12}
13
14htt() { # htt FILE
15 # Like `cat`, but with templating.
16 : "${HT_TMPL_COUNT:=0}"
17 ht_end="ht_main_$(date +%s)_${HT_TMPL_COUNT}" # be extra double sure
18 eval "$(
19 print "cat <<$ht_end"
20 cat "$@"
21 print
22 print "$ht_end"
23 )"
24 HT_TMPL_COUNT=$((HT_TMPL_COUNT + 1))
25}
26
27htmeta_clear() {
28 # Generate metadata-clearing commands from $meta_file.
29 while read -r line; do
30 case "$line" in
31 *'()'*) # function
32 unset -f "${line%()*}"
33 ;;
34 *=*) # variable assignment
35 unset -v "${line%=*}"
36 ;;
37 *) # other -- XXX: Don't know what to do
38 ;;
39 esac
40 done <"$meta_file" 2>/dev/null
41}
42
43htmeta() { # htmeta FILE
44 # Collect metadata from FILE.
45 # Metadata looks like this: `;;@<SHELL_EXPRESSION>`
46 sed -n 's/^;;@//p' "$1" 2>/dev/null | tee "$meta_file"
47}
48
49main() {
50 # Make two passes over each input file, collecting metadata and content.
51 # Of course, this isn't safe, but you trust yourself, right?
52 for file; do
53 eval "$(htmeta_clear)"
54 eval "$(htmeta "$file")"
55 ./ht.awk <"$file" | htt "$header_file" - "$footer_file"
56 done
57}
58
59test "$DEBUG" && set -x
60test "$SOURCE" || main "$@"