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

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

Issue 10780030: Dartdoc and apidoc updated to use Path. (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 24
25 HtmlDiff _diff; 25 HtmlDiff _diff;
26 26
27 void main() { 27 void main() {
Bill Hesse 2012/07/17 13:42:13 Couldn't we unify this and dartdoc.dart, perhaps w
Johnni Winther 2012/07/19 08:37:07 Dartdoc and apidoc are assimilating with the inten
28 final args = new Options().arguments; 28 final args = new Options().arguments;
29 29
30 int mode = doc.MODE_STATIC; 30 int mode = doc.MODE_STATIC;
31 String outputDir = 'docs'; 31 Path outputDir = const Path('docs');
32 String compilerPath;
33 bool generateAppCache = false; 32 bool generateAppCache = false;
34 33
35 // Parse the command-line arguments. 34 // Parse the command-line arguments.
36 for (int i = 0; i < args.length; i++) { 35 for (int i = 0; i < args.length; i++) {
37 final arg = args[i]; 36 final arg = args[i];
38 37
39 switch (arg) { 38 switch (arg) {
40 case '--mode=static': 39 case '--mode=static':
41 mode = doc.MODE_STATIC; 40 mode = doc.MODE_STATIC;
42 break; 41 break;
43 42
44 case '--mode=live-nav': 43 case '--mode=live-nav':
45 mode = doc.MODE_LIVE_NAV; 44 mode = doc.MODE_LIVE_NAV;
46 break; 45 break;
47 46
48 case '--generate-app-cache=true': 47 case '--generate-app-cache=true':
49 generateAppCache = true; 48 generateAppCache = true;
50 break; 49 break;
51 50
52 default: 51 default:
53 if (arg.startsWith('--out=')) { 52 if (arg.startsWith('--out=')) {
54 outputDir = arg.substring('--out='.length); 53 outputDir = new Path.fromNative(arg.substring('--out='.length));
55 } else if (arg.startsWith('--compiler=')) {
56 compilerPath = arg.substring('--compiler='.length);
57 } else { 54 } else {
58 print('Unknown option: $arg'); 55 print('Unknown option: $arg');
59 return; 56 return;
60 } 57 }
61 break; 58 break;
62 } 59 }
63 } 60 }
64 61
65 final libPath = '${doc.scriptDir}/../../';
66
67 doc.cleanOutputDirectory(outputDir); 62 doc.cleanOutputDirectory(outputDir);
68 63
69 // Compile the client-side code to JS. 64 // Compile the client-side code to JS.
70 // TODO(bob): Right path. 65 // TODO(bob): Right path.
71 66
72 final clientScript = (mode == doc.MODE_STATIC) ? 67 final clientScript = (mode == doc.MODE_STATIC) ?
73 'static' : 'live-nav'; 68 'static' : 'live-nav';
74 doc.compileScript( 69 final Future compiled = doc.compileScript(
75 '${doc.scriptDir}/../../lib/dartdoc/client-$clientScript.dart', 70 doc.scriptDir.append('../../lib/dartdoc/client-$clientScript.dart'),
76 '${outputDir}/client-$clientScript.js'); 71 outputDir.append('client-$clientScript.js'));
77 72
78 // TODO(rnystrom): Use platform-specific path separator. 73 // TODO(rnystrom): Use platform-specific path separator.
79 // The basic dartdoc-provided static content. 74 // The basic dartdoc-provided static content.
80 final Future copiedStatic = doc.copyFiles( 75 final Future copiedStatic = doc.copyFiles(
81 '${doc.scriptDir}/../../lib/dartdoc/static', outputDir); 76 doc.scriptDir.append('../../lib/dartdoc/static'),
77 outputDir);
82 78
83 // The apidoc-specific static content. 79 // The apidoc-specific static content.
84 final Future copiedApiDocStatic = doc.copyFiles('${doc.scriptDir}/static', 80 final Future copiedApiDocStatic = doc.copyFiles(
81 doc.scriptDir.append('static'),
85 outputDir); 82 outputDir);
86 83
87 print('Parsing MDN data...'); 84 print('Parsing MDN data...');
88 final mdnFile = new File('${doc.scriptDir}/mdn/database.json'); 85 final mdnFile = new File.fromPath(doc.scriptDir.append('mdn/database.json'));
89 final mdn = JSON.parse(mdnFile.readAsTextSync()); 86 final mdn = JSON.parse(mdnFile.readAsTextSync());
90 87
91 print('Cross-referencing dart:html...'); 88 print('Cross-referencing dart:html...');
92 HtmlDiff.initialize(libPath); 89 HtmlDiff.initialize(doc.libPath);
93 _diff = new HtmlDiff(printWarnings:false); 90 _diff = new HtmlDiff(printWarnings:false);
94 _diff.run(); 91 _diff.run();
95 92
96 // Process handwritten HTML documentation. 93 // Process handwritten HTML documentation.
97 final htmldoc = new Htmldoc(); 94 final htmldoc = new Htmldoc();
98 htmldoc.documentLibraries( 95 htmldoc.documentLibraries(
99 <String>['${doc.scriptDir}/../../lib/html/doc/html.dartdoc'], 96 <Path>[doc.scriptDir.append('../../lib/html/doc/html.dartdoc')],
100 libPath); 97 doc.libPath);
101 print('Processing handwritten HTML documentation...'); 98 print('Processing handwritten HTML documentation...');
102 99
103 // Process libraries. 100 // Process libraries.
104 101
102 // TODO(johnniwinther): Libraries for the compilation seem to be more like
103 // URIs. Perhaps Path should have a toURI() method.
Bill Hesse 2012/07/17 13:42:13 Why not use URI instead of Path here?
Johnni Winther 2012/07/19 08:37:07 Uri does not fit well either. Partially due to the
105 // Add all of the core libraries. 104 // Add all of the core libraries.
106 var apidocLibraries = <String>[ 105 var apidocLibraries = <Path>[
107 'dart:core', 106 const Path('dart:core'),
108 'dart:coreimpl', 107 const Path('dart:coreimpl'),
109 'dart:crypto', 108 const Path('dart:crypto'),
110 'dart:html', 109 const Path('dart:html'),
111 'dart:io', 110 const Path('dart:io'),
112 'dart:isolate', 111 const Path('dart:isolate'),
113 'dart:json', 112 const Path('dart:json'),
114 '${doc.scriptDir}/../../lib/math/math.dart', 113 doc.scriptDir.append('../../lib/math/math.dart'),
115 '${doc.scriptDir}/../../lib/unittest/unittest.dart', 114 doc.scriptDir.append('../../lib/unittest/unittest.dart'),
116 '${doc.scriptDir}/../../lib/i18n/intl.dart', 115 doc.scriptDir.append('../../lib/i18n/intl.dart'),
117 'dart:uri', 116 const Path('dart:uri'),
118 'dart:utf', 117 const Path('dart:utf'),
119 'dart:web', 118 const Path('dart:web'),
120 ]; 119 ];
121 print('Generating docs...'); 120 print('Generating docs...');
122 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache); 121 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache);
123 // Select the libraries to include in the produced documentation: 122 // Select the libraries to include in the produced documentation:
124 apidoc.libraries = <String>[ 123 apidoc.libraries = <String>[
125 'core', 124 'core',
126 'coreimpl', 125 'coreimpl',
127 'crypto', 126 'crypto',
128 'html', 127 'html',
129 'io', 128 'io',
130 'dart:isolate', 129 'dart:isolate',
131 'json', 130 'json',
132 'math', 131 'math',
133 'unittest', 132 'unittest',
134 'intl', 133 'intl',
135 'uri', 134 'uri',
136 'utf', 135 'utf',
137 'web', 136 'web',
138 ]; 137 ];
139 138
140 Futures.wait([copiedStatic, copiedApiDocStatic]).then((_) { 139 Futures.wait([compiled, copiedStatic, copiedApiDocStatic]).then((_) {
141 apidoc.documentLibraries(apidocLibraries, libPath); 140 apidoc.documentLibraries(apidocLibraries, doc.libPath);
142 }); 141 });
143 } 142 }
144 143
145 /** 144 /**
146 * This class is purely here to scrape handwritten HTML documentation. 145 * This class is purely here to scrape handwritten HTML documentation.
147 * This scraped documentation will later be merged with the generated 146 * This scraped documentation will later be merged with the generated
148 * HTML library. 147 * HTML library.
149 */ 148 */
150 class Htmldoc extends doc.Dartdoc { 149 class Htmldoc extends doc.Dartdoc {
151 String libraryComment; 150 String libraryComment;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 243
245 static final disqusShortname = 'dartapidocs'; 244 static final disqusShortname = 'dartapidocs';
246 245
247 /** 246 /**
248 * The URL to the page on MDN that content was pulled from for the current 247 * The URL to the page on MDN that content was pulled from for the current
249 * type being documented. Will be `null` if the type doesn't use any MDN 248 * type being documented. Will be `null` if the type doesn't use any MDN
250 * content. 249 * content.
251 */ 250 */
252 String mdnUrl; 251 String mdnUrl;
253 252
254 Apidoc(this.mdn, this.htmldoc, String outputDir, int mode, 253 Apidoc(this.mdn, this.htmldoc, Path outputDir, int mode,
255 bool generateAppCache) { 254 bool generateAppCache) {
256 this.outputDir = outputDir; 255 this.outputDir = outputDir;
257 this.mode = mode; 256 this.mode = mode;
258 this.generateAppCache = generateAppCache; 257 this.generateAppCache = generateAppCache;
259 258
260 mainTitle = 'Dart API Reference'; 259 mainTitle = 'Dart API Reference';
261 mainUrl = 'http://dartlang.org'; 260 mainUrl = 'http://dartlang.org';
262 261
263 final note = 'http://code.google.com/policies.html#restrictions'; 262 final note = 'http://code.google.com/policies.html#restrictions';
264 final cca = 'http://creativecommons.org/licenses/by/3.0/'; 263 final cca = 'http://creativecommons.org/licenses/by/3.0/';
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // Not a DOM type. 500 // Not a DOM type.
502 return null; 501 return null;
503 } 502 }
504 503
505 // Ignore top-level functions. 504 // Ignore top-level functions.
506 if (member.isTopLevel) return null; 505 if (member.isTopLevel) return null;
507 506
508 final mdnType = mdn[member.surroundingDeclaration().simpleName()]; 507 final mdnType = mdn[member.surroundingDeclaration().simpleName()];
509 if (mdnType == null) return null; 508 if (mdnType == null) return null;
510 var nameToFind = member.simpleName(); 509 var nameToFind = member.simpleName();
511 if (nameToFind.startsWith(GET_PREFIX)) {
512 nameToFind = nameToFind.substring(GET_PREFIX.length);
513 }
514 var mdnMember = null; 510 var mdnMember = null;
515 for (final candidateMember in mdnType['members']) { 511 for (final candidateMember in mdnType['members']) {
516 if (candidateMember['name'] == nameToFind) { 512 if (candidateMember['name'] == nameToFind) {
517 mdnMember = candidateMember; 513 mdnMember = candidateMember;
518 break; 514 break;
519 } 515 }
520 } 516 }
521 517
522 if (mdnMember == null) return null; 518 if (mdnMember == null) return null;
523 519
524 // Remember which MDN page we're using so we can attribute it. 520 // Remember which MDN page we're using so we can attribute it.
525 mdnUrl = mdnType['srcUrl']; 521 mdnUrl = mdnType['srcUrl'];
526 return mdnMember['help']; 522 return mdnMember['help'];
527 } 523 }
528 524
529 /** 525 /**
530 * Returns a link to [member], relative to a type page that may be in a 526 * Returns a link to [member], relative to a type page that may be in a
531 * different library than [member]. 527 * different library than [member].
532 */ 528 */
533 String _linkMember(MemberMirror member) { 529 String _linkMember(MemberMirror member) {
534 final typeName = member.surroundingDeclaration().simpleName(); 530 final typeName = member.surroundingDeclaration().simpleName();
535 var memberName = '$typeName.${member.simpleName()}'; 531 var memberName = '$typeName.${member.simpleName()}';
536 if (member.isConstructor || member.isFactory) { 532 if (member is MethodMirror && (member.isConstructor || member.isFactory)) {
537 final separator = member.constructorName == '' ? '' : '.'; 533 final separator = member.constructorName == '' ? '' : '.';
538 memberName = 'new $typeName$separator${member.constructorName}'; 534 memberName = 'new $typeName$separator${member.constructorName}';
539 } 535 }
540 536
541 return a(memberUrl(member), memberName); 537 return a(memberUrl(member), memberName);
542 } 538 }
543 } 539 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698