Skip to content
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

Extension type pages. Minimal, initial support. #3530

Merged
merged 1 commit into from
Oct 17, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/src/generator/file_structure.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ abstract class FileStructure {
Library() => FileStructureImpl(format, modelElement.dirName, 'library'),
Mixin() => FileStructureImpl(format, modelElement.name, 'mixin'),
Class() => FileStructureImpl(format, modelElement.name, 'class'),
ExtensionType() =>
FileStructureImpl(format, modelElement.name, 'extension-type'),
Operator() => FileStructureImpl(format,
'operator_${operatorNames[modelElement.referenceName]}', null),
GetterSetterCombo() => FileStructureImpl(format, modelElement.name,
modelElement.isConst ? 'constant' : null),
'operator_${operatorNames[modelElement.referenceName]}', null),
GetterSetterCombo() => FileStructureImpl(
format, modelElement.name, modelElement.isConst ? 'constant' : null),
_ => FileStructureImpl(format, modelElement.name, null)
};
}
Expand Down
24 changes: 19 additions & 5 deletions lib/src/generator/generator_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DartdocGeneratorBackendOptions implements TemplateOptions {

/// An interface for classes which are responsible for outputing the generated
/// documentation.
abstract class GeneratorBackend {
abstract interface class GeneratorBackend {
FileWriter get writer;

/// Emits JSON describing the [categories] defined by the package.
Expand All @@ -82,6 +82,14 @@ abstract class GeneratorBackend {
/// Emits documentation content for the [eNum].
void generateEnum(PackageGraph packageGraph, Library library, Enum eNum);

/// Emits documentation content for the [extension].
void generateExtension(
PackageGraph packageGraph, Library library, Extension extension);

/// Emits documentation content for the [extensionType].
void generateExtensionType(
PackageGraph packageGraph, Library library, ExtensionType extensionType);

/// Emits documentation content for the [mixin].
void generateMixin(PackageGraph packageGraph, Library library, Mixin mixin);

Expand All @@ -101,10 +109,6 @@ abstract class GeneratorBackend {
void generateMethod(PackageGraph packageGraph, Library library,
Container clazz, Method method);

/// Emits documentation content for the [extension].
void generateExtension(
PackageGraph packageGraph, Library library, Extension extension);

/// Emits documentation content for the [function].
void generateFunction(
PackageGraph packageGraph, Library library, ModelFunction function);
Expand Down Expand Up @@ -235,6 +239,16 @@ abstract class GeneratorBackendBase implements GeneratorBackend {
runtimeStats.incrementAccumulator('writtenExtensionFileCount');
}

@override
void generateExtensionType(
PackageGraph packageGraph, Library library, ExtensionType extensionType) {
var data = ExtensionTypeTemplateData(
options, packageGraph, library, extensionType);
var content = templates.renderExtensionType(data);
write(writer, extensionType.filePath, data, content);
runtimeStats.incrementAccumulator('writtenExtensionTypeFileCount');
}

@override
void generateFunction(
PackageGraph packageGraph, Library library, ModelFunction function) {
Expand Down
50 changes: 50 additions & 0 deletions lib/src/generator/generator_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class GeneratorFrontEnd implements Generator {
'writtenConstructorFileCount',
'writtenEnumFileCount',
'writtenExtensionFileCount',
'writtenExtensionTypeFileCount',
'writtenFunctionFileCount',
'writtenLibraryFileCount',
'writtenMethodFileCount',
Expand Down Expand Up @@ -188,6 +189,55 @@ class GeneratorFrontEnd implements Generator {
}
}

for (var extensionType in filterNonDocumented(lib.extensionTypes)) {
indexAccumulator.add(extensionType);
_generatorBackend.generateExtensionType(
packageGraph, lib, extensionType);

for (var constant
in filterNonDocumented(extensionType.constantFields)) {
indexAccumulator.add(constant);
_generatorBackend.generateConstant(
packageGraph, lib, extensionType, constant);
}

for (var method
in filterNonDocumented(extensionType.publicInstanceMethods)) {
indexAccumulator.add(method);
_generatorBackend.generateMethod(
packageGraph, lib, extensionType, method);
}

for (var operator
in filterNonDocumented(extensionType.instanceOperators)) {
indexAccumulator.add(operator);
_generatorBackend.generateMethod(
packageGraph, lib, extensionType, operator);
}

for (var property
in filterNonDocumented(extensionType.instanceFields)) {
indexAccumulator.add(property);
_generatorBackend.generateProperty(
packageGraph, lib, extensionType, property);
}

for (var staticField
in filterNonDocumented(extensionType.variableStaticFields)) {
indexAccumulator.add(staticField);
_generatorBackend.generateProperty(
packageGraph, lib, extensionType, staticField);
}

for (var method in filterNonDocumented(extensionType.staticMethods)) {
if (!method.isCanonical) continue;

indexAccumulator.add(method);
_generatorBackend.generateMethod(
packageGraph, lib, extensionType, method);
}
}

for (var mixin in filterNonDocumented(lib.mixins)) {
indexAccumulator.add(mixin);
_generatorBackend.generateMixin(packageGraph, lib, mixin);
Expand Down
11 changes: 11 additions & 0 deletions lib/src/generator/html_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ class HtmlGeneratorBackend extends GeneratorBackendBase {
runtimeStats.incrementAccumulator('writtenSidebarFileCount');
}

@override
void generateExtensionType(
PackageGraph packageGraph, Library library, ExtensionType extensionType) {
super.generateExtensionType(packageGraph, library, extensionType);
var data = ExtensionTypeTemplateData(
options, packageGraph, library, extensionType);
var sidebarContent = templates.renderSidebarForContainer(data);
write(writer, extensionType.sidebarPath, data, sidebarContent);
runtimeStats.incrementAccumulator('writtenSidebarFileCount');
}

@override
void generateLibrary(PackageGraph packageGraph, Library library) {
super.generateLibrary(packageGraph, library);
Expand Down
98 changes: 41 additions & 57 deletions lib/src/generator/template_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ abstract class TemplateData<T extends Documentable> extends TemplateDataBase {
@override
T get self;

String? get aboveSidebarPath;
String? get aboveSidebarPath => self.aboveSidebarPath;

String? get belowSidebarPath;
String? get belowSidebarPath => self.belowSidebarPath;

String _layoutTitle(String name, String kind, {required bool isDeprecated}) =>
_packageGraph.rendererFactory.templateRenderer
Expand Down Expand Up @@ -135,11 +135,6 @@ class PackageTemplateData extends TemplateData<Package> {
@override
Package get self => package;

@override
String? get aboveSidebarPath => null;
@override
String? get belowSidebarPath => null;

@override
String get layoutTitle =>
_layoutTitle(package.name, package.kind.toString(), isDeprecated: false);
Expand Down Expand Up @@ -201,11 +196,6 @@ class CategoryTemplateData extends TemplateData<Category>

@override
Category get self => category;

@override
String? get aboveSidebarPath => null;
@override
String? get belowSidebarPath => null;
}

class LibraryTemplateData extends TemplateData<Library>
Expand All @@ -230,11 +220,6 @@ class LibraryTemplateData extends TemplateData<Library>

@override
Library get self => library;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;
}

/// Template data for Mixin declarations.
Expand Down Expand Up @@ -290,11 +275,6 @@ abstract class InheritingContainerTemplateData<T extends InheritingContainer>
@override
T get self => clazz;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title =>
'${clazz.name} ${clazz.kind} - ${library.name} library - Dart API';
Expand Down Expand Up @@ -332,11 +312,6 @@ class ExtensionTemplateData<T extends Extension> extends TemplateData<T>
@override
T get self => extension;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title =>
'${extension.name} ${extension.kind} - ${library.name} library - Dart API';
Expand All @@ -353,6 +328,45 @@ class ExtensionTemplateData<T extends Extension> extends TemplateData<T>
List<Documentable> get navLinks => [_packageGraph.defaultPackage, library];
}

final class ExtensionTypeTemplateData<T extends ExtensionType>
extends TemplateData<T>
with OneDirectoryDown
implements TemplateDataWithLibrary<T>, TemplateDataWithContainer<T> {
final T extensionType;
@override
final Library library;

ExtensionTypeTemplateData(
super.htmlOptions,
super.packageGraph,
this.library,
this.extensionType,
);

@override
Container get container => extensionType;

@override
T get self => extensionType;

@override
String get title =>
'${extensionType.name} ${extensionType.kind} - ${library.name} library -'
' Dart API';
@override
String get metaDescription =>
'API docs for the ${extensionType.name} ${extensionType.kind} from the '
'${library.name} library, for the Dart programming language.';

@override
String get layoutTitle =>
_layoutTitle(extensionType.name, extensionType.kind.toString(),
isDeprecated: false);

@override
List<Documentable> get navLinks => [_packageGraph.defaultPackage, library];
}

class ConstructorTemplateData extends TemplateData<Constructor>
with TwoDirectoriesDown
implements
Expand All @@ -376,11 +390,6 @@ class ConstructorTemplateData extends TemplateData<Constructor>
@override
Constructor get self => constructor;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get layoutTitle => _layoutTitle(constructor.name, constructor.fullKind,
isDeprecated: constructor.isDeprecated);
Expand Down Expand Up @@ -428,11 +437,6 @@ class FunctionTemplateData extends TemplateData<ModelFunction>
@override
ModelFunction get self => function;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title =>
'${function.name} function - ${library.name} library - Dart API';
Expand Down Expand Up @@ -470,11 +474,6 @@ class MethodTemplateData extends TemplateData<Method>
@override
Method get self => method;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title =>
'${method.name} method - ${container.name} ${container.kind} - '
Expand Down Expand Up @@ -515,11 +514,6 @@ class PropertyTemplateData extends TemplateData<Field>
@override
Field get self => property;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title => '${property.name} ${property.kind} - '
'${container.name} ${container.kind} - '
Expand Down Expand Up @@ -555,11 +549,6 @@ class TypedefTemplateData extends TemplateData<Typedef>
@override
Typedef get self => typeDef;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title =>
'${typeDef.name} typedef - ${library.name} library - Dart API';
Expand Down Expand Up @@ -592,11 +581,6 @@ class TopLevelPropertyTemplateData extends TemplateData<TopLevelVariable>
@override
TopLevelVariable get self => property;

@override
String? get aboveSidebarPath => self.aboveSidebarPath;
@override
String? get belowSidebarPath => self.belowSidebarPath;

@override
String get title =>
'${property.name} $_type - ${library.name} library - Dart API';
Expand Down
Loading