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

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 22831008: Added an introduction option by passing in a file with markdown. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | « pkg/docgen/bin/sdk-introduction.md ('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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 * **docgen** is a tool for creating machine readable representations of Dart 6 * **docgen** is a tool for creating machine readable representations of Dart
7 * code metadata, including: classes, members, comments and annotations. 7 * code metadata, including: classes, members, comments and annotations.
8 * 8 *
9 * docgen is run on a `.dart` file or a directory containing `.dart` files. 9 * docgen is run on a `.dart` file or a directory containing `.dart` files.
10 * 10 *
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 /// Resolves reference links in doc comments. 58 /// Resolves reference links in doc comments.
59 markdown.Resolver linkResolver; 59 markdown.Resolver linkResolver;
60 60
61 /// Index of all indexable items. This also ensures that no class is 61 /// Index of all indexable items. This also ensures that no class is
62 /// created more than once. 62 /// created more than once.
63 Map<String, Indexable> entityMap = new Map<String, Indexable>(); 63 Map<String, Indexable> entityMap = new Map<String, Indexable>();
64 64
65 /// This is set from the command line arguments flag --include-private 65 /// This is set from the command line arguments flag --include-private
66 bool _includePrivate = false; 66 bool _includePrivate = false;
67 67
68 // TODO(janicejl): Make MDN content generic or pluggable. Maybe move
69 // MDN-specific code to its own library that is imported into the default impl?
68 /// Map of all the comments for dom elements from MDN. 70 /// Map of all the comments for dom elements from MDN.
69 Map _mdn; 71 Map _mdn;
70 72
71 /** 73 /**
72 * Docgen constructor initializes the link resolver for markdown parsing. 74 * Docgen constructor initializes the link resolver for markdown parsing.
73 * Also initializes the command line arguments. 75 * Also initializes the command line arguments.
74 * 76 *
75 * [packageRoot] is the packages directory of the directory being analyzed. 77 * [packageRoot] is the packages directory of the directory being analyzed.
76 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will 78 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will
77 * also be documented. 79 * also be documented.
78 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. 80 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented.
79 * This option is useful when only the SDK libraries are needed. 81 * This option is useful when only the SDK libraries are needed.
80 * 82 *
81 * Returns `true` if docgen sucessfuly completes. 83 * Returns `true` if docgen sucessfuly completes.
82 */ 84 */
83 Future<bool> docgen(List<String> files, {String packageRoot, 85 Future<bool> docgen(List<String> files, {String packageRoot,
84 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, 86 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false,
85 bool parseSdk: false, bool append: false}) { 87 bool parseSdk: false, bool append: false, String introduction: ''}) {
86 _includePrivate = includePrivate; 88 _includePrivate = includePrivate;
87 if (!append) { 89 if (!append) {
88 var dir = new Directory('docs'); 90 var dir = new Directory('docs');
89 if (dir.existsSync()) dir.deleteSync(recursive: true); 91 if (dir.existsSync()) dir.deleteSync(recursive: true);
90 } 92 }
91 93
92 if (packageRoot == null && !parseSdk) { 94 if (packageRoot == null && !parseSdk) {
93 var type = FileSystemEntity.typeSync(files.first); 95 var type = FileSystemEntity.typeSync(files.first);
94 if (type == FileSystemEntityType.DIRECTORY) { 96 if (type == FileSystemEntityType.DIRECTORY) {
95 packageRoot = _findPackageRoot(files.first); 97 packageRoot = _findPackageRoot(files.first);
96 } else if (type == FileSystemEntityType.FILE) { 98 } else if (type == FileSystemEntityType.FILE) {
97 logger.warning('WARNING: No package root defined. If Docgen fails, try ' 99 logger.warning('WARNING: No package root defined. If Docgen fails, try '
98 'again by setting the --package-root option.'); 100 'again by setting the --package-root option.');
99 } 101 }
100 } 102 }
101 logger.info('Package Root: ${packageRoot}'); 103 logger.info('Package Root: ${packageRoot}');
102 linkResolver = (name) => 104 linkResolver = (name) =>
103 fixReference(name, _currentLibrary, _currentClass, _currentMember); 105 fixReference(name, _currentLibrary, _currentClass, _currentMember);
104 106
105 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) 107 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk)
106 .then((MirrorSystem mirrorSystem) { 108 .then((MirrorSystem mirrorSystem) {
107 if (mirrorSystem.libraries.isEmpty) { 109 if (mirrorSystem.libraries.isEmpty) {
108 throw new StateError('No library mirrors were created.'); 110 throw new StateError('No library mirrors were created.');
109 } 111 }
110 _documentLibraries(mirrorSystem.libraries.values,includeSdk: includeSdk, 112 _documentLibraries(mirrorSystem.libraries.values,includeSdk: includeSdk,
111 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk); 113 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk,
114 introduction: introduction);
112 115
113 return true; 116 return true;
114 }); 117 });
115 } 118 }
116 119
117 List<String> _listLibraries(List<String> args) { 120 List<String> _listLibraries(List<String> args) {
118 if (args.length != 1) throw new UnsupportedError(USAGE); 121 if (args.length != 1) throw new UnsupportedError(USAGE);
119 var libraries = new List<String>(); 122 var libraries = new List<String>();
120 var type = FileSystemEntity.typeSync(args[0]); 123 var type = FileSystemEntity.typeSync(args[0]);
121 124
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // system, and it is not possible to use the stack trace. BUG(#11622) 220 // system, and it is not possible to use the stack trace. BUG(#11622)
218 // To avoid printing the stack trace. 221 // To avoid printing the stack trace.
219 exit(1); 222 exit(1);
220 }); 223 });
221 } 224 }
222 225
223 /** 226 /**
224 * Creates documentation for filtered libraries. 227 * Creates documentation for filtered libraries.
225 */ 228 */
226 void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false, 229 void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false,
227 bool outputToYaml: true, bool append: false, bool parseSdk: false}) { 230 bool outputToYaml: true, bool append: false, bool parseSdk: false,
231 String introduction: ''}) {
228 libs.forEach((lib) { 232 libs.forEach((lib) {
229 // Files belonging to the SDK have a uri that begins with 'dart:'. 233 // Files belonging to the SDK have a uri that begins with 'dart:'.
230 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { 234 if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
231 var library = generateLibrary(lib); 235 var library = generateLibrary(lib);
232 entityMap[library.qualifiedName] = library; 236 entityMap[library.qualifiedName] = library;
233 } 237 }
234 }); 238 });
235 // After everything is created, do a pass through all classes to make sure no 239 // After everything is created, do a pass through all classes to make sure no
236 // intermediate classes created by mixins are included. 240 // intermediate classes created by mixins are included.
237 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); 241 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid());
238 // Everything is a subclass of Object, therefore empty the list to avoid a 242 // Everything is a subclass of Object, therefore empty the list to avoid a
239 // giant list of subclasses to be printed out. 243 // giant list of subclasses to be printed out.
240 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); 244 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear();
241 245
242 var filteredEntities = entityMap.values.where(_isVisible); 246 var filteredEntities = entityMap.values.where(_isVisible);
243 // Output libraries and classes to file after all information is generated. 247 // Output libraries and classes to file after all information is generated.
244 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { 248 filteredEntities.where((e) => e is Class || e is Library).forEach((output) {
245 _writeIndexableToFile(output, outputToYaml); 249 _writeIndexableToFile(output, outputToYaml);
246 }); 250 });
247 // Outputs a yaml file with all libraries and their preview comments after 251 // Outputs a yaml file with all libraries and their preview comments after
248 // creating all libraries. This will help the viewer know what libraries are 252 // creating all libraries. This will help the viewer know what libraries are
249 // available to read in. 253 // available to read in.
250 var libraryMap = {'libraries' : filteredEntities.where((e) => 254 var libraryMap = {
251 e is Library).map((e) => e.previewMap).toList()}; 255 'libraries' : filteredEntities.where((e) =>
256 e is Library).map((e) => e.previewMap).toList(),
257 'introduction' : introduction == '' ?
258 '' : markdown.markdownToHtml(new File(introduction).readAsStringSync(),
259 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes)
260 };
252 _writeToFile(getYamlString(libraryMap), 'library_list.yaml', append: append); 261 _writeToFile(getYamlString(libraryMap), 'library_list.yaml', append: append);
253 // Outputs all the qualified names documented with their type. 262 // Outputs all the qualified names documented with their type.
254 // This will help generate search results. 263 // This will help generate search results.
255 _writeToFile(filteredEntities.map((e) => 264 _writeToFile(filteredEntities.map((e) =>
256 '${e.qualifiedName} ${e.typeName}').join('\n'), 265 '${e.qualifiedName} ${e.typeName}').join('\n'),
257 'index.txt', append: append); 266 'index.txt', append: append);
258 } 267 }
259 268
260 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { 269 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) {
261 _currentLibrary = library; 270 _currentLibrary = library;
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 String qualifiedName; 1156 String qualifiedName;
1148 List<String> parameters; 1157 List<String> parameters;
1149 1158
1150 Annotation(this.qualifiedName, this.parameters); 1159 Annotation(this.qualifiedName, this.parameters);
1151 1160
1152 Map toMap() => { 1161 Map toMap() => {
1153 'name': qualifiedName, 1162 'name': qualifiedName,
1154 'parameters': parameters 1163 'parameters': parameters
1155 }; 1164 };
1156 } 1165 }
OLDNEW
« no previous file with comments | « pkg/docgen/bin/sdk-introduction.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698