-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc.sh
executable file
·270 lines (217 loc) · 5.95 KB
/
doc.sh
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/bash
#
# Copyright 2014 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found
# in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd
#
# Usage:
# ./doc.sh <function name>
# Add the HTML shell. A data dictionary should be readable stdin. Does NOT
# depend on $PWD, so callers can cd.
set -o nounset
set -o errexit
to-html() {
local out=$1
jsont doc/html.jsont > $out
}
# TODO: Get rid of bad dependencies:
#
# webpipe docs -> pin -> docopt
make-dict() {
local body_filename=$1
pin --title-tag=h1 $body_filename
}
# Build main docs. Called by ./run.sh latch-demo, which calls './latch.sh
# rebuild'.
build() {
local in=$1
local out=$2
local base_in=$(basename $in .md) # For now, get rid of subdirs
local body=_tmp/$base_in-body.html
mkdir -p --verbose $(dirname $out)
echo "Building $in -> $body -> $out"
markdown $in >$body
ls -al $body
local template
case $base_in in
# Use simpler template from the screencast (so it's not skinny)
screencast)
template=doc/simple-html.jsont
;;
*)
template=doc/html.jsont
;;
esac
make-dict $body | jsont $template > $out
ls -al $out
}
build-all() {
build doc/webpipe.md _tmp/doc/webpipe.html
build doc/screencast.md _tmp/doc/screencast.html
shrink-screenshot
gallery
# For the video
ln -v -s -f \
../../doc/screenshot.jpg \
../../doc/screencast.ogv \
_tmp/doc
tree _tmp/doc
}
shrink-screenshot() {
convert doc/screenshot.jpg -scale '50%' _tmp/doc/screenshot_small.jpg
}
# TODO: Just list the plugins/ dir?
# - need to show symlinks
plugin-types() {
echo dot html json markdown Rplot.png treemap tar.gz txt zip
# TODO:
# - csv has issue with importing JSON Template; not being hermetic
# - R generates <html>, it's not a real snippet
# - typescript is also generates html
}
# Generate a named snippet for each plugin type. Then join them into an HTML
# doc.
gallery-snippets() {
local plugin_types="$1"
local out_dir=$2
rm -rf $out_dir
mkdir -p $out_dir
for p in $plugin_types; do
local plugin=$PWD/plugins/$p/render
local input
case $p in
dot)
input=$PWD/plugins/dot/testdata/cluster.dot
;;
typescript)
# disabled
input=$PWD/plugins/typescript/testdata/typescript
;;
*)
input=$PWD/plugins/$p/testdata/tiny.$p
;;
esac
# NOTE: we are not providing a number
local output=$p
# plugins are written to be in the output dir.
pushd $out_dir
$plugin $input $output
popd >/dev/null
done
}
print-gallery() {
local plugin_types="$1"
local base_dir=$2
cat <<EOF
<h1>webpipe Gallery</h1>
<p>Here is a list of file types and example documents. There is a JavaScript
visualization behind some links.</p>
EOF
# Generate TOC.
for p in $plugin_types; do
echo "<a href=\"#$p\">$p</a> <br/>"
done
# Generate snippets. TODO: should be use a <div> or something?
for p in $plugin_types; do
echo '<hr />'
echo "<a id=\"$p\"></a><h3>$p</h3>"
# TODO: alternative text?
local path=plugins/$p/gallery.md
if test -f $path; then
# display on stdout
markdown $path
fi
# snippet inline
cat $base_dir/$p.html
done
}
# TODO:
# - how to get the .js to work?
# It goes ../../...
# Maybe it should be a variable, like $WEBPIPE_PLUGIN_BASE_URL.
#
# could publish it to:
# there will be:
# webpipe/plugins/
# webpipe/s/2014-04-04/1.html
# webpipe/doc/gallery/index.html
# png testdata
# - just make a little R plot
makelink() {
local src=$1
local dest=$2
mkdir -p $(dirname $dest)
ln -v -s -f $src --no-target-directory $dest
}
# The gallery needs to reference static assets. list the ones with static.
# TODO: automate this more?
link-static() {
makelink $PWD/plugins/treemap/static/ _tmp/plugins/treemap/static
makelink $PWD/plugins/json/static/ _tmp/plugins/json/static
tree _tmp/doc
}
gallery() {
local plugin_types="$(plugin-types)"
local base_dir=$PWD/_tmp/doc/gallery # absolute path
gallery-snippets "$plugin_types" $base_dir
local body=$base_dir/body.html
local out=$base_dir/index.html
print-gallery "$plugin_types" $base_dir > $body
# NOTE: It's interesting that #anchors don't work without <html>? At least
# in Chrome.
make-dict $body | to-html $out
# The gallery needs to link to static assets. TODO: Should be _tmp/doc?
link-static
ls -al $base_dir
}
check() {
# TODO: put this in a test?
tidy -errors _tmp/gallery/out/index.html
}
# NOTE: gallery has to be 3 levels deep to access ../../../plugins/*/static
deploy() {
set -o errexit
# create a file in this dir with the base dir, e.g. [email protected]:mydir
local base=$(cat ssh-base.txt)
echo $base
# Have to get all the generated dirs. NOTE: Don't need the individual
# snippets. Maybe remove.
scp -r _tmp/doc/* $base/webpipe/doc
scp -r _tmp/plugins $base/webpipe
}
#
# Screencast
#
# Use the method here. "Record my desktop", then convert using mplayer then Image Magick.
#
# http://askubuntu.com/questions/107726/how-to-create-animated-gif-images-of-a-screencast
# 57s for a 2.7 M file.
frames() {
local video_in=$1
local frames_out=${2:-}
if test -z "$frames_out"; then
local out_dir=_tmp/frames
mkdir -p $out_dir
frames_out="$out_dir/$(basename $video_in)"
fi
# TODO: use png or gif?
time mplayer -ao null $video_in -vo jpeg:outdir=$frames_out
}
# Took 4m 37s for a 1.4 MB ogv? Resulted in 50 MB animated gif.
animated-gif() {
local frames_in=$1
local gif_out=${2:-_tmp/gif/screencast.gif}
mkdir -p $(dirname $gif_out)
time convert $frames_in/* $gif_out
}
# This method reduces gif from 50MB to 1MB.
#
# But on 142MB gif, this doesn't just crash, but hangs the machine!
optimize-gif() {
local gif_in=$1
local gif_out=$(echo $gif_in | sed 's/\.gif/_opt.gif/')
set -x
export MAGICK_THREAD_LIMIT=1
time convert $gif_in -fuzz 10% -layers Optimize $gif_out
}
"$@"