Skip to content

Commit 4f27b8f

Browse files
committed
Recombine options into one GeneratorContext
1 parent 5e4676b commit 4f27b8f

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

lib/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const String dartdocVersion = packageVersion;
3939

4040
/// Helper class that consolidates option contexts for instantiating generators.
4141
class DartdocGeneratorOptionContext extends DartdocOptionContext
42-
with BaseGeneratorContext, HtmlGeneratorContext {
42+
with GeneratorContext {
4343
DartdocGeneratorOptionContext(DartdocOptionSet optionSet, Directory dir)
4444
: super(optionSet, dir);
4545
}

lib/src/generator.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'dart:io' show Directory;
1010
import 'dart:isolate';
1111

1212
import 'package:dartdoc/src/dartdoc_options.dart';
13-
import 'package:dartdoc/src/html/html_generator.dart';
1413
import 'package:dartdoc/src/model/model.dart' show PackageGraph;
1514
import 'package:dartdoc/src/package_meta.dart';
1615

@@ -33,7 +32,7 @@ abstract class Generator {
3332
}
3433

3534
/// Dartdoc options related to generators generally.
36-
mixin BaseGeneratorContext on DartdocOptionContextBase {
35+
mixin GeneratorContext on DartdocOptionContextBase {
3736
List<String> get footer => optionSet['footer'].valueAt(context);
3837

3938
/// _footerText is only used to construct synthetic options.
@@ -47,6 +46,11 @@ mixin BaseGeneratorContext on DartdocOptionContextBase {
4746

4847
bool get prettyIndexJson => optionSet['prettyIndexJson'].valueAt(context);
4948

49+
String get favicon => optionSet['favicon'].valueAt(context);
50+
51+
String get relCanonicalPrefix =>
52+
optionSet['relCanonicalPrefix'].valueAt(context);
53+
5054
String get templatesDir => optionSet['templatesDir'].valueAt(context);
5155
}
5256

@@ -106,6 +110,15 @@ Future<List<DartdocOption>> createGeneratorOptions() async {
106110
'Generates `index.json` with indentation and newlines. The file is '
107111
'larger, but it\'s also easier to diff.',
108112
negatable: false),
113+
DartdocOptionArgFile<String>('favicon', null,
114+
isFile: true,
115+
help: 'A path to a favicon for the generated docs.',
116+
mustExist: true),
117+
DartdocOptionArgOnly<String>('relCanonicalPrefix', null,
118+
help:
119+
'If provided, add a rel="canonical" prefixed with provided value. '
120+
'Consider using if building many versions of the docs for public '
121+
'SEO; learn more at https://goo.gl/gktN6F.'),
109122
DartdocOptionArgOnly<String>("templatesDir", null,
110123
isDir: true,
111124
mustExist: true,
@@ -119,5 +132,5 @@ Future<List<DartdocOption>> createGeneratorOptions() async {
119132
'they must begin with an underscore, and references to them must '
120133
'omit the leading underscore (e.g. use {{>foo}} to reference the '
121134
'partial template _foo.html).'),
122-
]..addAll(createHtmlGeneratorOptions());
135+
];
123136
}

lib/src/html/html_generator.dart

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class HtmlGeneratorOptions implements HtmlOptions {
141141
}
142142

143143
/// Initialize and setup the generators.
144-
Future<List<Generator>> initHtmlGenerators(HtmlGeneratorContext context) async {
144+
Future<List<Generator>> initHtmlGenerators(GeneratorContext context) async {
145145
// TODO(jcollins-g): Rationalize based on GeneratorContext all the way down
146146
// through the generators.
147147
HtmlGeneratorOptions options = HtmlGeneratorOptions(
@@ -160,25 +160,3 @@ Future<List<Generator>> initHtmlGenerators(HtmlGeneratorContext context) async {
160160
)
161161
];
162162
}
163-
164-
/// Dartdoc options related to html generation.
165-
mixin HtmlGeneratorContext on BaseGeneratorContext {
166-
String get favicon => optionSet['favicon'].valueAt(context);
167-
168-
String get relCanonicalPrefix =>
169-
optionSet['relCanonicalPrefix'].valueAt(context);
170-
}
171-
172-
List<DartdocOption> createHtmlGeneratorOptions() {
173-
return <DartdocOption>[
174-
DartdocOptionArgFile<String>('favicon', null,
175-
isFile: true,
176-
help: 'A path to a favicon for the generated docs.',
177-
mustExist: true),
178-
DartdocOptionArgOnly<String>('relCanonicalPrefix', null,
179-
help:
180-
'If provided, add a rel="canonical" prefixed with provided value. '
181-
'Consider using if\nbuilding many versions of the docs for public '
182-
'SEO; learn more at https://goo.gl/gktN6F.'),
183-
];
184-
}

0 commit comments

Comments
 (0)