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

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented Sep 12, 2018

Fixes #1681, #1353.

I'm pretty excited about this PR, it has been a long time coming. I'm especially open to suggestions on how to do the style sheet for this, color selection and fonts, and so forth.

This PR expands category tag handling to all top level documented items. Changes how categories are configured -- the categoryOrder flag is now replaced with a more generic "categories" section in dartdoc_options.yaml. You can now specify user-visible names for categories. Categories can now have their own top level pages which are referred to as "APIs" and you can define where to load markdown to generate those pages.

Additionally, we generate json for all category data we load.

Screenshots from the test package:

screenshot from 2018-09-12 14-03-07
screenshot from 2018-09-12 14-03-33

Future work will need to make the categories able to span package boundaries more explicitly, but this should be good enough for Flutter and most pub packages.

@googlebot googlebot added the cla: yes Google CLA check succeeded. label Sep 12, 2018
@devoncarew
Copy link
Member

devoncarew commented Sep 14, 2018

This PR expands category tag handling to all top level documented items. Changes how categories are configured -- the categoryOrder flag is now replaced with a more generic "categories" section in dartdoc_options.yaml. You can now specify user-visible names for categories. Categories can now have their own top level pages which are referred to as "APIs"

🍾 very cool! I'll look through the PR now.

I'm especially open to suggestions on how to do the style sheet for this, color selection and fonts, and so forth.

The screenshot above looks good, and it's seems clear how to parse the information out when reading it.

The name of that top category - APIs - seems a bit odd, given that all of what you're seeing is API. I guess we're calling out the explicit semantic groupings of sub-apis defined in that package? I don't know of a better name; Topics? Categories? It could be possible to go without a name for that group, and just have them bare at the top level, but I'm not sure if that would look odd.

@jcollins-g
Copy link
Contributor Author

@gspencergoog @InMatrix

Copy link
Member

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

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

lgtm; thanks for breaking this into separate commits (I didn't look at the 2nd commit - the test file regen one)


/* 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.


/// Canonical path of the markdown file used to document this category
/// (or null if undocumented).
final String documentationMarkdown;
Copy link
Member

Choose a reason for hiding this comment

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

nit: newline after the field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

/// Canonical path of the markdown file used to document this category
/// (or null if undocumented).
final String documentationMarkdown;
CategoryDefinition(this.name, this._displayName, this.documentationMarkdown);
Copy link
Member

Choose a reason for hiding this comment

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

If _displayName is optional, perhaps used a named param?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have avoided named parameters in constructors because there are situations where they aren't allowed. If you feel strongly I think it's safe to use it here.

Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, what situation? I don't have a strong preference here. I prefer named params for optional values myself because I think it makes call sites more readable, and conveys intend about the param being optional.

YamlMap yamlMap, pathLib.Context pathContext) {
List<String> categoriesInOrder = [];
Map<String, CategoryDefinition> newCategoryDefinitions = {};
for (MapEntry entry in yamlMap.entries) {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, in the new world order, it's a lot more work to parse unstructured data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hopefully this design at least compartmentalizes the ugly into whatever class is being used with the DartdocOption.

Copy link
Member

Choose a reason for hiding this comment

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

Just calling out the additional work required in these situations -

@@ -102,6 +161,11 @@ class _OptionValueWithContext<T> {
.toList() as T;
} else if (value is String) {
return pathContext.canonicalize(resolveTildePath(value as String)) as T;
} else if (value is Map<String, String>) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess we're sure this is already a Map<String, String>, and not a Map<dynamic, dynamic>?

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; resolvedValue doesn't know what to do with other types. If a class used with fromYamlMap wants this support it has to deal with it itself. That could be changed, though.

}
_categoryNames = _categorySet.toList()..sort();
_subCategoryNames = _subCategorySet.toList()..sort();
if (_image == null) {
Copy link
Member

Choose a reason for hiding this comment

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

_image ??= '';?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


// TODO: implement location
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make it a bit clearer what's missing here (what the todo refers to)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was added by an intellij fix. removed.

@override
String get location => pathLib.toUri(documentationFile.file.path).toString();

// TODO: implement locationPieces
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually forgot to implement this. That will fail an assert elsewhere if we ever warn on a subclass of this, so implemented

bool get isCanonical => categoryDefinition != null;

@override
String get kind => 'API';
Copy link
Member

Choose a reason for hiding this comment

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

I think we should noodle on a slightly better name for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo added

@@ -5166,6 +5496,10 @@ class Package extends LibraryContainer

@override
Element get element => null;

// TODO: implement containerOrder
Copy link
Member

Choose a reason for hiding this comment

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

Is this todo still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, deleted

@InMatrix
Copy link

The name of that top category - APIs - seems a bit odd, given that all of what you're seeing is API. I guess we're calling out the explicit semantic groupings of sub-apis defined in that package? I don't know of a better name; Topics? Categories? It could be possible to go without a name for that group, and just have them bare at the top level, but I'm not sure if that would look odd.

Topics sound good to me. We can also consider API Groups. Excited to see this landing. Do we need to do anything to enable this feature when generating dartdoc for Flutter? I assume some content authoring work might need to be done to create landing pages for each category and add more complete category information to classes.

@jcollins-g
Copy link
Contributor Author

@InMatrix Flutter will need some work to make this happen; as is, you won't notice an immediate change. Ideally we'd create a tool that transforms the json already checked in to flutter manually, expanding it into comment blocks in the code.

@InMatrix
Copy link

@jcollins-g I'd be interested in experimenting with this feature locally. Let me know if you have some instructions on how to do it.

@jcollins-g
Copy link
Contributor Author

@InMatrix The README is updated in this PR to hopefully give enough instructions to be worth trying it. I'll also upload a flutter branch.

@jcollins-g
Copy link
Contributor Author

@InMatrix This is a sample flutter branch using the new category system. You'll have to activate a version of dartdoc including this PR, of course, for it to work.

https://github.com/flutter/flutter/compare/master...jcollins-g:categories-test?expand=1

@jcollins-g jcollins-g merged commit 5e63ba8 into master Sep 17, 2018
@jcollins-g jcollins-g deleted the dartdoc-categories-everything branch September 17, 2018 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants