OLD | NEW |
| (Empty) |
1 #library("prettyPrint"); | |
2 | |
3 #import("../../../frog/lib/node/node.dart"); | |
4 #import("dart:json"); | |
5 #import("util.dart"); | |
6 | |
7 String orEmpty(String str) { | |
8 return str == null ? "" : str; | |
9 } | |
10 | |
11 List<String> sortStringCollection(Collection<String> collection) { | |
12 final out = <String>[]; | |
13 out.addAll(collection); | |
14 out.sort((String a, String b) => a.compareTo(b)); | |
15 return out; | |
16 } | |
17 | |
18 int addMissing(StringBuffer sb, String type, Map members) { | |
19 int total = 0; | |
20 /** | |
21 * Add all missing members to the string output and return the number of | |
22 * missing members. | |
23 */ | |
24 void addMissingHelper(String propType) { | |
25 Map expected = allProps[type][propType]; | |
26 if (expected != null) { | |
27 for(final name in sortStringCollection(expected.getKeys())) { | |
28 if (!members.containsKey(name)) { | |
29 total++; | |
30 sb.add(""" | |
31 <tr class="missing"> | |
32 <td>$name</td> | |
33 <td></td> | |
34 <td>Could not find documentation for $propType</td> | |
35 </tr> | |
36 """); | |
37 } | |
38 } | |
39 } | |
40 } | |
41 | |
42 addMissingHelper('properties'); | |
43 addMissingHelper('methods'); | |
44 addMissingHelper('constants'); | |
45 return total; | |
46 } | |
47 | |
48 void main() { | |
49 // Database of code documentation. | |
50 final Map<String, Map> database = JSON.parse(fs.readFileSync( | |
51 'output/database.filtered.json', 'utf8')); | |
52 | |
53 // Types we have documentation for. | |
54 matchedTypes = new Set<String>(); | |
55 int numMissingMethods = 0; | |
56 int numFoundMethods = 0; | |
57 int numExtraMethods = 0; | |
58 int numGen = 0; | |
59 int numSkipped = 0; | |
60 final sbSkipped = new StringBuffer(); | |
61 final sbAllExamples = new StringBuffer(); | |
62 | |
63 // Table rows for all obsolete members. | |
64 final sbObsolete = new StringBuffer(); | |
65 // Main documentation file. | |
66 final sb = new StringBuffer(); | |
67 | |
68 // TODO(jacobr): switch to using a real template system instead of string | |
69 // interpolation combined with StringBuffers. | |
70 sb.add(""" | |
71 <html> | |
72 <head> | |
73 <style type="text/css"> | |
74 body { | |
75 background-color: #eee; | |
76 margin: 10px; | |
77 font: 14px/1.428 "Lucida Grande", "Lucida Sans Unicode", Lucida, | |
78 Arial, Helvetica, sans-serif; | |
79 } | |
80 | |
81 .debug { | |
82 color: #888; | |
83 } | |
84 | |
85 .compatibility, .links, .see-also, .summary, .members, .example { | |
86 border: 1px solid #CCC; | |
87 margin: 5px; | |
88 padding: 5px; | |
89 } | |
90 | |
91 .type, #dart_summary { | |
92 border: 1px solid; | |
93 margin-top: 10px; | |
94 margin-bottom: 10px; | |
95 padding: 10px; | |
96 overflow: hidden; | |
97 background-color: white; | |
98 -moz-box-shadow: 5px 5px 5px #888; | |
99 -webkit-box-shadow: 5px 5px 5px #888; | |
100 box-shadow: 5px 5px 5px #888; | |
101 } | |
102 | |
103 #dart_summary { | |
104 border: 2px solid #00F; | |
105 margin: 5px; | |
106 padding: 5px; | |
107 } | |
108 | |
109 th { | |
110 background-color:#ccc; | |
111 font-weight: bold; | |
112 } | |
113 | |
114 tr:nth-child(odd) { | |
115 background-color:#eee; | |
116 } | |
117 tr:nth-child(even) { | |
118 background-color:#fff; | |
119 } | |
120 | |
121 tr:nth-child(odd).unknown { | |
122 background-color:#dd0; | |
123 } | |
124 tr:nth-child(even).unknown { | |
125 background-color:#ff0; | |
126 } | |
127 | |
128 tr:nth-child(odd).missing { | |
129 background-color:#d88; | |
130 } | |
131 tr:nth-child(even).missing { | |
132 background-color:#faa; | |
133 } | |
134 | |
135 li.unknown { | |
136 color: #f00; | |
137 } | |
138 | |
139 td, th { | |
140 vertical-align: top; | |
141 } | |
142 </style> | |
143 <title>Doc Dump</title> | |
144 </head> | |
145 <body> | |
146 <h1>Doc Dump</h1> | |
147 <ul> | |
148 <li><a href="#dart_summary">Summary</a></li> | |
149 </li> | |
150 """); | |
151 for (String type in sortStringCollection(database.getKeys())) { | |
152 final entry = database[type]; | |
153 if (entry == null || entry.containsKey('skipped')) { | |
154 numSkipped++; | |
155 sbSkipped.add(""" | |
156 <li id="$type"> | |
157 <a target="_blank" href="http://www.google.com/cse?cx=01719397256594783026
6%3Awpqsk6dy6ee&ie=UTF-8&q=$type"> | |
158 $type | |
159 </a> | |
160 -- | |
161 Title: ${entry == null ? "???" : entry["title"]} -- Issue: | |
162 ${entry == null ? "???" : entry['cause']} | |
163 -- | |
164 <a target="_blank" href="${entry == null ? "???" : entry["srcUrl"]}"> | |
165 scraped url | |
166 </a> | |
167 </li>"""); | |
168 continue; | |
169 } | |
170 matchedTypes.add(type); | |
171 numGen++; | |
172 StringBuffer sbSections = new StringBuffer(); | |
173 StringBuffer sbMembers = new StringBuffer(); | |
174 StringBuffer sbExamples = new StringBuffer(); | |
175 if (entry.containsKey("members")) { | |
176 Map members = getMembersMap(entry); | |
177 sbMembers.add(""" | |
178 <div class="members"> | |
179 <h3><span class="debug">[dart]</span> Members</h3> | |
180 <table> | |
181 <tbody> | |
182 <tr> | |
183 <th>Name</th><th>Description</th><th>IDL</th><th>Status</th> | |
184 </tr> | |
185 """); | |
186 for (String name in sortStringCollection(members.getKeys())) { | |
187 Map memberData = members[name]; | |
188 bool unknown = !hasAny(type, name); | |
189 StringBuffer classes = new StringBuffer(); | |
190 if (unknown) classes.add("unknown "); | |
191 if (unknown) { | |
192 numExtraMethods++; | |
193 } else { | |
194 numFoundMethods++; | |
195 } | |
196 | |
197 final sbMember = new StringBuffer(); | |
198 | |
199 if (memberData.containsKey('url')) { | |
200 sbMember.add(""" | |
201 <td><a href="${memberData['url']}">$name</a></td> | |
202 """); | |
203 } else { | |
204 sbMember.add(""" | |
205 <td>$name</td> | |
206 """); | |
207 } | |
208 sbMember.add(""" | |
209 <td>${memberData['help']}</td> | |
210 <td> | |
211 <pre>${orEmpty(memberData['idl'])}</pre> | |
212 </td> | |
213 <td>${memberData['obsolete'] == true ? "Obsolete" : ""}</td> | |
214 """); | |
215 if (memberData['obsolete'] == true) { | |
216 sbObsolete.add("<tr class='$classes'><td>$type</td>$sbMember</tr>"); | |
217 } | |
218 sbMembers.add("<tr class='$classes'>$sbMember</tr>"); | |
219 } | |
220 | |
221 numMissingMethods += addMissing(sbMembers, type, members); | |
222 | |
223 sbMembers.add(""" | |
224 </tbody> | |
225 </table> | |
226 </div> | |
227 """); | |
228 } | |
229 for (String sectionName in | |
230 ["summary", "constructor", "compatibility", "specification", | |
231 "seeAlso"]) { | |
232 if (entry.containsKey(sectionName)) { | |
233 sbSections.add(""" | |
234 <div class="$sectionName"> | |
235 <h3><span class="debug">[Dart]</span> $sectionName</h3> | |
236 ${entry[sectionName]} | |
237 </div> | |
238 """); | |
239 } | |
240 } | |
241 if (entry.containsKey("links")) { | |
242 sbSections.add(""" | |
243 <div class="links"> | |
244 <h3><span class="debug">[Dart]</span> Specification</h3> | |
245 <ul> | |
246 """); | |
247 List links = entry["links"]; | |
248 for (Map link in links) { | |
249 sbSections.add(""" | |
250 <li><a href="${link['href']}">${link['title']}</a></li> | |
251 """); | |
252 } | |
253 sbSections.add(""" | |
254 </ul> | |
255 </div> | |
256 """); | |
257 } | |
258 if (entry.containsKey("examples")) { | |
259 for (String example in entry["examples"]) { | |
260 sbExamples.add(""" | |
261 <div class="example"> | |
262 <h3><span class="debug">[Dart]</span> Example</h3> | |
263 $example | |
264 </div> | |
265 """); | |
266 } | |
267 } | |
268 | |
269 String title = entry['title']; | |
270 if (title != type) { | |
271 title = '<h4>Dart type: $type</h4><h2>$title</h2>'; | |
272 } else { | |
273 title = '<h2>$title</h2>'; | |
274 } | |
275 sb.add(""" | |
276 <div class='type' id="$type"> | |
277 <a href='${entry['srcUrl']}'>$title</a> | |
278 $sbSections | |
279 $sbExamples | |
280 $sbMembers | |
281 </div> | |
282 """); | |
283 if (sbExamples.length > 0) { | |
284 sbAllExamples.add(""" | |
285 <div class='type' id="$type"> | |
286 <a href='${entry['srcUrl']}'>$title</a> | |
287 $sbExamples | |
288 </div> | |
289 """); | |
290 } | |
291 } | |
292 | |
293 for (String type in sortStringCollection(allProps.getKeys())) { | |
294 if (!matchedTypes.contains(type) && | |
295 !database.containsKey(type)) { | |
296 numSkipped++; | |
297 sbSkipped.add(""" | |
298 <li class="unknown" id="$type"> | |
299 <a target="_blank" href="http://www.google.com/cse?cx=01719397256594783026
6%3Awpqsk6dy6ee&ie=UTF-8&q=$type"> | |
300 $type | |
301 </a> | |
302 </li> | |
303 """); | |
304 } | |
305 } | |
306 | |
307 sb.add(""" | |
308 <div id="#dart_summary"> | |
309 <h2>Summary</h2> | |
310 <h3> | |
311 Generated docs for $numGen classes out of a possible | |
312 ${allProps.getKeys().length} | |
313 </h3> | |
314 <h3>Found documentation for $numFoundMethods methods listed in WebKit</h3> | |
315 <h3> | |
316 Found documentation for $numExtraMethods methods not listed in WebKit | |
317 </h3> | |
318 <h3> | |
319 Unable to find documentation for $numMissingMethods methods present in | |
320 WebKit | |
321 </h3> | |
322 <h3> | |
323 Skipped generating documentation for $numSkipped classes due to no | |
324 plausible matching files | |
325 </h3> | |
326 <ul> | |
327 $sbSkipped | |
328 </ul> | |
329 </div> | |
330 """); | |
331 sb.add(""" | |
332 </body> | |
333 </html> | |
334 """); | |
335 | |
336 fs.writeFileSync("output/database.html", sb.toString()); | |
337 | |
338 fs.writeFileSync("output/examples.html", """ | |
339 <html> | |
340 <head> | |
341 <style type="text/css"> | |
342 body { | |
343 background-color: #eee; | |
344 margin: 10px; | |
345 font: 14px/1.428 "Lucida Grande", "Lucida Sans Unicode", Lucida, Arial, | |
346 Helvetica, sans-serif; | |
347 } | |
348 | |
349 .debug { | |
350 color: #888; | |
351 } | |
352 | |
353 .example { | |
354 border: 1px solid #CCC; | |
355 margin: 5px; | |
356 padding: 5px; | |
357 } | |
358 | |
359 .type { | |
360 border: 1px solid; | |
361 margin-top: 10px; | |
362 margin-bottom: 10px; | |
363 padding: 10px; | |
364 overflow: hidden; | |
365 background-color: white; | |
366 -moz-box-shadow: 5px 5px 5px #888; | |
367 -webkit-box-shadow: 5px 5px 5px #888; | |
368 box-shadow: 5px 5px 5px #888; | |
369 } | |
370 </style> | |
371 <title>All examples</title> | |
372 </head> | |
373 <body> | |
374 <h1>All examples</h1> | |
375 $sbAllExamples | |
376 </body> | |
377 </html> | |
378 """); | |
379 | |
380 fs.writeFileSync("output/obsolete.html", """ | |
381 <html> | |
382 <head> | |
383 <style type="text/css"> | |
384 body { | |
385 background-color: #eee; | |
386 margin: 10px; | |
387 font: 14px/1.428 "Lucida Grande", "Lucida Sans Unicode", Lucida, | |
388 Arial, Helvetica, sans-serif; | |
389 } | |
390 | |
391 .debug { | |
392 color: #888; | |
393 } | |
394 | |
395 .type { | |
396 border: 1px solid; | |
397 margin-top: 10px; | |
398 margin-bottom: 10px; | |
399 padding: 10px; | |
400 overflow: hidden; | |
401 background-color: white; | |
402 -moz-box-shadow: 5px 5px 5px #888; | |
403 -webkit-box-shadow: 5px 5px 5px #888; | |
404 box-shadow: 5px 5px 5px #888; | |
405 } | |
406 </style> | |
407 <title>Methods marked as obsolete</title> | |
408 </head> | |
409 <body> | |
410 <h1>Methods marked as obsolete</h1> | |
411 <table> | |
412 <tbody> | |
413 <tr> | |
414 <th>Type</th> | |
415 <th>Name</th> | |
416 <th>Description</th> | |
417 <th>IDL</th> | |
418 <th>Status</th> | |
419 </tr> | |
420 $sbObsolete | |
421 </tbody> | |
422 </table> | |
423 </body> | |
424 </html> | |
425 """); | |
426 } | |
OLD | NEW |