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

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

Issue 14088002: Attempt to re-commit Dartdoc exports. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | « sdk/lib/_internal/dartdoc/test/utils_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library apidoc; 15 library apidoc;
16 16
17 import 'dart:async'; 17 import 'dart:async';
18 import 'dart:io'; 18 import 'dart:io';
19 import 'dart:json' as json; 19 import 'dart:json' as json;
20 import 'dart:uri';
20 21
21 import 'html_diff.dart'; 22 import 'html_diff.dart';
22 23
23 // TODO(rnystrom): Use "package:" URL (#4968). 24 // TODO(rnystrom): Use "package:" URL (#4968).
24 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'; 25 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart';
25 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t'; 26 import '../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dar t';
26 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart'; 27 import '../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
27 import '../../sdk/lib/_internal/libraries.dart'; 28 import '../../sdk/lib/_internal/libraries.dart';
29 import 'package:pathos/path.dart' as pathos;
28 30
29 HtmlDiff _diff; 31 HtmlDiff _diff;
30 32
31 void main() { 33 void main() {
32 final args = new Options().arguments; 34 final args = new Options().arguments;
33 35
34 int mode = MODE_STATIC; 36 int mode = MODE_STATIC;
35 Path outputDir = new Path('docs'); 37 Path outputDir = new Path('docs');
36 bool generateAppCache = false; 38 bool generateAppCache = false;
37 39
38 List<String> excludedLibraries = <String>[]; 40 List<String> excludedLibraries = <String>[];
39 List<String> includedLibraries = <String>[]; 41 List<String> includedLibraries = <String>[];
40 Path packageRoot; 42 String packageRoot;
41 String version; 43 String version;
42 44
43 // Parse the command-line arguments. 45 // Parse the command-line arguments.
44 for (int i = 0; i < args.length; i++) { 46 for (int i = 0; i < args.length; i++) {
45 final arg = args[i]; 47 final arg = args[i];
46 48
47 switch (arg) { 49 switch (arg) {
48 case '--mode=static': 50 case '--mode=static':
49 mode = MODE_STATIC; 51 mode = MODE_STATIC;
50 break; 52 break;
51 53
52 case '--mode=live-nav': 54 case '--mode=live-nav':
53 mode = MODE_LIVE_NAV; 55 mode = MODE_LIVE_NAV;
54 break; 56 break;
55 57
56 case '--generate-app-cache=true': 58 case '--generate-app-cache=true':
57 generateAppCache = true; 59 generateAppCache = true;
58 break; 60 break;
59 61
60 default: 62 default:
61 if (arg.startsWith('--exclude-lib=')) { 63 if (arg.startsWith('--exclude-lib=')) {
62 excludedLibraries.add(arg.substring('--exclude-lib='.length)); 64 excludedLibraries.add(arg.substring('--exclude-lib='.length));
63 } else if (arg.startsWith('--include-lib=')) { 65 } else if (arg.startsWith('--include-lib=')) {
64 includedLibraries.add(arg.substring('--include-lib='.length)); 66 includedLibraries.add(arg.substring('--include-lib='.length));
65 } else if (arg.startsWith('--out=')) { 67 } else if (arg.startsWith('--out=')) {
66 outputDir = new Path(arg.substring('--out='.length)); 68 outputDir = new Path(arg.substring('--out='.length));
67 } else if (arg.startsWith('--package-root=')) { 69 } else if (arg.startsWith('--package-root=')) {
68 packageRoot = new Path(arg.substring('--package-root='.length)); 70 packageRoot = arg.substring('--package-root='.length);
69 } else if (arg.startsWith('--version=')) { 71 } else if (arg.startsWith('--version=')) {
70 version = arg.substring('--version='.length); 72 version = arg.substring('--version='.length);
71 } else { 73 } else {
72 print('Unknown option: $arg'); 74 print('Unknown option: $arg');
73 return; 75 return;
74 } 76 }
75 break; 77 break;
76 } 78 }
77 } 79 }
78 80
(...skipping 18 matching lines...) Expand all
97 99
98 print('Cross-referencing dart:html...'); 100 print('Cross-referencing dart:html...');
99 // TODO(amouravski): move HtmlDiff inside of the future chain below to re-use 101 // TODO(amouravski): move HtmlDiff inside of the future chain below to re-use
100 // the MirrorSystem already analyzed. 102 // the MirrorSystem already analyzed.
101 _diff = new HtmlDiff(printWarnings:false); 103 _diff = new HtmlDiff(printWarnings:false);
102 Future htmlDiff = _diff.run(libPath); 104 Future htmlDiff = _diff.run(libPath);
103 105
104 // TODO(johnniwinther): Libraries for the compilation seem to be more like 106 // TODO(johnniwinther): Libraries for the compilation seem to be more like
105 // URIs. Perhaps Path should have a toURI() method. 107 // URIs. Perhaps Path should have a toURI() method.
106 // Add all of the core libraries. 108 // Add all of the core libraries.
107 final apidocLibraries = <Path>[]; 109 final apidocLibraries = <Uri>[];
108 LIBRARIES.forEach((String name, LibraryInfo info) { 110 LIBRARIES.forEach((String name, LibraryInfo info) {
109 if (info.documented) { 111 if (info.documented) {
110 apidocLibraries.add(new Path('dart:$name')); 112 apidocLibraries.add(Uri.parse('dart:$name'));
111 } 113 }
112 }); 114 });
113 115
114 // TODO(amouravski): This code is really wonky. 116 // TODO(amouravski): This code is really wonky.
115 var lister = new Directory.fromPath(scriptDir.append('../../pkg')).list(); 117 var lister = new Directory.fromPath(scriptDir.append('../../pkg')).list();
116 lister.listen((entity) { 118 lister.listen((entity) {
117 if (entity is Directory) { 119 if (entity is Directory) {
118 var path = new Path(entity.path); 120 var path = new Path(entity.path);
119 var libName = path.filename; 121 var libName = path.filename;
120 var libPath = path.append('lib/$libName.dart'); 122 var libPath = path.append('lib/$libName.dart');
121 123
122 // Ignore some libraries. 124 // Ignore some libraries.
123 if (excludedLibraries.contains(libName)) { 125 if (excludedLibraries.contains(libName)) {
124 return; 126 return;
125 } 127 }
126 128
127 // Ignore hidden directories (like .svn) as well as pkg.xcodeproj. 129 // Ignore hidden directories (like .svn) as well as pkg.xcodeproj.
128 if (libName.startsWith('.') || libName.endsWith('.xcodeproj')) { 130 if (libName.startsWith('.') || libName.endsWith('.xcodeproj')) {
129 return; 131 return;
130 } 132 }
131 133
132 if (new File.fromPath(libPath).existsSync()) { 134 if (new File.fromPath(libPath).existsSync()) {
133 apidocLibraries.add(libPath); 135 apidocLibraries.add(_pathToFileUri(libPath.toNativePath()));
134 includedLibraries.add(libName); 136 includedLibraries.add(libName);
135 } else { 137 } else {
136 print('Warning: could not find package at $path'); 138 print('Warning: could not find package at $path');
137 } 139 }
138 } 140 }
139 }, onDone: () { 141 }, onDone: () {
140 final apidoc = new Apidoc(mdn, outputDir, mode, generateAppCache, 142 final apidoc = new Apidoc(mdn, outputDir, mode, generateAppCache,
141 excludedLibraries, version); 143 excludedLibraries, version);
142 apidoc.dartdocPath = 144 apidoc.dartdocPath =
143 scriptDir.append('../../sdk/lib/_internal/dartdoc/'); 145 scriptDir.append('../../sdk/lib/_internal/dartdoc/');
144 // Select the libraries to include in the produced documentation: 146 // Select the libraries to include in the produced documentation:
145 apidoc.includeApi = true; 147 apidoc.includeApi = true;
146 apidoc.includedLibraries = includedLibraries; 148 apidoc.includedLibraries = includedLibraries;
147 149
148 // TODO(amouravski): make apidoc use roughly the same flow as bin/dartdoc. 150 // TODO(amouravski): make apidoc use roughly the same flow as bin/dartdoc.
149 Future.wait([copiedStatic, copiedApiDocStatic, htmlDiff]) 151 Future.wait([copiedStatic, copiedApiDocStatic, htmlDiff])
150 .then((_) => apidoc.documentLibraries( apidocLibraries, libPath, 152 .then((_) => apidoc.documentLibraries(apidocLibraries, libPath,
151 packageRoot)) 153 packageRoot))
152 .then((_) => compileScript(mode, outputDir, libPath)) 154 .then((_) => compileScript(mode, outputDir, libPath))
153 .then((_) => print(apidoc.status)) 155 .then((_) => print(apidoc.status))
154 .catchError((e) { 156 .catchError((e) {
155 print('Error: generation failed: ${e}'); 157 print('Error: generation failed: ${e}');
156 apidoc.cleanup(); 158 apidoc.cleanup();
157 exit(1); 159 exit(1);
158 }) 160 })
159 .whenComplete(() => apidoc.cleanup()); 161 .whenComplete(() => apidoc.cleanup());
160 }); 162 });
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 final typeName = member.owner.simpleName; 442 final typeName = member.owner.simpleName;
441 var memberName = '$typeName.${member.simpleName}'; 443 var memberName = '$typeName.${member.simpleName}';
442 if (member is MethodMirror && (member.isConstructor || member.isFactory)) { 444 if (member is MethodMirror && (member.isConstructor || member.isFactory)) {
443 final separator = member.constructorName == '' ? '' : '.'; 445 final separator = member.constructorName == '' ? '' : '.';
444 memberName = 'new $typeName$separator${member.constructorName}'; 446 memberName = 'new $typeName$separator${member.constructorName}';
445 } 447 }
446 448
447 return a(memberUrl(member), memberName); 449 return a(memberUrl(member), memberName);
448 } 450 }
449 } 451 }
452
453 /** Converts a local path string to a `file:` [Uri]. */
454 Uri _pathToFileUri(String path) {
455 path = pathos.absolute(path);
456 if (Platform.operatingSystem != 'windows') {
457 return Uri.parse('file://$path');
458 } else {
459 return Uri.parse('file:///${path.replaceAll("\\", "/")}');
460 }
461 }
462
OLDNEW
« no previous file with comments | « sdk/lib/_internal/dartdoc/test/utils_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698