-
Notifications
You must be signed in to change notification settings - Fork 124
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
Conversation
🍾 very cool! I'll look through the PR now.
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 - |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/src/dartdoc_options.dart
Outdated
/// 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>) { |
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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.
lib/src/model.dart
Outdated
} | ||
_categoryNames = _categorySet.toList()..sort(); | ||
_subCategoryNames = _subCategorySet.toList()..sort(); | ||
if (_image == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_image ??= '';
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/src/model.dart
Outdated
|
||
// TODO: implement location |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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.
lib/src/model.dart
Outdated
@override | ||
String get location => pathLib.toUri(documentationFile.file.path).toString(); | ||
|
||
// TODO: implement locationPieces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
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
lib/src/model.dart
Outdated
bool get isCanonical => categoryDefinition != null; | ||
|
||
@override | ||
String get kind => 'API'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo added
lib/src/model.dart
Outdated
@@ -5166,6 +5496,10 @@ class Package extends LibraryContainer | |||
|
|||
@override | |||
Element get element => null; | |||
|
|||
// TODO: implement containerOrder |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, deleted
|
@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. |
@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. |
@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. |
@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 |
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:
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.