Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: utils/apidoc/mdn/extract.dart

Issue 10889017: Repair bitrot in the utils/apidoc/mdn/ code. It now runs all the way through, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/apidoc/mdn/crawl.js ('k') | utils/apidoc/mdn/extract.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #import ("dart:html"); 1 #import ("dart:html");
2 #import ("dart:dom_deprecated", prefix:"dom");
3 #import ("dart:json"); 2 #import ("dart:json");
4 3
5 // Workaround for HTML lib missing feature. 4 // Workaround for HTML lib missing feature.
6 Range newRange() { 5 Range newRange() {
7 return LevelDom.wrapRange(dom.document.createRange()); 6 return document.createRange();
8 } 7 }
9 8
10 // Temporary range object to optimize performance computing client rects 9 // Temporary range object to optimize performance computing client rects
11 // from text nodes. 10 // from text nodes.
12 Range _tempRange; 11 Range _tempRange;
13 // Hacks because ASYNC measurement is annoying when just writing a script. 12 // Hacks because ASYNC measurement is annoying when just writing a script.
14 ClientRect getClientRect(Node n) { 13 ClientRect getClientRect(Node n) {
15 if (n is Element) { 14 if (n is Element) {
16 dom.Element raw = unwrapDomObject(n.dynamic); 15 // return LevelDom.wrapClientRect(n.$dom_getBoundingClientRect());
Jacob 2012/08/28 23:34:54 remove this commented out line
eub 2012/08/29 19:29:39 Done.
17 return LevelDom.wrapClientRect(raw.getBoundingClientRect()); 16 return n.$dom_getBoundingClientRect();
18 } else { 17 } else {
19 // Crazy hacks that works for nodes.... create a range and measure it. 18 // Crazy hacks that works for nodes.... create a range and measure it.
20 if (_tempRange == null) { 19 if (_tempRange == null) {
21 _tempRange = newRange(); 20 _tempRange = newRange();
22 } 21 }
23 _tempRange.setStartBefore(n); 22 _tempRange.setStartBefore(n);
24 _tempRange.setEndAfter(n); 23 _tempRange.setEndAfter(n);
25 return _tempRange.getBoundingClientRect(); 24 return _tempRange.getBoundingClientRect();
26 } 25 }
27 } 26 }
28 27
29 /** 28 /**
30 * CSS class that is added to elements in the DOM to indicate that they should 29 * CSS class that is added to elements in the DOM to indicate that they should
31 * be removed when extracting blocks of documentation. This is helpful when 30 * be removed when extracting blocks of documentation. This is helpful when
32 * running this script in a web browser as it is easy to visually see what 31 * running this script in a web browser as it is easy to visually see what
33 * blocks of information were extracted when using CSS such as DEBUG_CSS 32 * blocks of information were extracted when using CSS such as DEBUG_CSS
34 * which highlights elements that should be removed. 33 * which highlights elements that should be removed.
35 */ 34 */
36 final DART_REMOVED = "dart-removed"; 35 final DART_REMOVED = "dart-removed";
37 36
38 final DEBUG_CSS = """ 37 final DEBUG_CSS = """
39 <style type="text/css"> 38 <style type="text/css">
40 .dart-removed { 39 .dart-removed {
41 background-color: rgba(255, 0, 0, 0.5); 40 background-color: rgba(255, 0, 0, 0.5);
42 } 41 }
43 </style>"""; 42 </style>""";
44 43
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 375
377 Element parametersHeader; 376 Element parametersHeader;
378 Element returnValueHeader; 377 Element returnValueHeader;
379 for (final e in root.queryAll("h6")) { 378 for (final e in root.queryAll("h6")) {
380 if (e.text == 'Parameters') { 379 if (e.text == 'Parameters') {
381 parametersHeader = e; 380 parametersHeader = e;
382 } else if (e.text == 'Return value') { 381 } else if (e.text == 'Return value') {
383 returnValueHeader = e; 382 returnValueHeader = e;
384 } 383 }
385 } 384 }
386 385
387 if (parametersHeader != null) { 386 if (parametersHeader != null) {
388 int numEmptyParameters = 0; 387 int numEmptyParameters = 0;
389 final parameterDescriptions = root.queryAll("dd"); 388 final parameterDescriptions = root.queryAll("dd");
390 for (Element parameterDescription in parameterDescriptions) { 389 for (Element parameterDescription in parameterDescriptions) {
391 if (parameterDescription.text.trim().length == 0) { 390 if (parameterDescription.text.trim().length == 0) {
392 numEmptyParameters++; 391 numEmptyParameters++;
393 } 392 }
394 } 393 }
395 if (numEmptyParameters > 0 && 394 if (numEmptyParameters > 0 &&
396 numEmptyParameters == parameterDescriptions.length) { 395 numEmptyParameters == parameterDescriptions.length) {
397 // Remove the parameter list as it adds zero value as all descriptions 396 // Remove the parameter list as it adds zero value as all descriptions
398 // are empty. 397 // are empty.
399 parametersHeader.remove(); 398 parametersHeader.remove();
400 for (final e in root.queryAll("dl")) { 399 for (final e in root.queryAll("dl")) {
401 e.remove(); 400 e.remove();
402 } 401 }
403 } else if (parameterDescriptions.length == 0 && 402 } else if (parameterDescriptions.length == 0 &&
404 parametersHeader.nextElementSibling != null && 403 parametersHeader.nextElementSibling != null &&
405 parametersHeader.nextElementSibling.text.trim() == 'None.') { 404 parametersHeader.nextElementSibling.text.trim() == 'None.') {
406 // No need to display that the function takes 0 parameters. 405 // No need to display that the function takes 0 parameters.
407 parametersHeader.nextElementSibling.remove(); 406 parametersHeader.nextElementSibling.remove();
408 parametersHeader.remove(); 407 parametersHeader.remove();
409 } 408 }
410 } 409 }
411 410
412 // Heuristic: if the return value is a single word it is a type name not a 411 // Heuristic: if the return value is a single word it is a type name not a
(...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 // Put it back into the element. 1179 // Put it back into the element.
1181 a.attributes['href'] = href; 1180 a.attributes['href'] = href;
1182 } 1181 }
1183 1182
1184 if (!title.toLowerCase().contains(currentTypeTiny.toLowerCase())) { 1183 if (!title.toLowerCase().contains(currentTypeTiny.toLowerCase())) {
1185 bool foundMatch = false; 1184 bool foundMatch = false;
1186 // Test out if the title is really an HTML tag that matches the 1185 // Test out if the title is really an HTML tag that matches the
1187 // current class name. 1186 // current class name.
1188 for (String tag in [title.split(" ")[0], title.split(".").last()]) { 1187 for (String tag in [title.split(" ")[0], title.split(".").last()]) {
1189 try { 1188 try {
1190 dom.Element element = dom.document.createElement(tag); 1189 Element element = document.createElement(tag);
Jacob 2012/08/28 23:34:54 this isn't right... you want new Element.tag(tag)
eub 2012/08/29 19:29:39 Done.
1191 // TODO(jacobr): this is a really ugly way of doing this that will 1190 // TODO(jacobr): this is a really ugly way of doing this that will
1192 // stop working at some point soon. 1191 // stop working at some point soon.
1193 if (element.typeName == currentType) { 1192 if (element.typeName == currentType) {
1194 foundMatch = true; 1193 foundMatch = true;
1195 break; 1194 break;
1196 } 1195 }
1197 } catch(e) {} 1196 } catch(e) {}
1198 } 1197 }
1199 if (!foundMatch) { 1198 if (!foundMatch) {
1200 dbEntry['skipped'] = true; 1199 dbEntry['skipped'] = true;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 document.head.nodes.add(new Element.html(DEBUG_CSS)); 1299 document.head.nodes.add(new Element.html(DEBUG_CSS));
1301 1300
1302 onEnd(); 1301 onEnd();
1303 } 1302 }
1304 1303
1305 void main() { 1304 void main() {
1306 window.on.load.add(documentLoaded); 1305 window.on.load.add(documentLoaded);
1307 } 1306 }
1308 1307
1309 void documentLoaded(event) { 1308 void documentLoaded(event) {
1310 // Load the database of expected methods and properties with an 1309 // Load the database of expected methods and properties with an HttpRequest.
1311 // XMLHttpRequest. 1310 new HttpRequest.get('${window.location}.json', (req) {
1312 new XMLHttpRequest.get('${window.location}.json', (req) {
1313 data = JSON.parse(req.responseText); 1311 data = JSON.parse(req.responseText);
1314 dbEntry = {'members': [], 'srcUrl': pageUrl}; 1312 dbEntry = {'members': [], 'srcUrl': pageUrl};
1315 run(); 1313 run();
1316 }); 1314 });
1317 } 1315 }
OLDNEW
« no previous file with comments | « utils/apidoc/mdn/crawl.js ('k') | utils/apidoc/mdn/extract.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698