Skip to content

Expand category system to all top level items #1754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.21.0-dev.0
* Expand categories to all top level items as well as libraries. (#1681, #1353)
* The categoryOrder option in dartdoc_options.yaml and the command line
is replaced with a more generic "categories" option. See README.md.

## 0.20.4
* Hide pragma declarations from generated docs (#1726)
* Fix problems with lists in markdown not being handled correctly (#172)
Expand Down
57 changes: 51 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,22 @@ generates docs.

```yaml
dartdoc:
categoryOrder: ["First Category", "Second Category"]
categories:
"First Category":
markdown: doc/First.md
name: Awesome
"Second Category":
markdown: doc/Second.md
name: Great
linkTo:
url: "https://my.dartdocumentationsite.org/dev/%v%"
```

Unrecognized options will be ignored. Supported options:

* **categoryOrder**: Specify the order of categories, below, for display in the sidebar and
the package page.
* **categories**: Specify the order of categories. For APIs you'd like to document, specify
the markdown file with `markdown:` to use for the category page. Optionally, rename the
category from the source code into a display name with 'name:'.
* **exclude**: Specify a list of library names to avoid generating docs for,
overriding any specified in include.
* **include**: Specify a list of library names to generate docs for, ignoring all others.
Expand Down Expand Up @@ -144,9 +151,11 @@ as POSIX paths. Dartdoc will convert POSIX paths automatically on Windows.

### Categories

You can tag libraries in their documentation with the string `{@category YourCategory}`, and
that will cause the library to appear in a category when showing the sidebar on the Package
and Library pages.
You can tag libraries or top level classes, functions, and variables in their documentation with
the string `{@category YourCategory}`. For libraries, that will cause the library to appear in a
category when showing the sidebar on the Package and Library pages. For other types of objects,
the `{@category}` will be shown with a link to the category page if specified in
dartdoc_options.yaml, as above.

```dart
/// Here is my library.
Expand All @@ -155,6 +164,42 @@ and Library pages.
library my_library;
```

#### Other category tags and categories.json

A file `categories.json` will be generated at the top level of the documentation tree with
information about categories collected from objects in the source tree. The directives
`@category`, `@subCategory`, `@image`, and `@samples` are understood and saved into this json.
Future versions of dartdoc may make direct use of the image and samples tags.

As an example, if we document the class Icon in flutter using the following:

```dart
/// {@category Basics}
/// {@category Assets, Images, and Icons}
/// {@subCategory Information displays}
/// {@image <image alt='' src='/images/catalog-widget-placeholder.png'>}
class Icon extends StatelessWidget {}
```

that will result in the following json:

```json
{
"name": "Icon",
"qualifiedName": "widgets.Icon",
"href": "widgets/Icon-class.html",
"type": "class",
"categories": [
"Assets, Images, and Icons",
"Basics"
],
"subcategories": [
"Information displays"
],
"image": "<image alt='' src='/images/catalog-widget-placeholder.png'>"
}
```

### Animations

You can specify links to videos inline that will be handled with a simple HTML5 player:
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ analyzer:
- 'testing/test_package_export_error/**'
linter:
rules:
- always_declare_return_types
- annotate_overrides
- avoid_init_to_null
- directives_ordering
Expand Down
2 changes: 1 addition & 1 deletion bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Future<List<DartdocOption>> createDartdocProgramOptions() async {

/// Analyzes Dart files and generates a representation of included libraries,
/// classes, and members. Uses the current directory to look for libraries.
main(List<String> arguments) async {
void main(List<String> arguments) async {
DartdocOptionSet optionSet =
await DartdocOptionSet.fromOptionGenerators('dartdoc', [
createDartdocOptions,
Expand Down
5 changes: 3 additions & 2 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Dartdoc extends PackageBuilder {

/// An asynchronous factory method that builds Dartdoc's file writers
/// and returns a Dartdoc object with them.
static withDefaultGenerators(DartdocGeneratorOptionContext config) async {
static Future<Dartdoc> withDefaultGenerators(
DartdocGeneratorOptionContext config) async {
List<Generator> generators = await initGenerators(config);
return new Dartdoc._(config, generators);
}
Expand Down Expand Up @@ -259,7 +260,7 @@ class Dartdoc extends PackageBuilder {
} else {
// Error messages are orphaned by design and do not appear in the search
// index.
if (relativeFullPath != '__404error.html') {
if (<String>['__404error.html', 'categories.json'].contains(fullPath)) {
_warn(packageGraph, PackageWarning.orphanedFile, fullPath,
normalOrigin);
}
Expand Down
49 changes: 49 additions & 0 deletions lib/resources/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,55 @@ dl dt.callable .name {
text-decoration: line-through;
}

.category.linked {
font-weight: bold;
opacity: 1;
}

/* Colors for category based on categoryOrder in dartdoc_options.config. */
.category.cp-0 {
background-color: #54b7c4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do these show up? Do we need the ability to change the background color of category labels?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Categories are tagged with cp-N where N is the position in category order, and this is used to give some color to the background of the category label. If a package has its own style sheet it can override those either using category order or the category name, which is also encoded into the style.

}

.category.cp-1 {
background-color: #54c47f
}

.category.cp-2 {
background-color: #c4c254
}

.category.cp-3 {
background-color: #c49f54
}

.category.cp-4 {
background-color: #c45465
}

.category.cp-5 {
background-color: #c454c4
}

.category a {
color: white;
}

.category {
vertical-align: text-top;
padding: 4px;
font-size: 12px;
border-radius: 4px;
background-color: #B6B6B6;
text-transform: uppercase;
color: white;
opacity: .5;
}

h1 .category {
vertical-align: middle;
}

p.firstline {
font-weight: bold;
}
Expand Down
Loading