diff options
Diffstat (limited to 'ht.sh')
-rwxr-xr-x | ht.sh | 60 |
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 | ||
6 | header_file=header.htm | ||
7 | footer_file=footer.htm | ||
8 | meta_file=meta.sh | ||
9 | |||
10 | print() { | ||
11 | printf '%s\n' "$*" | ||
12 | } | ||
13 | |||
14 | htt() { # 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 | |||
22 | print "$ht_end" | ||
23 | )" | ||
24 | HT_TMPL_COUNT=$((HT_TMPL_COUNT + 1)) | ||
25 | } | ||
26 | |||
27 | htmeta_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 | |||
43 | htmeta() { # 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 | |||
49 | main() { | ||
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 | |||
59 | test "$DEBUG" && set -x | ||
60 | test "$SOURCE" || main "$@" | ||