-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·69 lines (57 loc) · 2.23 KB
/
build.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
#!/bin/bash
# There are two parts to this script:
# 1) Generate tutorial main page sections by substituting code sections into
# the html templates under $COGL_SRC/tutorials
# 2) Generate final web pages by substituting page sections into a
# template.html file according to a set of "mustache" markers.
#
# This script greps for all the "mustache" markers in template.html like
# {{foo}} and {{bar}} and then for each sub directory (PAGE) under pages/ we
# make a www/PAGE.html by copying template.html and substituting any
# pages/DIR/MUSTACHE_MARKER_NAME.html files we find that matches the names
# we found in the template. Markers without a corresponding file are simply
# stripped.
if test "$COGL_SRC" = ""; then
COGL_SRC=.
fi
for tutorial in `find $COGL_SRC/tutorials -maxdepth 1 -mindepth 1 -iname '*.c'`
do
tutorial=`basename $tutorial`
tutorial=${tutorial%.c}
output=pages/$tutorial/main.html
echo "Generating $output"
cp tutorials/$tutorial.html $output
for marker in `grep '{{' $output|sed -e 's/{{\([a-zA-Z_-]\+\)}}/\1/'`
do
printf " substituting %-30s" "{{$marker}}: "
if csplit -q tutorials/$tutorial.c "%//BEGIN($marker)%1" "/\/\/END($marker)/"; then
echo "OK"
else
echo "FAILED"
fi
sed -i -e "/\/\/BEGIN(/ d; /\/\/END(/ d; s/</\</g" xx00
sed -i -e "/{{$marker}}/ r xx00" -e "/{{$marker}}/ a </pre>" -e "s/{{$marker}}/<pre name=\"code\" class=\"c\">/g" $output
rm -f xx*
done
done
function mustache_substitute_pages()
{
local pages_dir=$1
local template=$2
local output_dir=$3
for page in `find $pages_dir -maxdepth 1 -mindepth 1 -type d`
do
echo "Generating $output_dir/`basename $page`.html"
cp template.html $output_dir/`basename $page`.html
for marker in `grep '{{' template.html|sed -e 's/{{\([a-zA-Z_-]\+\)}}/\1/'`
do
if test -f $page/$marker.html; then
echo " substituting {{$marker}} with $page/$marker.html"
sed -i -e "/{{$marker}}/ r $page/$marker.html" www/`basename $page`.html
fi
done
# Remove any remaining un-substituted mustache markers.
sed -i 's/{{\([a-zA-Z_-]\+\)}}//' www/`basename $page`.html
done
}
mustache_substitute_pages ./pages template.html ./www