From 60819e2084ddfca401d2505fa00b435fb1773ef4 Mon Sep 17 00:00:00 2001 From: Jonathan Koren Date: Fri, 13 Dec 2019 09:42:53 -0800 Subject: [PATCH 1/8] Remove --hosted-url as it is actually unused --- lib/src/html/html_generator.dart | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/src/html/html_generator.dart b/lib/src/html/html_generator.dart index 8cac333a0a..388aa1a578 100644 --- a/lib/src/html/html_generator.dart +++ b/lib/src/html/html_generator.dart @@ -131,7 +131,6 @@ class HtmlGenerator extends Generator { } class HtmlGeneratorOptions implements HtmlOptions { - final String url; final String faviconPath; final bool prettyIndexJson; final String templatesDir; @@ -146,8 +145,7 @@ class HtmlGeneratorOptions implements HtmlOptions { final bool useBaseHref; HtmlGeneratorOptions( - {this.url, - this.relCanonicalPrefix, + {this.relCanonicalPrefix, this.faviconPath, String toolVersion, this.prettyIndexJson = false, @@ -165,7 +163,6 @@ Future> initGenerators(GeneratorContext config) async { // TODO(jcollins-g): Rationalize based on GeneratorContext all the way down // through the generators. HtmlGeneratorOptions options = HtmlGeneratorOptions( - url: config.hostedUrl, relCanonicalPrefix: config.relCanonicalPrefix, toolVersion: dartdocVersion, faviconPath: config.favicon, @@ -191,6 +188,7 @@ Future _setSdkFooterCopyrightUri() async { } } +// Dartdoc options specific to generators abstract class GeneratorContext implements DartdocOptionContext { String get favicon => optionSet['favicon'].valueAt(context); List get footer => optionSet['footer'].valueAt(context); @@ -201,7 +199,6 @@ abstract class GeneratorContext implements DartdocOptionContext { List get footerTextPaths => optionSet['footerTextPaths'].valueAt(context); List get header => optionSet['header'].valueAt(context); - String get hostedUrl => optionSet['hostedUrl'].valueAt(context); bool get prettyIndexJson => optionSet['prettyIndexJson'].valueAt(context); String get relCanonicalPrefix => optionSet['relCanonicalPrefix'].valueAt(context); @@ -248,9 +245,6 @@ Future> createGeneratorOptions() async { isFile: true, help: 'paths to header files containing HTML text.', splitCommas: true), - DartdocOptionArgOnly('hostedUrl', null, - help: - 'URL where the docs will be hosted (used to generate the sitemap).'), DartdocOptionArgOnly('prettyIndexJson', false, help: "Generates `index.json` with indentation and newlines. The file is larger, but it's also easier to diff.", From 808a37f9369e1228b62ac45ea33d353d120b12b6 Mon Sep 17 00:00:00 2001 From: Jonathan Koren Date: Wed, 18 Dec 2019 07:58:51 -0800 Subject: [PATCH 2/8] Move templatesDir option to generator context --- lib/src/dartdoc_options.dart | 13 ------------- lib/src/html/html_generator.dart | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/src/dartdoc_options.dart b/lib/src/dartdoc_options.dart index 409f87617f..73851310b5 100644 --- a/lib/src/dartdoc_options.dart +++ b/lib/src/dartdoc_options.dart @@ -1421,8 +1421,6 @@ class DartdocOptionContext extends DartdocOptionContextBase bool isPackageExcluded(String name) => excludePackages.any((pattern) => name == pattern); - String get templatesDir => optionSet['templatesDir'].valueAt(context); - // TODO(jdkoren): temporary while we confirm href base behavior doesn't break important clients bool get useBaseHref => optionSet['useBaseHref'].valueAt(context); } @@ -1627,17 +1625,6 @@ Future> createDartdocOptions() async { 'exist. Executables for different platforms are specified by ' 'giving the platform name as a key, and a list of strings as the ' 'command.'), - DartdocOptionArgOnly("templatesDir", null, - isDir: true, - mustExist: true, - hide: true, - help: - 'Path to a directory containing templates to use instead of the default ones. ' - 'Directory must contain an html 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 _foo.html).'), DartdocOptionArgOnly('useBaseHref', false, help: 'Use in generated files (legacy behavior). This option ' diff --git a/lib/src/html/html_generator.dart b/lib/src/html/html_generator.dart index 388aa1a578..c74fac2403 100644 --- a/lib/src/html/html_generator.dart +++ b/lib/src/html/html_generator.dart @@ -181,6 +181,7 @@ Future> initGenerators(GeneratorContext config) async { } Uri _sdkFooterCopyrightUri; + Future _setSdkFooterCopyrightUri() async { if (_sdkFooterCopyrightUri == null) { _sdkFooterCopyrightUri = await Isolate.resolvePackageUri( @@ -189,19 +190,26 @@ Future _setSdkFooterCopyrightUri() async { } // Dartdoc options specific to generators -abstract class GeneratorContext implements DartdocOptionContext { +abstract class GeneratorContext implements DartdocOptionContextBase { String get favicon => optionSet['favicon'].valueAt(context); + List get footer => optionSet['footer'].valueAt(context); /// _footerText is only used to construct synthetic options. // ignore: unused_element List get _footerText => optionSet['footerText'].valueAt(context); + List get footerTextPaths => optionSet['footerTextPaths'].valueAt(context); + List get header => optionSet['header'].valueAt(context); + bool get prettyIndexJson => optionSet['prettyIndexJson'].valueAt(context); + String get relCanonicalPrefix => optionSet['relCanonicalPrefix'].valueAt(context); + + String get templatesDir => optionSet['templatesDir'].valueAt(context); } Future> createGeneratorOptions() async { @@ -254,5 +262,16 @@ Future> createGeneratorOptions() async { 'If provided, add a rel="canonical" prefixed with provided value. ' 'Consider using if\nbuilding many versions of the docs for public ' 'SEO; learn more at https://goo.gl/gktN6F.'), + DartdocOptionArgOnly("templatesDir", null, + isDir: true, + mustExist: true, + hide: true, + help: + 'Path to a directory containing templates to use instead of the default ones. ' + 'Directory must contain an html 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 _foo.html).'), ]; } From 87730b0821f3ca14ff116663231375f37c8cecbf Mon Sep 17 00:00:00 2001 From: Jonathan Koren Date: Wed, 18 Dec 2019 09:16:29 -0800 Subject: [PATCH 3/8] Separate html generator options from generic ones --- lib/dartdoc.dart | 2 +- lib/src/html/html_generator.dart | 54 +++++++++++++++++++------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/dartdoc.dart b/lib/dartdoc.dart index 2c1057036d..09c115ae02 100644 --- a/lib/dartdoc.dart +++ b/lib/dartdoc.dart @@ -39,7 +39,7 @@ const String dartdocVersion = packageVersion; /// Helper class to initialize the default generators since they require /// GeneratorContext. class DartdocGeneratorOptionContext extends DartdocOptionContext - with GeneratorContext { + with BaseGeneratorContext, HtmlGeneratorContext { DartdocGeneratorOptionContext(DartdocOptionSet optionSet, Directory dir) : super(optionSet, dir); } diff --git a/lib/src/html/html_generator.dart b/lib/src/html/html_generator.dart index c74fac2403..0b657b32f7 100644 --- a/lib/src/html/html_generator.dart +++ b/lib/src/html/html_generator.dart @@ -159,7 +159,8 @@ Future> initEmptyGenerators(DartdocOptionContext config) async { } /// Initialize and setup the generators. -Future> initGenerators(GeneratorContext config) async { +Future> initGenerators( + DartdocGeneratorOptionContext config) async { // TODO(jcollins-g): Rationalize based on GeneratorContext all the way down // through the generators. HtmlGeneratorOptions options = HtmlGeneratorOptions( @@ -189,10 +190,8 @@ Future _setSdkFooterCopyrightUri() async { } } -// Dartdoc options specific to generators -abstract class GeneratorContext implements DartdocOptionContextBase { - String get favicon => optionSet['favicon'].valueAt(context); - +/// Dartdoc options related to generators generally. +mixin BaseGeneratorContext on DartdocOptionContextBase { List get footer => optionSet['footer'].valueAt(context); /// _footerText is only used to construct synthetic options. @@ -206,29 +205,33 @@ abstract class GeneratorContext implements DartdocOptionContextBase { bool get prettyIndexJson => optionSet['prettyIndexJson'].valueAt(context); + String get templatesDir => optionSet['templatesDir'].valueAt(context); +} + +/// Dartdoc options related to html generation. +mixin HtmlGeneratorContext on DartdocOptionContextBase { + String get favicon => optionSet['favicon'].valueAt(context); + String get relCanonicalPrefix => optionSet['relCanonicalPrefix'].valueAt(context); - - String get templatesDir => optionSet['templatesDir'].valueAt(context); } Future> createGeneratorOptions() async { await _setSdkFooterCopyrightUri(); return [ - DartdocOptionArgFile('favicon', null, - isFile: true, - help: 'A path to a favicon for the generated docs.', - mustExist: true), DartdocOptionArgFile>('footer', [], isFile: true, - help: 'paths to footer files containing HTML text.', + help: + 'Paths to files with content to add to page footers, but possibly ' + 'outside of dedicated footer elements for the generator (e.g. ' + 'outside of