-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-documentation
executable file
·167 lines (151 loc) · 4.48 KB
/
make-documentation
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
#!/bin/bash
tred="/home/pajas/tred-devel"
pod2xhtml="${tred}/devel/pod_to_xhtml"
css=("${tred}/documentation/"*.css)
if [ ! -x "$pod2xhtml" ]; then
"Didn't find pod_to_xhtml in $pod2xhtml"
exit 1;
fi
get_element () {
xsh2 -qI "${1}" -C "register-namespace p http://ufal.mff.cuni.cz/pdt/pml/; echo :n (/p:tred_extension/p:${2})"
}
for pkg in "$@"; do
pkg=${pkg%/}
dir=$(readlink -f "${pkg}")
doc_dir="${dir}/documentation"
pod="${doc_dir}/.pod"
html="${doc_dir}/html"
css_dir="${doc_dir}/html/css"
index="${doc_dir}/index.html"
icon=$(get_element "${dir}/package.xml" 'icon')
title=$(get_element "${dir}/package.xml" 'title')
version=$(get_element "${dir}/package.xml" 'version')
copyright=$(get_element "${dir}/package.xml" 'copyright')
year=$(get_element "${dir}/package.xml" 'copyright/@year')
repo=$(get_element "${dir}/package.xml" 'repository/@href')
index_title="Generated documentation for TrEd extension ${pkg}"
if [ -f "${doc_dir}/include.html" ]; then
index_title="Documentation for TrEd extension ${pkg}"
fi
stamp='generated by make-documentation'
if [ -f "$index" ] && ! grep -q "$stamp" "$index"; then
index="${doc_dir}/generated.html"
echo "Index index.html not generated, using $index instead!" 1>&2
fi
mkdir -p "${css_dir}"
cp "${css[@]}" "${css_dir}"
cat <<EOF > "$index"
<html>
<head>
<title>$index_title</title>
<!-- $stamp -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="html/css/blue.css" rel="stylesheet">
</head>
<body>
EOF
echo "Icon: '${dir}/${icon}'"
if [ -f "${dir}/${icon}" ]; then
cat <<EOF >> "$index"
<img src="../${icon}" alt="$pkg icon" align="right"/>
EOF
fi
cat <<EOF >> "$index"
<p>TrEd Extension: ${pkg} (version ${version})</p>
<h1>${title}</h1>
<h2>(generated documentation)</h2>
<h3>Description:</h3>
<p>
EOF
get_element "${dir}/package.xml" 'description' >> "$index"
echo "</p>" >> "$index"
if [ -f "${doc_dir}/include.html" ]; then
echo "<div class=\"include\">" >> "$index"
cat "${doc_dir}/include.html" >> "$index"
echo "</div>" >> "$index"
fi
cat <<EOF >> "$index"
<h3>Installation</h3>
<p>This extension can be installed directly from <a href="http://ufal.mff.cuni.cz/tred">TrEd</a>, using
<b>Setup >> Manage Extensions >> Get New Extensions</b>; just make sure
the repository <tt>$repo</tt> is enabled in <b>Setup >> Manage Extensions >> Edit Repositories</b>.
<p>
EOF
if [ -d "${dir}/contrib" ]; then
cat <<EOF >> "$index"
<h3>TrEd macro files:</h3>
<ul>
EOF
pushd "${dir}/contrib"
for f in */* ; do if [[ -e $f && $f != *~ ]] ; then
fdir=$(dirname "$f")
if grep -q '^=' "$f"; then
mkdir -p "${pod}/$fdir"
mkdir -p "${html}/$fdir"
podselect < "$f" > "${pod}/${f}.pod"
podchecker "${pod}/${f}.pod"
"$pod2xhtml" --no-index --toplink 'back' --topurl ../../index.html --css ../css/blue.css --infile "${pod}/${f}.pod" --outfile "${html}/${f}.html" --title "Generated documentation for ${f}"
echo "<li><a href=\"html/${f}.html\">${f}</a></li>" >> "$index"
else
echo "<li>${f}</li>" >> "$index"
fi
fi
done
popd
echo "</ul>" >> "$index"
fi
if [ -d "${dir}"/stylesheets ]; then
cat <<EOF >> "$index"
<h3>Stylesheet files:</h3>
<ul>
EOF
pushd "${dir}"/stylesheets/
for f in * ; do if [[ -e $f && $f != *~ ]] ; then
echo "<li>${f}</li>" >> "$index"
fi
done
echo "</ul>" >> "$index"
popd
fi
if [ -d "${dir}"/resources ]; then
cat <<EOF >> "$index"
<h3>Resource files:</h3>
<ul>
EOF
pushd "${dir}"/resources
for f in * ; do if [[ -e $f && $f != *~ ]] ; then
echo "<li>${f}</li>" >> "$index"
fi
done
popd
echo "</ul>" >> "$index"
fi
if [ -d "${dir}"/bin ]; then
cat <<EOF >> "$index"
<h3>Script files:</h3>
<ul>
EOF
pushd "${dir}"/bin
for f in *; do if [[ -e $f && $f != *~ ]] ; then
echo "<li>${f}</li>" >> "$index"
fi
done
popd
echo "</ul>" >> "$index"
fi
cat <<EOF >> "$index"
<h3>Copyright</h3>
<p>Copyright (c) $year by $copyright<p>
EOF
cat <<EOF >> "$index"
<h3>License</h3>
<p>This is a free software distributed under GPL - The General Public Licence.
<br />
Full text of the GPL can be found at <a href="http://www.gnu.org/copyleft/gpl.html">http://www.gnu.org/copyleft/gpl.html</a>.</p>
EOF
cat <<EOF >> "$index"
</body>
</html>
EOF
rm -rf "$pod"
done