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

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

Issue 10809035: Several new features and improvements for dartdoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * This generates the reference documentation for the core libraries that come 6 * This generates the reference documentation for the core libraries that come
7 * with dart. It is built on top of dartdoc, which is a general-purpose library 7 * with dart. It is built on top of dartdoc, which is a general-purpose library
8 * for generating docs from any Dart code. This library extends that to include 8 * for generating docs from any Dart code. This library extends that to include
9 * additional information and styling specific to our standard library. 9 * additional information and styling specific to our standard library.
10 * 10 *
11 * Usage: 11 * Usage:
12 * 12 *
13 * $ dart apidoc.dart [--out=<output directory>] 13 * $ dart apidoc.dart [--out=<output directory>]
14 */ 14 */
15 15
16 #library('apidoc'); 16 #library('apidoc');
17 17
18 #import('dart:io'); 18 #import('dart:io');
19 #import('dart:json'); 19 #import('dart:json');
20 #import('html_diff.dart'); 20 #import('html_diff.dart');
21 #import('../../lib/dartdoc/mirrors/mirrors.dart'); 21 #import('../../lib/dartdoc/mirrors/mirrors.dart');
22 #import('../../lib/dartdoc/mirrors/mirrors_util.dart'); 22 #import('../../lib/dartdoc/mirrors/mirrors_util.dart');
23 #import('../../lib/dartdoc/dartdoc.dart', prefix: 'doc'); 23 #import('../../lib/dartdoc/dartdoc.dart', prefix: 'doc');
24 #import('../../lib/compiler/implementation/library_map.dart');
24 25
25 HtmlDiff _diff; 26 HtmlDiff _diff;
26 27
27 void main() { 28 void main() {
28 final args = new Options().arguments; 29 final args = new Options().arguments;
29 30
30 int mode = doc.MODE_STATIC; 31 int mode = doc.MODE_STATIC;
31 Path outputDir = const Path('docs'); 32 Path outputDir = const Path('docs');
32 bool generateAppCache = false; 33 bool generateAppCache = false;
33 34
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 htmldoc.documentLibraries( 96 htmldoc.documentLibraries(
96 <Path>[doc.scriptDir.append('../../lib/html/doc/html.dartdoc')], 97 <Path>[doc.scriptDir.append('../../lib/html/doc/html.dartdoc')],
97 doc.libPath); 98 doc.libPath);
98 print('Processing handwritten HTML documentation...'); 99 print('Processing handwritten HTML documentation...');
99 100
100 // Process libraries. 101 // Process libraries.
101 102
102 // TODO(johnniwinther): Libraries for the compilation seem to be more like 103 // TODO(johnniwinther): Libraries for the compilation seem to be more like
103 // URIs. Perhaps Path should have a toURI() method. 104 // URIs. Perhaps Path should have a toURI() method.
104 // Add all of the core libraries. 105 // Add all of the core libraries.
105 var apidocLibraries = <Path>[ 106 var apidocLibraries = new List<Path>();
floitsch 2012/07/23 10:43:56 = <Path>[];
Johnni Winther 2012/07/24 08:49:16 Done.
106 const Path('dart:core'), 107 DART2JS_LIBRARY_MAP.forEach((String name, LibraryInfo info) {
107 const Path('dart:coreimpl'), 108 if (!info.internal) {
108 const Path('dart:crypto'), 109 apidocLibraries.add(new Path('dart:$name'));
109 const Path('dart:html'), 110 }
110 const Path('dart:io'), 111 });
111 const Path('dart:isolate'), 112 apidocLibraries.add(doc.scriptDir.append('../../lib/math/math.dart'));
112 const Path('dart:json'), 113 apidocLibraries.add(doc.scriptDir.append('../../lib/unittest/unittest.dart'));
113 doc.scriptDir.append('../../lib/math/math.dart'), 114 apidocLibraries.add(doc.scriptDir.append('../../lib/i18n/intl.dart'));
114 doc.scriptDir.append('../../lib/unittest/unittest.dart'), 115
115 doc.scriptDir.append('../../lib/i18n/intl.dart'),
116 const Path('dart:uri'),
117 const Path('dart:utf'),
118 const Path('dart:web'),
119 ];
120 print('Generating docs...'); 116 print('Generating docs...');
121 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache); 117 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache);
122 // Select the libraries to include in the produced documentation: 118 // Select the libraries to include in the produced documentation:
123 apidoc.libraries = <String>[ 119 apidoc.includeAPI = true;
124 'core', 120 apidoc.includeLibraries = <String>[
125 'coreimpl',
126 'crypto',
127 'html',
128 'io',
129 'dart:isolate',
130 'json',
131 'math',
132 'unittest', 121 'unittest',
133 'intl', 122 'intl',
134 'uri',
135 'utf',
136 'web',
137 ]; 123 ];
138 124
139 Futures.wait([compiled, copiedStatic, copiedApiDocStatic]).then((_) { 125 Futures.wait([compiled, copiedStatic, copiedApiDocStatic]).then((_) {
140 apidoc.documentLibraries(apidocLibraries, doc.libPath); 126 apidoc.documentLibraries(apidocLibraries, doc.libPath);
141 }); 127 });
142 } 128 }
143 129
144 /** 130 /**
145 * This class is purely here to scrape handwritten HTML documentation. 131 * This class is purely here to scrape handwritten HTML documentation.
146 * This scraped documentation will later be merged with the generated 132 * This scraped documentation will later be merged with the generated
(...skipping 18 matching lines...) Expand all
165 } 151 }
166 152
167 // Suppress any actual writing to file. This is only for analysis. 153 // Suppress any actual writing to file. This is only for analysis.
168 void endFile() { 154 void endFile() {
169 } 155 }
170 156
171 void write(String s) { 157 void write(String s) {
172 } 158 }
173 159
174 String getRecordedLibraryComment(LibraryMirror library) { 160 String getRecordedLibraryComment(LibraryMirror library) {
175 if (library.simpleName() == 'html') { 161 if (library.simpleName() == HTML_LIBRARY_NAME) {
176 return libraryComment; 162 return libraryComment;
177 } 163 }
178 return null; 164 return null;
179 } 165 }
180 166
181 String getRecordedTypeComment(TypeMirror type) { 167 String getRecordedTypeComment(TypeMirror type) {
182 if (typeComments.containsKey(type.qualifiedName())) { 168 if (typeComments.containsKey(type.qualifiedName())) {
183 return typeComments[type.qualifiedName()]; 169 return typeComments[type.qualifiedName()];
184 } 170 }
185 return null; 171 return null;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 super.docLibrary(library); 343 super.docLibrary(library);
358 } 344 }
359 345
360 /** Override definition from parent class to strip out annotation tags. */ 346 /** Override definition from parent class to strip out annotation tags. */
361 String commentToHtml(String comment) { 347 String commentToHtml(String comment) {
362 return super.commentToHtml( 348 return super.commentToHtml(
363 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); 349 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), ''));
364 } 350 }
365 351
366 String getLibraryComment(LibraryMirror library) { 352 String getLibraryComment(LibraryMirror library) {
367 if (library.simpleName() == 'html') { 353 if (library.simpleName() == HTML_LIBRARY_NAME) {
368 return htmldoc.libraryComment; 354 return htmldoc.libraryComment;
369 } 355 }
370 return super.getLibraryComment(library); 356 return super.getLibraryComment(library);
371 } 357 }
372 358
373 String getTypeComment(TypeMirror type) { 359 String getTypeComment(TypeMirror type) {
374 return _mergeDocs( 360 return _mergeDocs(
375 includeMdnTypeComment(type), super.getTypeComment(type), 361 includeMdnTypeComment(type), super.getTypeComment(type),
376 htmldoc.getRecordedTypeComment(type)); 362 htmldoc.getRecordedTypeComment(type));
377 } 363 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 </p> 431 </p>
446 '''); 432 ''');
447 } 433 }
448 } 434 }
449 435
450 /** 436 /**
451 * Gets the MDN-scraped docs for [type], or `null` if this type isn't 437 * Gets the MDN-scraped docs for [type], or `null` if this type isn't
452 * scraped from MDN. 438 * scraped from MDN.
453 */ 439 */
454 includeMdnTypeComment(TypeMirror type) { 440 includeMdnTypeComment(TypeMirror type) {
455 if (type.library().simpleName() == 'html') { 441 if (type.library().simpleName() == HTML_LIBRARY_NAME) {
456 // If it's an HTML type, try to map it to a base DOM type so we can find 442 // If it's an HTML type, try to map it to a base DOM type so we can find
457 // the MDN docs. 443 // the MDN docs.
458 final domTypes = _diff.htmlTypesToDom[type.qualifiedName()]; 444 final domTypes = _diff.htmlTypesToDom[type.qualifiedName()];
459 445
460 // Couldn't find a DOM type. 446 // Couldn't find a DOM type.
461 if ((domTypes == null) || (domTypes.length != 1)) return null; 447 if ((domTypes == null) || (domTypes.length != 1)) return null;
462 448
463 // Use the corresponding DOM type when searching MDN. 449 // Use the corresponding DOM type when searching MDN.
464 // TODO(rnystrom): Shame there isn't a simpler way to get the one item 450 // TODO(rnystrom): Shame there isn't a simpler way to get the one item
465 // out of a singleton Set. 451 // out of a singleton Set.
466 type = domTypes.iterator().next(); 452 type = domTypes.iterator().next();
467 } else if (type.library().simpleName() != 'dom') { 453 } else if (type.library().simpleName() != DOM_LIBRARY_NAME) {
468 // Not a DOM type. 454 // Not a DOM type.
469 return null; 455 return null;
470 } 456 }
471 457
472 final mdnType = mdn[type.simpleName()]; 458 final mdnType = mdn[type.simpleName()];
473 if (mdnType == null) return null; 459 if (mdnType == null) return null;
474 if (mdnType['skipped'] != null) return null; 460 if (mdnType['skipped'] != null) return null;
475 461
476 // Remember which MDN page we're using so we can attribute it. 462 // Remember which MDN page we're using so we can attribute it.
477 mdnUrl = mdnType['srcUrl']; 463 mdnUrl = mdnType['srcUrl'];
478 return mdnType['summary']; 464 return mdnType['summary'];
479 } 465 }
480 466
481 /** 467 /**
482 * Gets the MDN-scraped docs for [member], or `null` if this type isn't 468 * Gets the MDN-scraped docs for [member], or `null` if this type isn't
483 * scraped from MDN. 469 * scraped from MDN.
484 */ 470 */
485 includeMdnMemberComment(MemberMirror member) { 471 includeMdnMemberComment(MemberMirror member) {
486 var library = findLibrary(member); 472 var library = findLibrary(member);
487 if (library.simpleName() == 'html') { 473 if (library.simpleName() == HTML_LIBRARY_NAME) {
488 // If it's an HTML type, try to map it to a base DOM type so we can find 474 // If it's an HTML type, try to map it to a base DOM type so we can find
489 // the MDN docs. 475 // the MDN docs.
490 final domMembers = _diff.htmlToDom[member.qualifiedName()]; 476 final domMembers = _diff.htmlToDom[member.qualifiedName()];
491 477
492 // Couldn't find a DOM type. 478 // Couldn't find a DOM type.
493 if ((domMembers == null) || (domMembers.length != 1)) return null; 479 if ((domMembers == null) || (domMembers.length != 1)) return null;
494 480
495 // Use the corresponding DOM member when searching MDN. 481 // Use the corresponding DOM member when searching MDN.
496 // TODO(rnystrom): Shame there isn't a simpler way to get the one item 482 // TODO(rnystrom): Shame there isn't a simpler way to get the one item
497 // out of a singleton Set. 483 // out of a singleton Set.
498 member = domMembers.iterator().next(); 484 member = domMembers.iterator().next();
499 } else if (library.simpleName() != 'dom') { 485 } else if (library.simpleName() != DOM_LIBRARY_NAME) {
500 // Not a DOM type. 486 // Not a DOM type.
501 return null; 487 return null;
502 } 488 }
503 489
504 // Ignore top-level functions. 490 // Ignore top-level functions.
505 if (member.isTopLevel) return null; 491 if (member.isTopLevel) return null;
506 492
507 final mdnType = mdn[member.surroundingDeclaration().simpleName()]; 493 final mdnType = mdn[member.surroundingDeclaration().simpleName()];
508 if (mdnType == null) return null; 494 if (mdnType == null) return null;
509 var nameToFind = member.simpleName(); 495 var nameToFind = member.simpleName();
(...skipping 20 matching lines...) Expand all
530 final typeName = member.surroundingDeclaration().simpleName(); 516 final typeName = member.surroundingDeclaration().simpleName();
531 var memberName = '$typeName.${member.simpleName()}'; 517 var memberName = '$typeName.${member.simpleName()}';
532 if (member is MethodMirror && (member.isConstructor || member.isFactory)) { 518 if (member is MethodMirror && (member.isConstructor || member.isFactory)) {
533 final separator = member.constructorName == '' ? '' : '.'; 519 final separator = member.constructorName == '' ? '' : '.';
534 memberName = 'new $typeName$separator${member.constructorName}'; 520 memberName = 'new $typeName$separator${member.constructorName}';
535 } 521 }
536 522
537 return a(memberUrl(member), memberName); 523 return a(memberUrl(member), memberName);
538 } 524 }
539 } 525 }
OLDNEW
« tools/create_sdk.py ('K') | « tools/create_sdk.py ('k') | utils/apidoc/html_diff.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698