Skip to content

Remove the deprecated templates-dir option #4026

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.0.0-dev

* Remove the deprecated `templates-dir` option.

## 8.3.3

* Require Dart 3.6 or later.
Expand Down
2 changes: 1 addition & 1 deletion dartdoc_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dartdoc:
linkToSource:
root: '.'
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v8.3.3/%f%#L%l%'
uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v9.0.0-dev/%f%#L%l%'
3 changes: 0 additions & 3 deletions lib/src/dartdoc_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1278,9 +1278,6 @@ class DartdocGeneratorOptionContext extends DartdocOptionContext {
String? get relCanonicalPrefix =>
optionSet['relCanonicalPrefix'].valueAt(context);

// TODO(kallentu): Remove --templates-dir completely.
String? get templatesDir => optionSet['templatesDir'].valueAt(context);

// TODO(jdkoren): duplicated temporarily so that GeneratorContext is enough for configuration.
@override
bool get useBaseHref => optionSet['useBaseHref'].valueAt(context);
Expand Down
17 changes: 0 additions & 17 deletions lib/src/generator/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,5 @@ List<DartdocOption> createGeneratorOptions(
'If provided, add a rel="canonical" prefixed with provided value. '
'Consider using if building many versions of the docs for public '
'SEO; learn more at https://goo.gl/gktN6F.'),
// TODO(kallentu): Remove --templates-dir completely.
DartdocOptionArgOnly<String?>(
'templatesDir',
null,
resourceProvider,
optionIs: OptionKind.dir,
mustExist: true,
hide: true,
help: '(deprecated) Path to a directory with templates to use instead of '
'the default ones. Directory must contain a file for each of the '
'following: 404error, category, class, constant, constructor, '
'enum, function, index, library, method, mixin, property, '
'top_level_constant, top_level_property, typedef. Partial '
'templates are supported; 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).',
),
];
}
9 changes: 0 additions & 9 deletions lib/src/generator/generator_frontend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'package:dartdoc/src/generator/generator.dart';
import 'package:dartdoc/src/generator/generator_backend.dart';
import 'package:dartdoc/src/generator/templates.dart';
import 'package:dartdoc/src/logging.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/model_utils.dart';
Expand All @@ -20,14 +19,6 @@ class GeneratorFrontEnd implements Generator {

@override
Future<void> generate(PackageGraph? packageGraph) async {
if (_generatorBackend.templates is RuntimeTemplates) {
packageGraph?.defaultPackage.warn(
PackageWarning.deprecated,
message: "The '--templates-dir' option is deprecated, and will soon no "
'longer be supported.',
);
}

await _generatorBackend.generateAdditionalFiles();

if (packageGraph == null) {
Expand Down
12 changes: 4 additions & 8 deletions lib/src/generator/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,14 @@ abstract class Templates {
String renderTopLevelProperty(TopLevelPropertyTemplateData context);
String renderTypedef(TypedefTemplateData context);

/// Creates a [Templates] instance either from the default set of templates,
/// or a custom set if the 'templatesDir' Dartdoc option is used.
/// Creates a [Templates] instance from the default set of templates.
///
/// [forceRuntimeTemplates] should only be given `true` during tests.
static Future<Templates> fromContext(DartdocGeneratorOptionContext context,
// TODO(srawlins): Remove this option, as runtime templates are no longer
// supported.
{bool forceRuntimeTemplates = false}) async {
var templatesDir = context.templatesDir;
if (templatesDir != null) {
return RuntimeTemplates._create(
context.resourceProvider.getFolder(templatesDir),
resourceProvider: context.resourceProvider);
} else if (forceRuntimeTemplates) {
if (forceRuntimeTemplates) {
var directory = await context.resourceProvider
.getResourceFolder('package:dartdoc/templates');
return RuntimeTemplates._create(directory,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const packageVersion = '8.3.3';
const packageVersion = '9.0.0-dev';
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: dartdoc
version: 8.3.3
version: 9.0.0-dev
description: A non-interactive HTML documentation generator for Dart source code.
repository: https://github.com/dart-lang/dartdoc

Expand Down
82 changes: 0 additions & 82 deletions test/options_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -438,88 +438,6 @@ class C1 {}
package.documentedCategoriesSorted.map((c) => c.name), equals(['One']));
}

void
test_templatesDirOption_referencingANonExistentDirectory_resultsInDartdocFailure() async {
await createPackage(
libFiles: [
d.file('library_1.dart', '''
library library_1;
class Foo {}
'''),
],
);
expect(
() => buildDartdoc(additionalArguments: ['--templates-dir', 'bad']),
throwsA(const TypeMatcher<DartdocFailure>().having(
(f) => f.message,
'message',
startsWith(
'Argument --templates-dir, set to bad, resolves to missing path'),
)));
}

void test_templatesDirOption_specifiesTheTemplatesToUse() async {
await createPackage(
libFiles: [
d.file('library_1.dart', '''
library library_1;
class Foo {}
'''),
],
files: [
d.dir('templates', [
d.file('_sidebar_for_container.html', 'EMPTY'),
d.file('_sidebar_for_library.html', 'EMPTY'),
d.file('404error.html', 'EMPTY'),
d.file('category.html', 'EMPTY'),
d.file('class.html', 'CLASS FILE'),
d.file('constructor.html', 'EMPTY'),
d.file('enum.html', 'EMPTY'),
d.file('extension.html', 'EMPTY'),
d.file('function.html', 'EMPTY'),
d.file('index.html', 'EMPTY'),
d.file('library.html', 'EMPTY'),
d.file('method.html', 'EMPTY'),
d.file('mixin.html', 'EMPTY'),
d.file('property.html', 'EMPTY'),
d.file('top_level_property.html', 'EMPTY'),
d.file('typedef.html', 'EMPTY'),
d.file('search.html', 'EMPTY'),
]),
],
);
var customTemplatesDir = path.join(packagePath, 'templates');
var dartdoc = await buildDartdoc(
additionalArguments: ['--templates-dir', customTemplatesDir]);
await dartdoc.generateDocsBase();
final indexContent = resourceProvider
.getFile(
path.joinAll([packagePath, 'doc', 'library_1', 'Foo-class.html']))
.readAsStringSync();
expect(indexContent, contains('CLASS FILE'));
}

void
test_templatesDirOptionReferencingAnEmptyDirectory_resultsInDartdocFailure() async {
await createPackage(
libFiles: [
d.file('library_1.dart', '''
library library_1;
class Foo {}
'''),
],
);
var customTemplatesDir = resourceProvider
.newFolder(resourceProvider.pathContext
.canonicalize(resourceProvider.convertPath('/custom_templates')))
.path;
expect(
() => buildDartdoc(
additionalArguments: ['--templates-dir', customTemplatesDir]),
throwsA(const TypeMatcher<DartdocFailure>().having((f) => f.message,
'message', startsWith('Missing required template file'))));
}

void test_emptyPackage() async {
await createPackage();
await (await buildDartdoc()).generateDocs();
Expand Down