Skip to content

Commit a7a7de5

Browse files
committed
roll up a BUNCH of args into an options class
1 parent 550d2bd commit a7a7de5

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

lib/dartdoc.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,20 @@ Future<List<Generator>> initGenerators(String url, List<String> headerFilePaths,
5050
{String faviconPath,
5151
bool useCategories: false,
5252
bool prettyIndexJson: false}) async {
53+
var options = new HtmlGeneratorOptions(
54+
url: url,
55+
relCanonicalPrefix: relCanonicalPrefix,
56+
toolVersion: version,
57+
faviconPath: faviconPath,
58+
useCategories: useCategories,
59+
prettyIndexJson: prettyIndexJson);
60+
5361
return [
5462
await HtmlGenerator.create(
55-
url: url,
56-
headers: headerFilePaths,
57-
footers: footerFilePaths,
58-
relCanonicalPrefix: relCanonicalPrefix,
59-
toolVersion: version,
60-
faviconPath: faviconPath,
61-
useCategories: useCategories,
62-
prettyIndexJson: prettyIndexJson)
63+
options: options,
64+
headers: headerFilePaths,
65+
footers: footerFilePaths,
66+
)
6367
];
6468
}
6569

lib/src/html/html_generator.dart

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import '../model.dart';
1212
import 'html_generator_instance.dart';
1313
import 'templates.dart';
1414

15-
String dartdocVersion = 'unknown';
16-
1715
typedef String Renderer(String input);
1816

1917
// Generation order for libraries:
@@ -35,13 +33,8 @@ typedef String Renderer(String input);
3533
// methods
3634

3735
class HtmlGenerator extends Generator {
38-
final String _url;
39-
final String _relCanonicalPrefix;
4036
final Templates _templates;
41-
final String _toolVersion;
42-
final String faviconPath;
43-
final bool useCategories;
44-
final bool prettyIndexJson;
37+
final HtmlGeneratorOptions _options;
4538

4639
final StreamController<File> _onFileCreated =
4740
new StreamController(sync: true);
@@ -51,38 +44,40 @@ class HtmlGenerator extends Generator {
5144

5245
/// [url] - optional URL for where the docs will be hosted.
5346
static Future<HtmlGenerator> create(
54-
{String url,
47+
{HtmlGeneratorOptions options,
5548
List<String> headers,
56-
List<String> footers,
57-
String relCanonicalPrefix,
58-
String toolVersion,
59-
String faviconPath,
60-
bool useCategories: false,
61-
bool prettyIndexJson: false}) async {
49+
List<String> footers}) async {
6250
var templates =
6351
await Templates.create(headerPaths: headers, footerPaths: footers);
6452

65-
if (toolVersion == null) {
66-
toolVersion = 'unknown';
67-
}
68-
69-
return new HtmlGenerator._(url, relCanonicalPrefix, templates, toolVersion,
70-
faviconPath: faviconPath,
71-
useCategories: useCategories,
72-
prettyIndexJson: prettyIndexJson);
53+
return new HtmlGenerator._(
54+
options ?? new HtmlGeneratorOptions(), templates);
7355
}
7456

75-
HtmlGenerator._(
76-
this._url, this._relCanonicalPrefix, this._templates, this._toolVersion,
77-
{this.faviconPath, this.useCategories, this.prettyIndexJson: false});
57+
HtmlGenerator._(this._options, this._templates);
7858

7959
@override
8060
Future generate(Package package, Directory out) {
81-
return new HtmlGeneratorInstance(_toolVersion, _url, _templates, package,
82-
out, _onFileCreated, _relCanonicalPrefix,
83-
faviconPath: faviconPath,
84-
useCategories: useCategories,
85-
prettyIndexJson: prettyIndexJson)
61+
return new HtmlGeneratorInstance(
62+
_options, _templates, package, out, _onFileCreated)
8663
.generate();
8764
}
8865
}
66+
67+
class HtmlGeneratorOptions {
68+
final String url;
69+
final String relCanonicalPrefix;
70+
final String faviconPath;
71+
final String toolVersion;
72+
final bool useCategories;
73+
final bool prettyIndexJson;
74+
75+
HtmlGeneratorOptions(
76+
{this.url,
77+
this.relCanonicalPrefix,
78+
this.faviconPath,
79+
String toolVersion,
80+
this.useCategories: false,
81+
this.prettyIndexJson: false})
82+
: this.toolVersion = toolVersion ?? 'unknown';
83+
}

lib/src/html/html_generator_instance.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,31 @@ import 'package:collection/collection.dart' show compareNatural;
1111
import 'package:path/path.dart' as path;
1212

1313
import '../model.dart';
14+
import 'html_generator.dart' show HtmlGeneratorOptions;
1415
import 'resource_loader.dart' as loader;
1516
import 'resources.g.dart' as resources;
1617
import 'template_data.dart';
1718
import 'templates.dart';
1819

1920
class HtmlGeneratorInstance implements HtmlOptions {
20-
final String url;
21+
final HtmlGeneratorOptions _options;
22+
23+
String get url => _options.url;
2124
final Templates _templates;
2225
final Package package;
2326
final Directory out;
2427
final List<ModelElement> documentedElements = <ModelElement>[];
2528
final StreamController<File> _onFileCreated;
2629
@override
27-
final String relCanonicalPrefix;
30+
String get relCanonicalPrefix => _options.relCanonicalPrefix;
2831
@override
29-
final String toolVersion;
30-
final String faviconPath;
31-
final bool useCategories;
32-
final bool prettyIndexJson;
33-
34-
HtmlGeneratorInstance(this.toolVersion, this.url, this._templates,
35-
this.package, this.out, this._onFileCreated, this.relCanonicalPrefix,
36-
{this.faviconPath, this.useCategories, this.prettyIndexJson: false});
32+
String get toolVersion => _options.toolVersion;
33+
String get faviconPath => _options.faviconPath;
34+
bool get useCategories => _options.useCategories;
35+
bool get prettyIndexJson => _options.prettyIndexJson;
36+
37+
HtmlGeneratorInstance(this._options, this._templates, this.package, this.out,
38+
this._onFileCreated);
3739

3840
Future generate() async {
3941
if (!out.existsSync()) out.createSync();

0 commit comments

Comments
 (0)