-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake-zeal-docs.zsh
executable file
·160 lines (143 loc) · 3.67 KB
/
make-zeal-docs.zsh
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
#!/bin/zsh
DOCSET="EMF_XSD_SDK.docset"
if [[ -d ${DOCSET} ]]; then
echo "Deleting the old ${DOCSET} directory"
rm -rf ${DOCSET}
fi
# Create the docset folder
mkdir -p ${DOCSET}/Contents/Resources/Documents/
# Generate the docs
javadoc -d ${DOCSET}/Contents/Resources/Documents/ \
emf-jars/org/eclipse/**/*.java
# Create the Info.plist
cat <<EOF > ${DOCSET}/Contents/Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>emf-xsd-sdk</string>
<key>CFBundleName</key>
<string>EMF XSD SDK</string>
<key>DocSetPlatformFamily</key>
<string>emf-xsd-sdk</string>
<key>isDashDocset</key>
<true/>
<key>dashIndexFilePath</key>
<string>overview-summary.html</string>
</dict>
</plist>
EOF
# Create the meta.json
cat <<EOF > ${DOCSET}/meta.json
{
"aliases": [],
"feed_url": "",
"icon": "lisp",
"name": "emf-xsd-sdk",
"oldVersions": [],
"revision": "1",
"source": "tsdh",
"title": "EMF XSD SDK",
"urls": [],
"version": ""
}
EOF
DB="${DOCSET}/Contents/Resources/docSet.dsidx"
# Create the SQLite DB
echo "Creating new database ${DB}"
sqlite3 ${DB} \
'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);
CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);'
function htmlEscape() {
echo ${1} | sed -e 's/</</' | sed -e 's/>/>/'
}
# $1 = name
# $2 = type
# $3 = link
function insertIntoDB() {
local name
name=$(htmlEscape ${1})
sqlite3 ../docSet.dsidx \
"INSERT OR IGNORE INTO searchIndex(name, type, path)
VALUES ('${name}', '${2}', '${3}');"
}
function compressDetails() {
local line=""
while IFS= read -r l; do
echo $l
if [[ $l == -- ]]; then
print -r - $line
line=""
else
line+=${l}
fi
done
if [[ -n ${line} ]]; then
print -r - $line
fi
}
# $1 = class
# $2 = type
# $3 = file
function parseDetails() {
local anchor
local thing
while IFS= read -r l; do
anchor=$(echo ${l} | grep -oP '<a name="\K.*?(?=">.*)')
thing=$(echo ${l} | grep -oP '<h4>\K.*(?=</h4>)')
if [[ -n ${anchor} && -n ${thing} ]]; then
local type=${2}
if [[ ${type} == "Field" && ${thing} =~ "^[A-Z0-9_]+$" ]]; then
# All-uppercase fields are usually constants
type="Constant"
fi
echo " |--> ${type} ${thing}"
if [[ ${thing} == ${1} && ${type} != "Constructor" ]]; then
# Inserting a Class/Enum/Interface
insertIntoDB "${thing}" ${type} "${3}#${anchor}"
else
# Inserting a Field or Method or Constructor
insertIntoDB "${thing} (${1})" ${type} "${3}#${anchor}"
fi
fi
done
}
# $1 = class
# $2 = file
# $3 = type
# $4 = rx
function parseFileDetails() {
sed -n "/=\+ ${4} DETAIL =\+/,/========/p" ${2} \
| grep -P -B5 '<h4>.*</h4>' \
| compressDetails \
| parseDetails ${1} ${3} ${2}
}
# $1 = file
function parseJavaDocFile() {
local class
class=$(grep -oP '<h2 title="[^"]+" class="title">\K(Interface|Class|Enum).*(?=</h2>)' ${1})
if [[ -n ${class} ]]; then
local -a a
a=(${(s/ /)class})
echo "====> $a[1] $a[2]"
insertIntoDB $a[2] $a[1] ${1}
# Fields
parseFileDetails $a[2] ${1} "Field" "FIELD"
# Constructors
parseFileDetails $a[2] ${1} "Constructor" "CONSTRUCTOR"
# Methods
parseFileDetails $a[2] ${1} "Method" "METHOD"
else
echo "Ignoring file ${file}"
fi
}
cd ${DOCSET}/Contents/Resources/Documents/
for file in org/eclipse/**/*.html; do
parseJavaDocFile ${file}
done
cd -
# Add icons
cp emf-jars/modeling32.png ${DOCSET}/icon@2x.png
convert -scale 16x16 ${DOCSET}/icon@2x.png ${DOCSET}/icon.png
echo Fini.