OLD | NEW |
---|---|
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 * Library for taking a JSON file and putting the comments located within into | 6 * Library for taking a JSON file and putting the comments located within into |
7 * the HTML files the comments are associated with. | 7 * the HTML files the comments are associated with. |
8 * | 8 * |
9 * The format of the JSON file is: | 9 * The format of the JSON file is: |
10 * | 10 * |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 _anyErrors = true; | 59 _anyErrors = true; |
60 completer.complete(false); | 60 completer.complete(false); |
61 } else { | 61 } else { |
62 fileJson = JSON.parse(jsonRead); | 62 fileJson = JSON.parse(jsonRead); |
63 } | 63 } |
64 | 64 |
65 // TODO(amouravski): Refactor to not duplicate code here and in html-to-json. | 65 // TODO(amouravski): Refactor to not duplicate code here and in html-to-json. |
66 // Find html files. (lister) | 66 // Find html files. (lister) |
67 final lister = htmlDir.list(recursive: false); | 67 final lister = htmlDir.list(recursive: false); |
68 | 68 |
69 var pathList = <Path>[]; | |
69 lister.onFile = (String path) { | 70 lister.onFile = (String path) { |
71 pathList.add(path); | |
72 }; | |
73 | |
74 getFile(Path path) { | |
70 final name = new Path.fromNative(path).filename; | 75 final name = new Path.fromNative(path).filename; |
71 | 76 |
72 // Ignore private classes. | 77 // Ignore private classes. |
73 if (name.startsWith('_')) return; | 78 if (name.startsWith('_')) return; |
74 | 79 |
75 // Ignore non-dart files. | 80 // Ignore non-dart files. |
76 if (!name.endsWith('.dart')) return; | 81 if (!name.endsWith('.dart')) return; |
77 | 82 |
78 File file = new File(path); | 83 File file = new File(path); |
79 | 84 |
80 // TODO(amouravski): Handle missing file. | 85 // TODO(amouravski): Handle missing file. |
81 if (!file.existsSync()) { | 86 if (!file.existsSync()) { |
82 print('ERROR: cannot find file: $path'); | 87 print('ERROR: cannot find file: $path'); |
83 _anyErrors = true; | 88 _anyErrors = true; |
84 return; | 89 return; |
85 } | 90 } |
86 | 91 |
87 if (!fileJson.containsKey(name)) { | 92 if (!fileJson.containsKey(name)) { |
88 print('WARNING: file found that is not in JSON: $path'); | 93 print('WARNING: file found that is not in JSON: $path'); |
89 _anyErrors = true; | 94 _anyErrors = true; |
90 return; | 95 return; |
91 } | 96 } |
92 | 97 |
93 var comments = fileJson[name]; | 98 var comments = fileJson[name]; |
94 | 99 |
95 _convertFile(file, comments); | 100 print('BLAH $name'); |
96 | 101 |
97 fileJson.remove(name); | 102 fileJson.remove(name); |
98 }; | 103 }; |
99 | 104 |
100 lister.onDone = (_) { | 105 lister.onDone = (_) { |
106 while(!pathList.isEmpty) { | |
107 getFile(pathList.removeLast()); | |
108 } | |
109 print('foo'); | |
101 | 110 |
102 fileJson.forEach((key, _) { | 111 fileJson.forEach((key, _) { |
103 print('WARNING: the following filename was found in the JSON but not in ' | 112 print('WARNING: the following filename was found in the JSON but not in ' |
104 '${htmlDir.path}:\n"$key"'); | 113 '${htmlDir.path}:\n"$key"'); |
105 _anyErrors = true; | 114 _anyErrors = true; |
106 }); | 115 }); |
107 | 116 |
108 completer.complete(_anyErrors); | 117 completer.complete(_anyErrors); |
109 }; | |
Adam
2012/11/27 22:18:05
This closing brace is needed
Andrei Mouravski
2012/11/28 00:28:34
Done.
| |
110 | 118 |
111 return completer.future; | 119 return completer.future; |
112 } | 120 } |
113 | 121 |
114 | 122 |
115 /** | 123 /** |
116 * Inserts the comments from JSON into a single file. | 124 * Inserts the comments from JSON into a single file. |
117 */ | 125 */ |
118 void _convertFile(File file, Map<String, List<String>> comments) { | 126 void _convertFile(File file, Map<String, List<String>> comments) { |
119 var fileLines = file.readAsLinesSync(); | 127 var fileLines = file.readAsLinesSync(); |
(...skipping 22 matching lines...) Expand all Loading... | |
142 | 150 |
143 // TODO(amouravski): file.writeAsStringSync('${Strings.join(fileLines, '\n')}\ n'); | 151 // TODO(amouravski): file.writeAsStringSync('${Strings.join(fileLines, '\n')}\ n'); |
144 var outputStream = file.openOutputStream(); | 152 var outputStream = file.openOutputStream(); |
145 outputStream.writeString(Strings.join(fileLines, '\n')); | 153 outputStream.writeString(Strings.join(fileLines, '\n')); |
146 outputStream.writeString('\n'); | 154 outputStream.writeString('\n'); |
147 | 155 |
148 outputStream.onNoPendingWrites = () { | 156 outputStream.onNoPendingWrites = () { |
149 outputStream.close(); | 157 outputStream.close(); |
150 }; | 158 }; |
151 } | 159 } |
OLD | NEW |