Skip to content

Commit b159cdc

Browse files
authored
HtmlGeneratorInstance: cleanup JSON writing (#1536)
1 parent f2fddbb commit b159cdc

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/src/html/html_generator_instance.dart

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ class HtmlGeneratorInstance implements HtmlOptions {
6262
var encoder =
6363
prettyIndexJson ? new JsonEncoder.withIndent(' ') : new JsonEncoder();
6464

65-
File jsonFile = _createOutputFile(path.join(out.path, 'index.json'));
66-
String json = encoder.convert(
65+
final List<Map> indexItems =
6766
documentedElements.where((e) => e.isCanonical).map((ModelElement e) {
6867
Map data = {
6968
'name': e.name,
@@ -82,15 +81,18 @@ class HtmlGeneratorInstance implements HtmlOptions {
8281
data['qualifiedName'] = e.fullyQualifiedName;
8382
}
8483
return data;
85-
}).toList()
86-
..sort((a, b) {
87-
var value = compareNatural(a['qualifiedName'], b['qualifiedName']);
88-
if (value == 0) {
89-
value = compareNatural(a['type'], b['type']);
90-
}
91-
return value;
92-
}));
93-
jsonFile.writeAsStringSync('${json}\n');
84+
}).toList();
85+
86+
indexItems.sort((a, b) {
87+
var value = compareNatural(a['qualifiedName'], b['qualifiedName']);
88+
if (value == 0) {
89+
value = compareNatural(a['type'], b['type']);
90+
}
91+
return value;
92+
});
93+
94+
String json = encoder.convert(indexItems);
95+
_writeFile(path.join(out.path, 'index.json'), '${json}\n');
9496
}
9597

9698
void _generateDocs() {

0 commit comments

Comments
 (0)