blob: f69faf140aa80e9d4f5436933e7fcd663e81f69a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# `pp(1)`
a preprocessor
`pp(1)` allows embedding
[`sh(1)`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html)
code in files of any type by nesting it inside the `#!\n` token, where
`\n` is a new line. That means that if you'd like a simple loop or an
`if` inside an HTML file for instance,
you could use `pp(1)`.
## Basic usage
For the following code:
<!doctype html>
<title>pp(1) example</title>
<ul>
#!
i=1
while test $i -le 10
do
if test $((i % 2)) -eq 0
then
#!
<li class=even>$i</li>
#!
else
#!
<li class=odd>$i</li>
#!
fi
i=$((i + 1))
done
#!
</ul>
`pp(1)` outputs:
<!doctype html>
<title>pp(1) example</title>
<ul>
<li class=odd>1</li>
<li class=even>2</li>
<li class=odd>3</li>
<li class=even>4</li>
<li class=odd>5</li>
<li class=even>6</li>
<li class=odd>7</li>
<li class=even>8</li>
<li class=odd>9</li>
<li class=even>10</li>
</ul>
## Arguments
You can also pass arguments to it by appending them to the command call:
<!doctype html>
<title>$1</title>
<p>
#!
echo $2
#!
</p>
Calling the above code with
`pp tmp.upphtml 'pp(1) example' 'hello, world'`
will result in:
<!doctype html>
<title>pp(1) example</title>
<p>
hello world
</p>
## Pipes
`pp(1)`'s `stdin` is sent to the child
[`sh(1)`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html)
<!doctype html>
<title>pp(1) example</title>
<p>
#!
cat
#!
</p>
`echo 'hello, world' | pp tmp.upphtml` will output:
<!doctype html>
<title>pp(1) example</title>
<p>
hello, world
</p>
## Debugging
`pp(1)` also takes an optional `-d` flag. If passed, `pp(1)` will dump
the generated
[`sh(1)`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html)
code instead of executing it:
<!doctype html>
<title>pp(1) example</title>
<ul>
#!
i=1
while test $i -le 10
do
if test $((i % 2)) -eq 0
then
#!
<li class=even>$i</li>
#!
else
#!
<li class=odd>$i</li>
#!
fi
i=$((i + 1))
done
#!
</ul>
`pp -d tmp.upphtml` will output:
echo "<!doctype html>
<title>pp(1) example</title>
<ul>"
i=1
while test $i -le 10
do
if test $((i % 2)) -eq 0
then
echo " <li class=even>$i</li>"
else
echo " <li class=odd>$i</li>"
fi
i=$((i + 1))
done
echo "</ul>"
## Example
<!doctype html>
<html lang=en>
<title>pp(1)</title>
<meta charset=UTF-8>
<meta name=viewport content='width=device-width'>
<link rel=stylesheet href=../theme.css>
<body>
<a href=../#myprojects>Home</a>
#!
addcls() {
sed "s/<code>/<code class=language-bash>/g"
}
smu README | addcls
#!
<h2>Files</h2>
<ul>
#!
for f in *
do
case $f in
*.upp*|*.html|*.tgz)
continue
;;
esac
#!
<li><a href=$f>$f</a></li>
#!
done
#!
</ul>
<h2>Download</h2>
<a href=pp.tgz>pp.tgz</a>
<script src=../prism.js data-manual></script>
<script src=../enhance.js></script>
</body>
</html>
## See also
* <https://github.com/radare/spp>
* <https://werc.cat-v.org/docs/rc-template-lang>
* <https://code.9front.org/hg/werc/file/92f7463dac1a/bin/template.awk>
|