Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 } | 237 } |
| 238 }); | 238 }); |
| 239 // 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 |
| 240 // intermediate classes created by mixins are included. | 240 // intermediate classes created by mixins are included. |
| 241 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); | 241 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); |
| 242 // 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 |
| 243 // giant list of subclasses to be printed out. | 243 // giant list of subclasses to be printed out. |
| 244 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); | 244 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); |
| 245 | 245 |
| 246 var filteredEntities = entityMap.values.where(_isVisible); | 246 var filteredEntities = entityMap.values.where(_isVisible); |
| 247 | |
| 248 // Outputs a YAML or JSON file with all libraries and their preview comments | |
| 249 // after creating all libraries. This will help the viewer know what | |
| 250 // libraries are available to read in. | |
| 251 var libraryMap; | |
| 252 if (append) { | |
| 253 var docsDir = listDir('docs'); | |
| 254 if (docsDir.contains('docs/library_list.json')){ | |
|
Bob Nystrom
2013/08/16 20:51:10
Nit: space before "{".
Also, I would flip the con
janicejl
2013/08/16 21:33:45
Done.
| |
| 255 libraryMap = parse(new File('docs/library_list.json').readAsStringSync()); | |
| 256 } else { | |
| 257 throw new StateError('No library_list.json.'); | |
| 258 } | |
| 259 libraryMap['libraries'].addAll(filteredEntities.where((e) => | |
| 260 e is Library).map((e) => e.previewMap).toList()); | |
|
Bob Nystrom
2013/08/16 20:51:10
Nit, how about wrapping this on ".", like:
librar
janicejl
2013/08/16 21:33:45
Done.
| |
| 261 if (introduction.isNotEmpty) { | |
| 262 var intro = libraryMap['introduction']; | |
| 263 if (intro.isNotEmpty) { | |
| 264 intro = intro + '<br/><br/>' + markdown.markdownToHtml( | |
|
Bob Nystrom
2013/08/16 20:51:10
intro += '<br/><br/>'...
Bob Nystrom
2013/08/16 20:51:10
You can get rid of some duplicate code:
var intro
janicejl
2013/08/16 21:33:45
Done.
| |
| 265 new File(introduction).readAsStringSync(), | |
| 266 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes); | |
| 267 } else { | |
| 268 intro = markdown.markdownToHtml(new File(introduction) | |
| 269 .readAsStringSync(), linkResolver: linkResolver, | |
| 270 inlineSyntaxes: markdownSyntaxes); | |
| 271 } | |
| 272 libraryMap['introduction'] = intro; | |
| 273 } | |
| 274 outputToYaml = libraryMap['filetype'] == 'yaml'; | |
| 275 } else { | |
| 276 libraryMap = { | |
| 277 'libraries' : filteredEntities.where((e) => | |
| 278 e is Library).map((e) => e.previewMap).toList(), | |
| 279 'introduction' : introduction == '' ? | |
| 280 '' : markdown.markdownToHtml(new File(introduction) | |
| 281 .readAsStringSync(), linkResolver: linkResolver, | |
| 282 inlineSyntaxes: markdownSyntaxes), | |
| 283 'filetype' : outputToYaml ? 'yaml' : 'json' | |
| 284 }; | |
| 285 } | |
| 286 _writeToFile(stringify(libraryMap), 'library_list.json'); | |
| 247 // Output libraries and classes to file after all information is generated. | 287 // Output libraries and classes to file after all information is generated. |
| 248 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 288 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 249 _writeIndexableToFile(output, outputToYaml); | 289 _writeIndexableToFile(output, outputToYaml); |
| 250 }); | 290 }); |
| 251 // Outputs a YAML or JSON file with all libraries and their preview comments | |
| 252 // after creating all libraries. This will help the viewer know what | |
| 253 // libraries are available to read in. | |
| 254 var libraryMap = { | |
| 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 }; | |
| 261 if (outputToYaml) { | |
| 262 _writeToFile(getYamlString(libraryMap), 'library_list.yaml', | |
| 263 append: append); | |
| 264 } else { | |
| 265 _writeToFile(stringify(libraryMap), 'library_list.json', append: append); | |
| 266 } | |
| 267 // Outputs all the qualified names documented with their type. | 291 // Outputs all the qualified names documented with their type. |
| 268 // This will help generate search results. | 292 // This will help generate search results. |
| 269 _writeToFile(filteredEntities.map((e) => | 293 _writeToFile(filteredEntities.map((e) => |
| 270 '${e.qualifiedName} ${e.typeName}').join('\n'), | 294 '${e.qualifiedName} ${e.typeName}').join('\n'), |
| 271 'index.txt', append: append); | 295 'index.txt', append: append); |
| 272 } | 296 } |
| 273 | 297 |
| 274 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 298 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
| 275 _currentLibrary = library; | 299 _currentLibrary = library; |
| 276 var result = new Library(library.qualifiedName, _commentToHtml(library), | 300 var result = new Library(library.qualifiedName, _commentToHtml(library), |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 String qualifiedName; | 1178 String qualifiedName; |
| 1155 List<String> parameters; | 1179 List<String> parameters; |
| 1156 | 1180 |
| 1157 Annotation(this.qualifiedName, this.parameters); | 1181 Annotation(this.qualifiedName, this.parameters); |
| 1158 | 1182 |
| 1159 Map toMap() => { | 1183 Map toMap() => { |
| 1160 'name': qualifiedName, | 1184 'name': qualifiedName, |
| 1161 'parameters': parameters | 1185 'parameters': parameters |
| 1162 }; | 1186 }; |
| 1163 } | 1187 } |
| OLD | NEW |