| 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 JSON file with all libraries and their preview comments. |
| 249 // This will help the viewer know what libraries are available to read in. |
| 250 var libraryMap; |
| 251 if (append) { |
| 252 var docsDir = listDir('docs'); |
| 253 if (!docsDir.contains('docs/library_list.json')) { |
| 254 throw new StateError('No library_list.json'); |
| 255 } |
| 256 libraryMap = parse(new File('docs/library_list.json').readAsStringSync()); |
| 257 libraryMap['libraries'].addAll(filteredEntities |
| 258 .where((e) => e is Library) |
| 259 .map((e) => e.previewMap)); |
| 260 if (introduction.isNotEmpty) { |
| 261 var intro = libraryMap['introduction']; |
| 262 if (intro.isNotEmpty) intro += '<br/><br/>'; |
| 263 intro += markdown.markdownToHtml( |
| 264 new File(introduction).readAsStringSync(), |
| 265 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes); |
| 266 libraryMap['introduction'] = intro; |
| 267 } |
| 268 outputToYaml = libraryMap['filetype'] == 'yaml'; |
| 269 } else { |
| 270 libraryMap = { |
| 271 'libraries' : filteredEntities.where((e) => |
| 272 e is Library).map((e) => e.previewMap).toList(), |
| 273 'introduction' : introduction == '' ? |
| 274 '' : markdown.markdownToHtml(new File(introduction) |
| 275 .readAsStringSync(), linkResolver: linkResolver, |
| 276 inlineSyntaxes: markdownSyntaxes), |
| 277 'filetype' : outputToYaml ? 'yaml' : 'json' |
| 278 }; |
| 279 } |
| 280 _writeToFile(stringify(libraryMap), 'library_list.json'); |
| 247 // Output libraries and classes to file after all information is generated. | 281 // Output libraries and classes to file after all information is generated. |
| 248 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 282 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 249 _writeIndexableToFile(output, outputToYaml); | 283 _writeIndexableToFile(output, outputToYaml); |
| 250 }); | 284 }); |
| 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. | 285 // Outputs all the qualified names documented with their type. |
| 268 // This will help generate search results. | 286 // This will help generate search results. |
| 269 _writeToFile(filteredEntities.map((e) => | 287 _writeToFile(filteredEntities.map((e) => |
| 270 '${e.qualifiedName} ${e.typeName}').join('\n'), | 288 '${e.qualifiedName} ${e.typeName}').join('\n'), |
| 271 'index.txt', append: append); | 289 'index.txt', append: append); |
| 272 } | 290 } |
| 273 | 291 |
| 274 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 292 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
| 275 _currentLibrary = library; | 293 _currentLibrary = library; |
| 276 var result = new Library(library.qualifiedName, _commentToHtml(library), | 294 var result = new Library(library.qualifiedName, _commentToHtml(library), |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 String qualifiedName; | 1172 String qualifiedName; |
| 1155 List<String> parameters; | 1173 List<String> parameters; |
| 1156 | 1174 |
| 1157 Annotation(this.qualifiedName, this.parameters); | 1175 Annotation(this.qualifiedName, this.parameters); |
| 1158 | 1176 |
| 1159 Map toMap() => { | 1177 Map toMap() => { |
| 1160 'name': qualifiedName, | 1178 'name': qualifiedName, |
| 1161 'parameters': parameters | 1179 'parameters': parameters |
| 1162 }; | 1180 }; |
| 1163 } | 1181 } |
| OLD | NEW |