about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-01-25 23:04:02 -0600
committerCase Duckworth2024-01-25 23:04:02 -0600
commitd17a818581cf73ec2801bfd8d80a2e6e95c3b412 (patch)
tree3f94fbf5e20b7b38adaf9e1aaffc4344ee136c2e
parentUpdate to use prefix characters (diff)
downloadet-d17a818581cf73ec2801bfd8d80a2e6e95c3b412.tar.gz
et-d17a818581cf73ec2801bfd8d80a2e6e95c3b412.zip
Add templating capability main
-rwxr-xr-xet32
-rw-r--r--template.htm3
-rw-r--r--test.et1
-rwxr-xr-xtet9
4 files changed, 35 insertions, 10 deletions
diff --git a/et b/et index 144b10a..19a8833 100755 --- a/et +++ b/et
@@ -3,24 +3,31 @@
3# usage: et <file> | sh 3# usage: et <file> | sh
4 4
5BEGIN { 5BEGIN {
6 dend = ";doc_end;" 6 # Tuneables
7 postproc = postproc ? postproc : "shexpand"
8 bodyfunc = bodyfunc ? bodyfunc : "body"
9 # Globals
10 wrpfx = ";:"; shxpfx = "!shx!"; def_docend = "---end---"
11 pretext = bodyfunc"(){\n"; posttext = "}\n"bodyfunc
7 # Ask sed to do these b/c awk has no capture groups ;_; 12 # Ask sed to do these b/c awk has no capture groups ;_;
8 shellfix = "sed -E" \ 13 shellfix = "sed -E" \
9 " -e 's/`/\\\\`/g'" \ 14 " -e 's/`/\\\\`/g'" \
10 " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \ 15 " -e 's/(^|[^\\$])\\$([^\\$]|$)/\\1\\\\$\\2/g'" \
11 " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'" 16 " -e 's/(^|[^\\$])\\$(\\$+)([^\\$]|$)/\\1\\2\\3/g'"
12 shxwrap = " -e 's/^/:/'" 17 shxwrap = " -e 's/^/"wrpfx"/'"
13 htmlfix = "sed -E" \ 18 htmlfix = "sed -E" \
14 " -e 's#([^\\\\]|^)&#\\1\\&amp;#g'" \ 19 " -e 's#([^\\\\]|^)&#\\1\\&amp;#g'" \
15 " -e 's#([^\\\\]|^)<#\\1\\&lt;#g'" \ 20 " -e 's#([^\\\\]|^)<#\\1\\&lt;#g'" \
16 " -e 's#([^\\\\]|^)>#\\1\\&gt;#g'" \ 21 " -e 's#([^\\\\]|^)>#\\1\\&gt;#g'" \
17 " -e 's#\\\\([&<>])#\\1#g'" 22 " -e 's#\\\\([&<>])#\\1#g'"
18 true = 1 ; false = 0 23 true = 1 ; false = 0
19 print "#!/bin/sh\n########## generated with excitable text #########" 24 print "### excitable text ###"
20 print "shexpand()(eval \"$(:;(echo 'cat<<.';cat|sed 's/^/,/';echo .)"\ 25 print "wrap()(sed \"s/^/$1/\");unwrap()(sed \"s/^$1//\")"
21 "|unwrap ,)\")" 26 print "shexpand()(eval"\
27 " \"$(:;(echo 'cat<<.';sed 's/^/"shxpfx"/';echo .)"\
28 "|unwrap "shxpfx")\")"
22 print "shellfix()(" shellfix ")\nhtmlfix()(" htmlfix ")" 29 print "shellfix()(" shellfix ")\nhtmlfix()(" htmlfix ")"
23 print "wrap()(sed \"s/^/$1/\")\nunwrap()(sed \"s/^$1//\")" 30 print "postproc=" postproc
24} 31}
25 32
26end[endn] && $0 == end[endn] { 33end[endn] && $0 == end[endn] {
@@ -39,9 +46,10 @@ end[endn] && $0 == end[endn] {
39/^\.\.\./ { 46/^\.\.\./ {
40 printpar() 47 printpar()
41 docp = !docp 48 docp = !docp
42 docend = $2 ? $2 : dend 49 docend = $2 ? $2 : def_docend
43 if (docp) print "unwrap :<<'" docend "'|shexpand" 50 if (docp) print pretext "unwrap '" wrpfx "'" \
44 else print docend "\n" 51 "<<'" docend "'|$postproc"
52 else end_text()
45 next 53 next
46} 54}
47 55
@@ -71,7 +79,11 @@ end[endn] && $0 == end[endn] {
71 79
72END { 80END {
73 if (par) printpar() 81 if (par) printpar()
74 if (docp) print docend 82 if (docp) end_text()
83}
84
85function end_text() {
86 print docend "\n" posttext
75} 87}
76 88
77function printpar() { 89function printpar() {
diff --git a/template.htm b/template.htm new file mode 100644 index 0000000..13d48d5 --- /dev/null +++ b/template.htm
@@ -0,0 +1,3 @@
1<!DOCTYPE html>
2<title>${title}</title>
3<body>$(body)</body>
diff --git a/test.et b/test.et index 927a4af..60c59bc 100644 --- a/test.et +++ b/test.et
@@ -1,5 +1,6 @@
1. ./etlib.sh 1. ./etlib.sh
2alias verse=cat 2alias verse=cat
3title="test file"
3... 4...
4here's a test file 5here's a test file
5.a href="https://example.com" a link or something!! 6.a href="https://example.com" a link or something!!
diff --git a/tet b/tet new file mode 100755 index 0000000..c97d677 --- /dev/null +++ b/tet
@@ -0,0 +1,9 @@
1#!/bin/sh
2
3__template__="$1"; shift
4et="$(which et||echo ./et)"
5
6"$et" "$@" | sed '$d'
7echo 'shexpand<<%'
8cat "$__template__"
9echo %