Skip to content

Commit 628acf6

Browse files
authored
Implement basic categorization for libraries in dartdoc (#1641)
* Squash changes * Update README with usage for categories. * review comments
1 parent b9087d6 commit 628acf6

34 files changed

+578
-337
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,34 @@ authoring doc comments for Dart with `dartdoc`.
9595

9696
## Advanced features
9797

98+
### dartdoc_options.yaml
99+
100+
Creating a file named dartdoc_options.yaml at the top of your package can change how Dartdoc
101+
generates docs.
102+
103+
```yaml
104+
dartdoc:
105+
categoryOrder: ["First Category", "Second Category"]
106+
107+
```
108+
For now, there's only one option:
109+
110+
* **categoryOrder**: Specify the order of categories, below, for display in the sidebar and
111+
the package page.
112+
113+
### Categories
114+
115+
You can tag libraries in their documentation with the string `{@category YourCategory}`, and
116+
that will cause the library to appear in a category when showing the sidebar on the Package
117+
and Library pages.
118+
119+
```dart
120+
/// Here is my library.
121+
///
122+
/// {@category Amazing}
123+
library my_library;
124+
```
125+
98126
### Macros
99127

100128
You can specify "macros", i.e. reusable pieces of documentation. For that, first specify a template

bin/dartdoc.dart

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ main(List<String> arguments) async {
192192
PackageMeta packageMeta = new PackageMeta.fromDir(inputDir);
193193

194194
if (packageMeta == null) {
195-
stderr.writeln(' fatal error: Unable to generate documentation: no pubspec.yaml found');
195+
stderr.writeln(
196+
' fatal error: Unable to generate documentation: no pubspec.yaml found');
196197
exit(1);
197198
}
198199

@@ -212,7 +213,6 @@ main(List<String> arguments) async {
212213
}
213214
}
214215

215-
216216
logInfo("Generating documentation for '${packageMeta}' into "
217217
"${outputDir.absolute.path}${Platform.pathSeparator}");
218218

@@ -221,7 +221,6 @@ main(List<String> arguments) async {
221221
footerFilePaths: footerFilePaths,
222222
footerTextFilePaths: footerTextFilePaths,
223223
faviconPath: args['favicon'],
224-
displayAsPackages: args['use-categories'],
225224
prettyIndexJson: args['pretty-index-json']);
226225

227226
for (var generator in generators) {
@@ -311,10 +310,8 @@ ArgParser _createArgsParser() {
311310
parser.addFlag('show-progress',
312311
help: 'Display progress indications to console stdout', negatable: false);
313312
parser.addOption('sdk-readme',
314-
help:
315-
'Path to the SDK description file. Deprecated (ignored)');
316-
parser.addOption('input',
317-
help: 'Path to source directory.');
313+
help: 'Path to the SDK description file. Deprecated (ignored)');
314+
parser.addOption('input', help: 'Path to source directory.');
318315
parser.addOption('output',
319316
help: 'Path to output directory.', defaultsTo: defaultOutDir);
320317
parser.addMultiOption('header',
@@ -349,22 +346,18 @@ ArgParser _createArgsParser() {
349346
help: 'A path to a favicon for the generated docs.');
350347
parser.addFlag('use-categories',
351348
help:
352-
'Group libraries from the same package in the libraries sidebar. (deprecated, replaced by display-as-packages)',
353-
negatable: false,
354-
defaultsTo: false);
355-
parser.addFlag('display-as-packages',
356-
help: 'Group libraries from the same package in the libraries sidebar.',
349+
'Group libraries from the same package in the libraries sidebar. (deprecated, ignored)',
357350
negatable: false,
358351
defaultsTo: false);
359352
parser.addMultiOption('category-order',
360353
help:
361-
'A list of package names to place first when --display-as-packages is '
362-
'set. Unmentioned categories are sorted after these. (deprecated, replaced by package-order)',
354+
'A list of package names to place first when grouping libraries in packages. '
355+
'Unmentioned categories are sorted after these. (deprecated, replaced by package-order)',
363356
splitCommas: true);
364357
parser.addMultiOption('package-order',
365358
help:
366-
'A list of package names to place first when --display-as-packages is '
367-
'set. Unmentioned categories are sorted after these.',
359+
'A list of package names to place first when grouping libraries in packages. '
360+
'Unmentioned categories are sorted after these.',
368361
splitCommas: true);
369362
parser.addFlag('auto-include-dependencies',
370363
help:

lib/dartdoc.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ Future<List<Generator>> initGenerators(String url, String relCanonicalPrefix,
4646
List<String> footerFilePaths,
4747
List<String> footerTextFilePaths,
4848
String faviconPath,
49-
bool displayAsPackages: false,
5049
bool prettyIndexJson: false}) async {
5150
var options = new HtmlGeneratorOptions(
5251
url: url,
5352
relCanonicalPrefix: relCanonicalPrefix,
5453
toolVersion: version,
5554
faviconPath: faviconPath,
56-
displayAsPackages: displayAsPackages,
5755
prettyIndexJson: prettyIndexJson);
5856

5957
return [

lib/resources/styles.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,19 @@ ul.subnav li:last-of-type {
630630
padding-top: 25px;
631631
}
632632

633+
.sidebar ol li.section-subtitle a {
634+
color: inherit;
635+
}
636+
637+
.sidebar ol li.section-subtitle {
638+
font-weight: 400;
639+
text-transform: uppercase;
640+
}
641+
642+
.sidebar ol li.section-subitem {
643+
margin-left: 12px;
644+
}
645+
633646
.sidebar ol li:first-child {
634647
padding-top: 0;
635648
margin-top: 0;

lib/src/html/html_generator.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ class HtmlGeneratorOptions implements HtmlOptions {
115115
final String faviconPath;
116116
final bool prettyIndexJson;
117117

118-
@override
119-
final bool displayAsPackages;
120-
121118
@override
122119
final String relCanonicalPrefix;
123120

@@ -129,7 +126,6 @@ class HtmlGeneratorOptions implements HtmlOptions {
129126
this.relCanonicalPrefix,
130127
this.faviconPath,
131128
String toolVersion,
132-
this.displayAsPackages: false,
133129
this.prettyIndexJson: false})
134130
: this.toolVersion = toolVersion ?? 'unknown';
135131
}

lib/src/html/template_data.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import '../model.dart';
77
abstract class HtmlOptions {
88
String get relCanonicalPrefix;
99
String get toolVersion;
10-
bool get displayAsPackages;
1110
}
1211

1312
class Subnav {
@@ -63,7 +62,6 @@ abstract class TemplateData<T extends Documentable> {
6362
T get self;
6463
String get version => htmlOptions.toolVersion;
6564
String get relCanonicalPrefix => htmlOptions.relCanonicalPrefix;
66-
bool get displayAsPackages => htmlOptions.displayAsPackages;
6765

6866
Iterable<Subnav> getSubNavItems() => <Subnav>[];
6967

@@ -113,7 +111,7 @@ class PackageTemplateData extends TemplateData<PackageGraph> {
113111
String get homepage => packageGraph.homepage;
114112

115113
@override
116-
String get kind => (displayAsPackages || packageGraph.isSdk) ? '' : 'package';
114+
String get kind => packageGraph.kind;
117115

118116
/// `null` for packages because they are at the root – not needed
119117
@override

lib/src/html/templates.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const _partials = const <String>[
2020
'constant',
2121
'footer',
2222
'head',
23+
'library',
24+
'packages',
2325
'property',
2426
'features',
2527
'documentation',

0 commit comments

Comments
 (0)