6
6
library dartdoc.generator;
7
7
8
8
import 'dart:async' show Stream, Future;
9
+ import 'dart:io' show Directory;
10
+ import 'dart:isolate' ;
9
11
12
+ import 'package:dartdoc/src/dartdoc_options.dart' ;
13
+ import 'package:dartdoc/src/html/html_generator.dart' ;
10
14
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;
11
18
12
19
/// An abstract class that defines a generator that generates documentation for
13
20
/// a given package.
@@ -24,3 +31,93 @@ abstract class Generator {
24
31
/// Fetches all filenames written by this generator.
25
32
Set <String > get writtenFiles;
26
33
}
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
+ }
0 commit comments