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

Side by Side Diff: tools/dom/docs/lib/docs.dart

Issue 13116021: Fix docs.dart, which has been sad and neglected. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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 | « tools/dom/docs/docs.json ('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 /** 1 /**
2 * A library for extracting the documentation from the various HTML libraries 2 * A library for extracting the documentation from the various HTML libraries
3 * ([dart:html], [dart:svg], [dart:web_audio], [dart:indexed_db]) and saving 3 * ([dart:html], [dart:svg], [dart:web_audio], [dart:indexed_db]) and saving
4 * those documentation comments to a JSON file. 4 * those documentation comments to a JSON file.
5 */ 5 */
6 6
7 library docs; 7 library docs;
8 8
9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mi rror.dart';
9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.da rt'; 10 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.da rt';
11 import '../../../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
10 import '../../../../sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart'; 12 import '../../../../sdk/lib/_internal/dartdoc/lib/src/json_serializer.dart';
11 import '../../../../sdk/lib/_internal/dartdoc/lib/dartdoc.dart';
12 import '../../../../utils/apidoc/lib/metadata.dart'; 13 import '../../../../utils/apidoc/lib/metadata.dart';
13 import 'dart:async'; 14 import 'dart:async';
14 import 'dart:io'; 15 import 'dart:io';
15 16
16 /// The various HTML libraries. 17 /// The various HTML libraries.
17 const List<String> HTML_LIBRARY_NAMES = const ['dart:html', 18 const List<String> HTML_LIBRARY_NAMES = const ['dart:html',
18 'dart:indexed_db', 19 'dart:indexed_db',
19 'dart:svg', 20 'dart:svg',
20 'dart:web_audio', 21 'dart:web_audio',
21 'dart:web_sql']; 22 'dart:web_sql'];
(...skipping 14 matching lines...) Expand all
36 * ... 37 * ...
37 * ], 38 * ],
38 * ... 39 * ...
39 * } 40 * }
40 * }, 41 * },
41 * ... 42 * ...
42 * }, 43 * },
43 * ... 44 * ...
44 * } 45 * }
45 * 46 *
46 * Returns `true` if any errors were encountered, `false` otherwise. 47 * Completes to `true` if any errors were encountered, `false` otherwise.
47 */ 48 */
48 bool convert(Path libPath, Path jsonPath) { 49 Future<bool> convert(Path libPath, Path jsonPath) {
49 var paths = <Path>[]; 50 var paths = <Path>[];
50 for (var libraryName in HTML_LIBRARY_NAMES) { 51 for (var libraryName in HTML_LIBRARY_NAMES) {
51 paths.add(new Path(libraryName)); 52 paths.add(new Path(libraryName));
52 } 53 }
53 54
54 // TODO(amouravski): Account for errors in compilation. 55 return analyze(paths, libPath, options: ['--preserve-comments'])
55 final compilation = new Compilation.library(paths, libPath, null, 56 .then((MirrorSystem mirrors) {
56 ['--preserve-comments']); 57 var convertedJson = _generateJsonFromLibraries(mirrors);
57 58 return new Future.immediate(_exportJsonToFile(convertedJson, jsonPath));
58 var convertedJson = _generateJsonFromLibraries(compilation); 59 });
59
60 var anyErrors = _exportJsonToFile(convertedJson, jsonPath);
61
62 return anyErrors;
63 } 60 }
64 61
65 bool _exportJsonToFile(Map convertedJson, Path jsonPath) { 62 bool _exportJsonToFile(Map convertedJson, Path jsonPath) {
66 final jsonFile = new File.fromPath(jsonPath); 63 final jsonFile = new File.fromPath(jsonPath);
67 var writeJson = prettySerialize(convertedJson); 64 var writeJson = prettySerialize(convertedJson);
68 65
69 var outputStream = jsonFile.openOutputStream(); 66 var outputStream = jsonFile.openWrite();
70 outputStream.writeString(writeJson); 67 outputStream.writeln(writeJson);
71 68
72 return false; 69 return false;
73 } 70 }
74 71
75 Map _generateJsonFromLibraries(Compilation compilation) { 72 Map _generateJsonFromLibraries(MirrorSystem mirrors) {
76 var convertedJson = {}; 73 var convertedJson = {};
77 74
78 // Sort the libraries by name (not key). 75 // Sort the libraries by name (not key).
79 var sortedLibraries = new List<LibraryMirror>.from( 76 var sortedLibraries = new List<LibraryMirror>.from(
80 compilation.mirrors.libraries.values.where( 77 mirrors.libraries.values.where(
81 (e) => HTML_LIBRARY_NAMES.indexOf(e.uri.toString()) >= 0)) 78 (e) => HTML_LIBRARY_NAMES.indexOf(e.uri.toString()) >= 0))
82 ..sort((x, y) => 79 ..sort((x, y) =>
83 x.uri.toString().toUpperCase().compareTo( 80 x.uri.toString().toUpperCase().compareTo(
84 y.uri.toString().toUpperCase())); 81 y.uri.toString().toUpperCase()));
85 82
86 for (LibraryMirror libMirror in sortedLibraries) { 83 for (LibraryMirror libMirror in sortedLibraries) {
87 print('Extracting documentation from ${libMirror.displayName}.'); 84 print('Extracting documentation from ${libMirror.displayName}.');
88 85
89 var libraryJson = {}; 86 var libraryJson = {};
90 var sortedClasses = _sortAndFilterMirrors( 87 var sortedClasses = _sortAndFilterMirrors(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 for (var s in tags.reflectee.split(',')) { 177 for (var s in tags.reflectee.split(',')) {
181 domNames.add(s.trim()); 178 domNames.add(s.trim());
182 } 179 }
183 180
184 if (domNames.length == 1 && domNames[0] == 'none') return <String>[]; 181 if (domNames.length == 1 && domNames[0] == 'none') return <String>[];
185 return domNames; 182 return domNames;
186 } else { 183 } else {
187 return <String>[]; 184 return <String>[];
188 } 185 }
189 } 186 }
OLDNEW
« no previous file with comments | « tools/dom/docs/docs.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698