-
Notifications
You must be signed in to change notification settings - Fork 127
Cleanup categorization to simplify template generation migration #2875
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:collection/collection.dart'; | ||
import 'package:dartdoc/src/model/model.dart'; | ||
|
||
final RegExp _categoryRegExp = RegExp( | ||
|
@@ -49,23 +50,23 @@ abstract class Categorization implements ModelElement { | |
return rawDocs; | ||
} | ||
|
||
bool get hasSubCategoryNames => subCategoryNames!.isNotEmpty; | ||
bool get hasSubCategoryNames => subCategoryNames?.isNotEmpty ?? false; | ||
List<String>? _subCategoryNames; | ||
|
||
/// Either a set of strings containing all declared subcategories for this symbol, | ||
/// or a set containing Null if none were declared. | ||
/// or 'null' if none were declared. | ||
List<String>? get subCategoryNames { | ||
// TODO(jcollins-g): avoid side-effect dependency | ||
if (_subCategoryNames == null) documentationLocal; | ||
return _subCategoryNames; | ||
} | ||
|
||
@override | ||
bool get hasCategoryNames => categoryNames!.isNotEmpty; | ||
bool get hasCategoryNames => categoryNames?.isNotEmpty ?? false; | ||
List<String>? _categoryNames; | ||
|
||
/// Either a set of strings containing all declared categories for this symbol, | ||
/// or a set containing Null if none were declared. | ||
/// or 'null' if none were declared. | ||
List<String>? get categoryNames { | ||
// TODO(jcollins-g): avoid side-effect dependency | ||
if (_categoryNames == null) documentationLocal; | ||
|
@@ -75,40 +76,42 @@ abstract class Categorization implements ModelElement { | |
bool get hasImage => image!.isNotEmpty; | ||
String? _image; | ||
|
||
/// Either a URI to a defined image, or the empty string if none | ||
/// was declared. | ||
/// Either a URI to a defined image, | ||
/// or 'null' if one was not declared. | ||
String? get image { | ||
// TODO(jcollins-g): avoid side-effect dependency | ||
if (_image == null) documentationLocal; | ||
return _image; | ||
} | ||
|
||
bool get hasSamples => samples!.isNotEmpty; | ||
bool get hasSamples => samples?.isNotEmpty ?? false; | ||
String? _samples; | ||
|
||
/// Either a URI to documentation with samples, or the empty string if none | ||
/// was declared. | ||
/// Either a URI to documentation with samples, | ||
/// or 'null' if one was not declared. | ||
String? get samples { | ||
// TODO(jcollins-g): avoid side-effect dependency | ||
if (_samples == null) documentationLocal; | ||
return _samples; | ||
} | ||
|
||
Iterable<Category?>? _categories; | ||
late final Iterable<Category> categories = () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 Love it |
||
var categoryNames = this.categoryNames; | ||
if (categoryNames == null) { | ||
return <Category>[]; | ||
} | ||
|
||
Iterable<Category?> get categories { | ||
_categories ??= categoryNames! | ||
return categoryNames | ||
.map((n) => package?.nameToCategory[n]) | ||
.where((c) => c != null) | ||
.whereNotNull() | ||
.toList() | ||
..sort(); | ||
return _categories!; | ||
} | ||
}(); | ||
|
||
@override | ||
Iterable<Category?> get displayedCategories { | ||
Iterable<Category> get displayedCategories { | ||
if (config.showUndocumentedCategories) return categories; | ||
return categories.where((c) => c!.isDocumented); | ||
return categories.where((c) => c.isDocumented); | ||
} | ||
|
||
bool? _hasCategorization; | ||
|
@@ -117,6 +120,6 @@ abstract class Categorization implements ModelElement { | |
/// declared. | ||
late final bool hasCategorization = () { | ||
if (_hasCategorization == null) documentationLocal; | ||
return _hasCategorization!; | ||
return _hasCategorization ?? false; | ||
}(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm, returns a List.... 🤷 ; to fix later I suppose.