Skip to content

Commit f895c61

Browse files
authored
Surface category one liner on index page (#3632)
* Surface category one liner on index page * Regenerate renderers
1 parent fdd3618 commit f895c61

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

lib/src/generator/templates.aot_renderers_for_html.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,13 @@ String renderIndex(PackageTemplateData context0) {
10481048
<h3>''');
10491049
buffer.writeEscaped(context8.name);
10501050
buffer.write('''</h3>''');
1051+
if (context8.isDocumented) {
1052+
buffer.writeln();
1053+
buffer.write('''
1054+
<p>''');
1055+
buffer.write(context8.oneLineDoc);
1056+
buffer.write('''</p>''');
1057+
}
10511058
var context9 = context8.externalItems;
10521059
for (var context10 in context9) {
10531060
buffer.writeln();

lib/templates/html/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ <h2>{{name}}</h2>
1919
{{/defaultCategory.publicLibrariesSorted}}
2020
{{#categoriesWithPublicLibraries}}
2121
<h3>{{name}}</h3>
22+
{{#isDocumented}}
23+
<p>{{{ oneLineDoc }}}</p>
24+
{{/isDocumented}}
2225
{{#externalItems}}
2326
<dt>
2427
<span class="name">

test/templates/category_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void main() async {
2121
late PackageMetaProvider packageMetaProvider;
2222
late DartdocGeneratorOptionContext context;
2323
late List<String> topicOneLines;
24+
late List<String> indexPageLines;
2425

2526
Future<PubPackageBuilder> createPackageBuilder() async {
2627
context = await utils.generatorContextFromArgv([
@@ -75,6 +76,8 @@ dartdoc:
7576
categories:
7677
One:
7778
markdown: one.md
79+
Documented:
80+
markdown: documented.md
7881
''',
7982
libFiles: [
8083
d.file('lib.dart', '''
@@ -118,10 +121,15 @@ extension Ex on int {}
118121
/// An extension type.
119122
/// {@category One}
120123
extension type ExType(int it) {}
124+
'''),
125+
d.file('other.dart', '''
126+
/// {@category Documented}
127+
library;
121128
'''),
122129
],
123130
files: [
124131
d.file('one.md', ''),
132+
d.file('documented.md', 'First line.\n\nSecond line.'),
125133
],
126134
resourceProvider: resourceProvider,
127135
);
@@ -131,6 +139,10 @@ extension type ExType(int it) {}
131139
.getFile(path.join(packagePath, 'doc', 'topics', 'One-topic.html'))
132140
.readAsStringSync()
133141
.split('\n');
142+
indexPageLines = resourceProvider
143+
.getFile(path.join(packagePath, 'doc', 'index.html'))
144+
.readAsStringSync()
145+
.split('\n');
134146
});
135147

136148
test('page links to classes annotated with category', () async {
@@ -296,4 +308,11 @@ extension type ExType(int it) {}
296308
]),
297309
);
298310
});
311+
312+
test('index page includes topics and their one liner description', () {
313+
indexPageLines.expectMainContentContainsAllInOrder([
314+
equalsIgnoringWhitespace('<h3>Documented</h3>'),
315+
equalsIgnoringWhitespace('<p>First line.</p>'),
316+
]);
317+
});
299318
}

0 commit comments

Comments
 (0)