Skip to content

Determine file extensions on a per-package basis #2134

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 3 commits into from
Jan 22, 2020
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
5 changes: 5 additions & 0 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,9 @@ class DartdocOptionContext extends DartdocOptionContextBase
bool isPackageExcluded(String name) =>
excludePackages.any((pattern) => name == pattern);

/// Output format, e.g. 'html', 'md'
String get format => optionSet['format'].valueAt(context);

// TODO(jdkoren): temporary while we confirm href base behavior doesn't break important clients
bool get useBaseHref => optionSet['useBaseHref'].valueAt(context);
}
Expand Down Expand Up @@ -1633,6 +1636,8 @@ Future<List<DartdocOption>> createDartdocOptions() async {
'pages, and please file an issue on Github.',
negatable: false,
hide: true),
// TODO(jdkoren): Unhide when we have good support for another format.
DartdocOptionArgOnly<String>('format', 'html', hide: true),
// TODO(jcollins-g): refactor so there is a single static "create" for
// each DartdocOptionContext that traverses the inheritance tree itself.
]
Expand Down
5 changes: 0 additions & 5 deletions lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ mixin GeneratorContext on DartdocOptionContextBase {

String get templatesDir => optionSet['templatesDir'].valueAt(context);

/// Output format, e.g. 'html', 'md'
String get format => optionSet['format'].valueAt(context);

// TODO(jdkoren): duplicated temporarily so that GeneratorContext is enough for configuration.
bool get useBaseHref => optionSet['useBaseHref'].valueAt(context);
}
Expand Down Expand Up @@ -141,7 +138,5 @@ Future<List<DartdocOption>> createGeneratorOptions() async {
'they must begin with an underscore, and references to them must '
'omit the leading underscore (e.g. use {{>foo}} to reference the '
'partial template named _foo).'),
// TODO(jdkoren): Unhide when we have good support for another format.
DartdocOptionArgOnly<String>('format', 'html', hide: true),
];
}
10 changes: 6 additions & 4 deletions lib/src/model/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ class Category extends Nameable
@override
String get fullyQualifiedName => name;

String get filePath => 'topics/${name}-topic.html';
String get fileType => package.fileType;

String get filePath => 'topics/$name-topic.$fileType';

@override
String get href => isCanonical ? '${package.baseHref}$filePath' : null;

String get categorization => _renderer.renderCategoryLabel(this);
String get categorization => _categoryRenderer.renderCategoryLabel(this);

String get linkedName => _renderer.renderLinkedName(this);
String get linkedName => _categoryRenderer.renderLinkedName(this);

int _categoryIndex;

Expand Down Expand Up @@ -199,6 +201,6 @@ class Category extends Nameable
@override
Iterable<Typedef> get typedefs => _typedefs;

CategoryRenderer get _renderer =>
CategoryRenderer get _categoryRenderer =>
packageGraph.rendererFactory.categoryRenderer;
}
2 changes: 1 addition & 1 deletion lib/src/model/class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class Class extends Container
ModelElement get enclosingElement => library;

@override
String get fileName => "${name}-class.html";
String get fileName => '$name-class.$fileType';

@override
String get filePath => '${library.dirName}/$fileName';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Field extends ModelElement
FieldElement get field => (element as FieldElement);

@override
String get fileName => isConst ? '$name-constant.html' : '$name.html';
String get fileName => '${isConst ? '$name-constant' : name}.$fileType';

String _sourceCode;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
}

@override
String get fileName => '$dirName-library.html';
String get fileName => '$dirName-library.$fileType';

@override
String get filePath => '${library.dirName}/$fileName';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Mixin extends Class {
bool get hasModifiers => super.hasModifiers || hasPublicSuperclassConstraints;

@override
String get fileName => "${name}-mixin.html";
String get fileName => '$name-mixin.$fileType';

@override
String get kind => 'mixin';
Expand Down
4 changes: 3 additions & 1 deletion lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,9 @@ abstract class ModelElement extends Canonicalization
return '';
}

String get fileName => "${name}.html";
String get fileName => '$name.$fileType';

String get fileType => package.fileType;

String get filePath;

Expand Down
5 changes: 2 additions & 3 deletions lib/src/model/operator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ class Operator extends Method {
String get fileName {
var actualName = super.name;
if (friendlyNames.containsKey(actualName)) {
return "operator_${friendlyNames[actualName]}.html";
} else {
return '$actualName.html';
actualName = "operator_${friendlyNames[actualName]}";
}
return '$actualName.$fileType';
}

@override
Expand Down
14 changes: 13 additions & 1 deletion lib/src/model/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,19 @@ class Package extends LibraryContainer
@override
String get enclosingName => packageGraph.defaultPackageName;

String get filePath => 'index.html';
String get filePath => 'index.$fileType';

String get fileType {
// TODO(jdkoren): Provide a way to determine file type of a remote package's
// docs. Perhaps make this configurable through dartdoc options.
// In theory, a remote package could be documented in any supported format.
// In practice, devs depend on Dart, Flutter, and/or packages fetched
// from pub.dev, and we know that all of those use html docs.
if (package.documentedWhere == DocumentLocation.remote) {
return 'html';
}
return config.format;
}

@override
String get fullyQualifiedName => 'package:$name';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/top_level_variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class TopLevelVariable extends ModelElement
}

@override
String get fileName => isConst ? '$name-constant.html' : '$name.html';
String get fileName => '${isConst ? '$name-constant' : name}.$fileType';

@override
DefinedElementType get modelType => super.modelType;
Expand Down
12 changes: 12 additions & 0 deletions lib/src/render/file_type_renderer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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.

abstract class FileTypeRenderer {
String get fileType;
}

class HtmlFileTypeRenderer extends FileTypeRenderer {
@override
String get fileType => 'html';
}