Skip to content

Commit 2f15f71

Browse files
committed
Added pretty-index-json command line flag
1 parent 3332e40 commit 2f15f71

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* fix multiple issues in annotation/feature list handling (#1268, #1162, #1081)
44

5+
* Added `pretty-index-json` command line flag.
6+
57
## 0.9.12
68

79
* add print styles

bin/dartdoc.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ main(List<String> arguments) async {
125125

126126
var generators = await initGenerators(
127127
url, headerFilePaths, footerFilePaths, args['rel-canonical-prefix'],
128-
faviconPath: args['favicon'], useCategories: args['use-categories']);
128+
faviconPath: args['favicon'],
129+
useCategories: args['use-categories'],
130+
prettyIndexJson: args['pretty-index-json']);
129131

130132
for (var generator in generators) {
131133
generator.onFileCreated.listen(_onProgress);
@@ -222,6 +224,11 @@ ArgParser _createArgsParser() {
222224
'Include all the used libraries into the docs, even the ones not in the current package or "include-external"',
223225
negatable: false,
224226
defaultsTo: false);
227+
parser.addFlag('pretty-index-json',
228+
help:
229+
"Generates `index.json` with indentation and newlines. The file is larger, but it's also easier to diff.",
230+
negatable: false,
231+
defaultsTo: false);
225232
return parser;
226233
}
227234

lib/dartdoc.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ final String defaultOutDir = path.join('doc', 'api');
4747
/// Initialize and setup the generators.
4848
Future<List<Generator>> initGenerators(String url, List<String> headerFilePaths,
4949
List<String> footerFilePaths, String relCanonicalPrefix,
50-
{String faviconPath, bool useCategories: false}) async {
50+
{String faviconPath,
51+
bool useCategories: false,
52+
bool prettyIndexJson: false}) async {
5153
return [
5254
await HtmlGenerator.create(
5355
url: url,
@@ -56,7 +58,8 @@ Future<List<Generator>> initGenerators(String url, List<String> headerFilePaths,
5658
relCanonicalPrefix: relCanonicalPrefix,
5759
toolVersion: version,
5860
faviconPath: faviconPath,
59-
useCategories: useCategories)
61+
useCategories: useCategories,
62+
prettyIndexJson: prettyIndexJson)
6063
];
6164
}
6265

lib/src/html/html_generator.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class HtmlGenerator extends Generator {
4141
final String _toolVersion;
4242
final String faviconPath;
4343
final bool useCategories;
44+
final bool prettyIndexJson;
4445

4546
final StreamController<File> _onFileCreated =
4647
new StreamController(sync: true);
@@ -56,7 +57,8 @@ class HtmlGenerator extends Generator {
5657
String relCanonicalPrefix,
5758
String toolVersion,
5859
String faviconPath,
59-
bool useCategories: false}) async {
60+
bool useCategories: false,
61+
bool prettyIndexJson: false}) async {
6062
var templates =
6163
await Templates.create(headerPaths: headers, footerPaths: footers);
6264

@@ -65,18 +67,22 @@ class HtmlGenerator extends Generator {
6567
}
6668

6769
return new HtmlGenerator._(url, relCanonicalPrefix, templates, toolVersion,
68-
faviconPath: faviconPath, useCategories: useCategories);
70+
faviconPath: faviconPath,
71+
useCategories: useCategories,
72+
prettyIndexJson: prettyIndexJson);
6973
}
7074

7175
HtmlGenerator._(
7276
this._url, this._relCanonicalPrefix, this._templates, this._toolVersion,
73-
{this.faviconPath, this.useCategories});
77+
{this.faviconPath, this.useCategories, this.prettyIndexJson: false});
7478

7579
@override
7680
Future generate(Package package, Directory out) {
7781
return new HtmlGeneratorInstance(_toolVersion, _url, _templates, package,
7882
out, _onFileCreated, _relCanonicalPrefix,
79-
faviconPath: faviconPath, useCategories: useCategories)
83+
faviconPath: faviconPath,
84+
useCategories: useCategories,
85+
prettyIndexJson: prettyIndexJson)
8086
.generate();
8187
}
8288
}

lib/src/html/html_generator_instance.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async' show Future, StreamController;
6-
import 'dart:convert' show JSON;
6+
import 'dart:convert' show JsonEncoder;
77
import 'dart:io' show Directory, File, stdout;
88
import 'dart:typed_data' show Uint8List;
99

@@ -28,10 +28,11 @@ class HtmlGeneratorInstance implements HtmlOptions {
2828
final String toolVersion;
2929
final String faviconPath;
3030
final bool useCategories;
31+
final bool prettyIndexJson;
3132

3233
HtmlGeneratorInstance(this.toolVersion, this.url, this._templates,
3334
this.package, this.out, this._onFileCreated, this.relCanonicalPrefix,
34-
{this.faviconPath, this.useCategories});
35+
{this.faviconPath, this.useCategories, this.prettyIndexJson: false});
3536

3637
Future generate() async {
3738
if (!out.existsSync()) out.createSync();
@@ -50,7 +51,11 @@ class HtmlGeneratorInstance implements HtmlOptions {
5051

5152
void _generateSearchIndex() {
5253
File jsonFile = _createOutputFile(out, 'index.json');
53-
String json = JSON.encode(
54+
55+
var encoder =
56+
prettyIndexJson ? new JsonEncoder.withIndent(' ') : new JsonEncoder();
57+
58+
String json = encoder.convert(
5459
documentedElements.where((e) => e.isCanonical).map((ModelElement e) {
5560
Map data = {
5661
'name': e.name,

0 commit comments

Comments
 (0)