@@ -13,31 +13,33 @@ import 'package:dartdoc/src/model/model_element.dart';
13
13
/// Convenience function to generate category JSON since different generators
14
14
/// will likely want the same content for this.
15
15
String generateCategoryJson (Iterable <Categorization > categories, bool pretty) {
16
- var encoder = pretty ? JsonEncoder .withIndent (' ' ) : JsonEncoder ();
17
16
// ignore: omit_local_variable_types
18
17
final List <Map <String , Object >> indexItems =
19
- categories.map ((Categorization e ) {
20
- var data = < String , Object > {
21
- 'name' : e .name,
22
- 'qualifiedName' : e .fullyQualifiedName,
23
- 'href' : e .href,
24
- 'type' : e .kind,
18
+ categories.map ((Categorization categorization ) {
19
+ final data = < String , Object > {
20
+ 'name' : categorization .name,
21
+ 'qualifiedName' : categorization .fullyQualifiedName,
22
+ 'href' : categorization .href,
23
+ 'type' : categorization .kind,
25
24
};
26
25
27
- if (e.hasCategoryNames) data['categories' ] = e.categoryNames;
28
- if (e.hasSubCategoryNames) data['subcategories' ] = e.subCategoryNames;
29
- if (e.hasImage) data['image' ] = e.image;
30
- if (e.hasSamples) data['samples' ] = e.samples;
26
+ if (categorization.hasCategoryNames) {
27
+ data['categories' ] = categorization.categoryNames;
28
+ }
29
+ if (categorization.hasSubCategoryNames) {
30
+ data['subcategories' ] = categorization.subCategoryNames;
31
+ }
32
+ if (categorization.hasImage) {
33
+ data['image' ] = categorization.image;
34
+ }
35
+ if (categorization.hasSamples) {
36
+ data['samples' ] = categorization.samples;
37
+ }
31
38
return data;
32
- }).toList ( );
39
+ }).sorted (_sortElementRepresentations );
33
40
34
- indexItems.sort ((a, b) {
35
- var value = compareNatural (a['qualifiedName' ], b['qualifiedName' ]);
36
- if (value == 0 ) {
37
- value = compareNatural (a['type' ], b['type' ]);
38
- }
39
- return value;
40
- });
41
+ final encoder =
42
+ pretty ? const JsonEncoder .withIndent (' ' ) : const JsonEncoder ();
41
43
42
44
return encoder.convert (indexItems);
43
45
}
@@ -46,37 +48,39 @@ String generateCategoryJson(Iterable<Categorization> categories, bool pretty) {
46
48
/// generators will likely want the same content for this.
47
49
String generateSearchIndexJson (
48
50
Iterable <Indexable > indexedElements, bool pretty) {
49
- var encoder = pretty ? JsonEncoder .withIndent (' ' ) : JsonEncoder ();
50
- final indexItems = indexedElements.map ((Indexable e) {
51
- var data = < String , Object > {
52
- 'name' : e.name,
53
- 'qualifiedName' : e.fullyQualifiedName,
54
- 'href' : e.href,
55
- 'type' : e.kind,
56
- 'overriddenDepth' : e.overriddenDepth,
51
+ final indexItems = indexedElements.map ((Indexable indexable) {
52
+ final data = < String , Object > {
53
+ 'name' : indexable.name,
54
+ 'qualifiedName' : indexable.fullyQualifiedName,
55
+ 'href' : indexable.href,
56
+ 'type' : indexable.kind,
57
+ 'overriddenDepth' : indexable.overriddenDepth,
57
58
};
58
- if (e is ModelElement ) {
59
- data['packageName' ] = e .package.name;
59
+ if (indexable is ModelElement ) {
60
+ data['packageName' ] = indexable .package.name;
60
61
}
61
- if (e is EnclosedElement ) {
62
- var ee = e as EnclosedElement ;
62
+ if (indexable is EnclosedElement ) {
63
+ final ee = indexable as EnclosedElement ;
63
64
data['enclosedBy' ] = {
64
65
'name' : ee.enclosingElement.name,
65
66
'type' : ee.enclosingElement.kind
66
67
};
67
68
68
- data['qualifiedName' ] = e .fullyQualifiedName;
69
+ data['qualifiedName' ] = indexable .fullyQualifiedName;
69
70
}
70
71
return data;
71
- }).toList ( );
72
+ }).sorted (_sortElementRepresentations );
72
73
73
- indexItems.sort ((a, b) {
74
- var value = compareNatural (a['qualifiedName' ], b['qualifiedName' ]);
75
- if (value == 0 ) {
76
- value = compareNatural (a['type' ], b['type' ]);
77
- }
78
- return value;
79
- });
74
+ final encoder =
75
+ pretty ? const JsonEncoder .withIndent (' ' ) : const JsonEncoder ();
80
76
81
77
return encoder.convert (indexItems);
82
78
}
79
+
80
+ int _sortElementRepresentations (Map <String , Object > a, Map <String , Object > b) {
81
+ final value = compareNatural (a['qualifiedName' ], b['qualifiedName' ]);
82
+ if (value == 0 ) {
83
+ return compareNatural (a['type' ], b['type' ]);
84
+ }
85
+ return value;
86
+ }
0 commit comments