Skip to content

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 2 commits into from
Dec 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions lib/src/model/categorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Copy link
Member

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.

/// 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;
Expand All @@ -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 = () {
Copy link
Member

Choose a reason for hiding this comment

The 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;
Expand All @@ -117,6 +120,6 @@ abstract class Categorization implements ModelElement {
/// declared.
late final bool hasCategorization = () {
if (_hasCategorization == null) documentationLocal;
return _hasCategorization!;
return _hasCategorization ?? false;
}();
}