Skip to content

Commit 04013af

Browse files
committed
Move base generator context options to generator.dart
1 parent 3445706 commit 04013af

File tree

2 files changed

+97
-85
lines changed

2 files changed

+97
-85
lines changed

lib/src/generator.dart

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66
library dartdoc.generator;
77

88
import 'dart:async' show Stream, Future;
9+
import 'dart:io' show Directory;
10+
import 'dart:isolate';
911

12+
import 'package:dartdoc/src/dartdoc_options.dart';
13+
import 'package:dartdoc/src/html/html_generator.dart';
1014
import 'package:dartdoc/src/model/model.dart' show PackageGraph;
15+
import 'package:dartdoc/src/package_meta.dart';
16+
17+
import 'package:path/path.dart' as path;
1118

1219
/// An abstract class that defines a generator that generates documentation for
1320
/// a given package.
@@ -24,3 +31,93 @@ abstract class Generator {
2431
/// Fetches all filenames written by this generator.
2532
Set<String> get writtenFiles;
2633
}
34+
35+
/// Dartdoc options related to generators generally.
36+
mixin BaseGeneratorContext on DartdocOptionContextBase {
37+
List<String> get footer => optionSet['footer'].valueAt(context);
38+
39+
/// _footerText is only used to construct synthetic options.
40+
// ignore: unused_element
41+
List<String> get _footerText => optionSet['footerText'].valueAt(context);
42+
43+
List<String> get footerTextPaths =>
44+
optionSet['footerTextPaths'].valueAt(context);
45+
46+
List<String> get header => optionSet['header'].valueAt(context);
47+
48+
bool get prettyIndexJson => optionSet['prettyIndexJson'].valueAt(context);
49+
50+
String get templatesDir => optionSet['templatesDir'].valueAt(context);
51+
}
52+
53+
Uri _sdkFooterCopyrightUri;
54+
55+
Future<void> _setSdkFooterCopyrightUri() async {
56+
if (_sdkFooterCopyrightUri == null) {
57+
// TODO(jdkoren): find a way to make this not specific to HTML, or have
58+
// alternatives for other supported formats.
59+
_sdkFooterCopyrightUri = await Isolate.resolvePackageUri(
60+
Uri.parse('package:dartdoc/resources/sdk_footer_text.html'));
61+
}
62+
}
63+
64+
Future<List<DartdocOption>> createGeneratorOptions() async {
65+
await _setSdkFooterCopyrightUri();
66+
return <DartdocOption>[
67+
DartdocOptionArgFile<List<String>>('footer', [],
68+
isFile: true,
69+
help:
70+
'Paths to files with content to add to page footers, but possibly '
71+
'outside of dedicated footer elements for the generator (e.g. '
72+
'outside of <footer> for an HTML generator). To add text content '
73+
'to dedicated footer elements, use --footer-text instead.',
74+
mustExist: true,
75+
splitCommas: true),
76+
DartdocOptionArgFile<List<String>>('footerText', [],
77+
isFile: true,
78+
help: 'Paths to files with content to add to page footers (next to the '
79+
'package name and version).',
80+
mustExist: true,
81+
splitCommas: true),
82+
DartdocOptionSyntheticOnly<List<String>>(
83+
'footerTextPaths',
84+
(DartdocSyntheticOption<List<String>> option, Directory dir) {
85+
final List<String> footerTextPaths = <String>[];
86+
final PackageMeta topLevelPackageMeta =
87+
option.root['topLevelPackageMeta'].valueAt(dir);
88+
// TODO(jcollins-g): Eliminate special casing for SDK and use config file.
89+
if (topLevelPackageMeta.isSdk == true) {
90+
footerTextPaths
91+
.add(path.canonicalize(_sdkFooterCopyrightUri.toFilePath()));
92+
}
93+
footerTextPaths.addAll(option.parent['footerText'].valueAt(dir));
94+
return footerTextPaths;
95+
},
96+
isFile: true,
97+
help: 'paths to footer-text-files (adding special case for SDK)',
98+
mustExist: true,
99+
),
100+
DartdocOptionArgFile<List<String>>('header', [],
101+
isFile: true,
102+
help: 'Paths to files with content to add to page headers.',
103+
splitCommas: true),
104+
DartdocOptionArgOnly<bool>('prettyIndexJson', false,
105+
help:
106+
'Generates `index.json` with indentation and newlines. The file is '
107+
'larger, but it\'s also easier to diff.',
108+
negatable: false),
109+
DartdocOptionArgOnly<String>("templatesDir", null,
110+
isDir: true,
111+
mustExist: true,
112+
hide: true,
113+
help:
114+
'Path to a directory with templates to use instead of the default '
115+
'ones. Directory must contain a file for each of the following: '
116+
'404error, category, class, constant, constructor, enum, function, '
117+
'index, library, method, mixin, property, top_level_constant, '
118+
'top_level_property, typedef. Partial templates are supported; '
119+
'they must begin with an underscore, and references to them must '
120+
'omit the leading underscore (e.g. use {{>foo}} to reference the '
121+
'partial template _foo.html).'),
122+
]..addAll(createHtmlGeneratorOptions());
123+
}

lib/src/html/html_generator.dart

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -166,33 +166,6 @@ Future<List<Generator>> initGenerators(
166166
];
167167
}
168168

169-
Uri _sdkFooterCopyrightUri;
170-
171-
Future<void> _setSdkFooterCopyrightUri() async {
172-
if (_sdkFooterCopyrightUri == null) {
173-
_sdkFooterCopyrightUri = await Isolate.resolvePackageUri(
174-
Uri.parse('package:dartdoc/resources/sdk_footer_text.html'));
175-
}
176-
}
177-
178-
/// Dartdoc options related to generators generally.
179-
mixin BaseGeneratorContext on DartdocOptionContextBase {
180-
List<String> get footer => optionSet['footer'].valueAt(context);
181-
182-
/// _footerText is only used to construct synthetic options.
183-
// ignore: unused_element
184-
List<String> get _footerText => optionSet['footerText'].valueAt(context);
185-
186-
List<String> get footerTextPaths =>
187-
optionSet['footerTextPaths'].valueAt(context);
188-
189-
List<String> get header => optionSet['header'].valueAt(context);
190-
191-
bool get prettyIndexJson => optionSet['prettyIndexJson'].valueAt(context);
192-
193-
String get templatesDir => optionSet['templatesDir'].valueAt(context);
194-
}
195-
196169
/// Dartdoc options related to html generation.
197170
mixin HtmlGeneratorContext on DartdocOptionContextBase {
198171
String get favicon => optionSet['favicon'].valueAt(context);
@@ -201,64 +174,6 @@ mixin HtmlGeneratorContext on DartdocOptionContextBase {
201174
optionSet['relCanonicalPrefix'].valueAt(context);
202175
}
203176

204-
Future<List<DartdocOption>> createGeneratorOptions() async {
205-
await _setSdkFooterCopyrightUri();
206-
return <DartdocOption>[
207-
DartdocOptionArgFile<List<String>>('footer', [],
208-
isFile: true,
209-
help:
210-
'Paths to files with content to add to page footers, but possibly '
211-
'outside of dedicated footer elements for the generator (e.g. '
212-
'outside of <footer> for an HTML generator). To add text content '
213-
'to dedicated footer elements, use --footer-text instead.',
214-
mustExist: true,
215-
splitCommas: true),
216-
DartdocOptionArgFile<List<String>>('footerText', [],
217-
isFile: true,
218-
help: 'Paths to files with content to add to page footers (next to the '
219-
'package name and version).',
220-
mustExist: true,
221-
splitCommas: true),
222-
DartdocOptionSyntheticOnly<List<String>>(
223-
'footerTextPaths',
224-
(DartdocSyntheticOption<List<String>> option, Directory dir) {
225-
final List<String> footerTextPaths = <String>[];
226-
final PackageMeta topLevelPackageMeta =
227-
option.root['topLevelPackageMeta'].valueAt(dir);
228-
// TODO(jcollins-g): Eliminate special casing for SDK and use config file.
229-
if (topLevelPackageMeta.isSdk == true) {
230-
footerTextPaths
231-
.add(path.canonicalize(_sdkFooterCopyrightUri.toFilePath()));
232-
}
233-
footerTextPaths.addAll(option.parent['footerText'].valueAt(dir));
234-
return footerTextPaths;
235-
},
236-
isFile: true,
237-
help: 'paths to footer-text-files (adding special case for SDK)',
238-
mustExist: true,
239-
),
240-
DartdocOptionArgFile<List<String>>('header', [],
241-
isFile: true,
242-
help: 'Paths to files with content to add to page headers.',
243-
splitCommas: true),
244-
DartdocOptionArgOnly<bool>('prettyIndexJson', false,
245-
help:
246-
"Generates `index.json` with indentation and newlines. The file is larger, but it's also easier to diff.",
247-
negatable: false),
248-
DartdocOptionArgOnly<String>("templatesDir", null,
249-
isDir: true,
250-
mustExist: true,
251-
hide: true,
252-
help:
253-
'Path to a directory containing templates to use instead of the default ones. '
254-
'Directory must contain an html file for each of the following: 404error, category, '
255-
'class, constant, constructor, enum, function, index, library, method, mixin, '
256-
'property, top_level_constant, top_level_property, typedef. Partial templates are '
257-
'supported; they must begin with an underscore, and references to them must omit the '
258-
'leading underscore (e.g. use {{>foo}} to reference the partial template _foo.html).'),
259-
]..addAll(createHtmlGeneratorOptions());
260-
}
261-
262177
List<DartdocOption> createHtmlGeneratorOptions() {
263178
return <DartdocOption>[
264179
DartdocOptionArgFile<String>('favicon', null,

0 commit comments

Comments
 (0)