From d26cc5e617cda16893e73bb6f2f1aa8a20e8c82c Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Thu, 7 Apr 2016 18:41:02 -0700 Subject: [PATCH] add a --favicon flag --- CHANGELOG.md | 4 ++++ bin/dartdoc.dart | 5 ++++- lib/dartdoc.dart | 6 ++++-- lib/src/html/html_generator.dart | 13 +++++++++---- lib/src/html/html_generator_instance.dart | 9 +++++++-- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5357137e3c..3e1c70b337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## unreleased +* [enhancement] added a `--favicon` option to specify a favicon to use for the + generated docs + ## 0.9.3+1 * [bug] fix an issue with including duplicated libraries diff --git a/bin/dartdoc.dart b/bin/dartdoc.dart index f8e903e504..150f02cfcc 100644 --- a/bin/dartdoc.dart +++ b/bin/dartdoc.dart @@ -115,7 +115,8 @@ main(List arguments) async { print(''); var generators = await initGenerators( - url, headerFilePaths, footerFilePaths, args['rel-canonical-prefix']); + url, headerFilePaths, footerFilePaths, args['rel-canonical-prefix'], + faviconPath: args['favicon']); for (var generator in generators) { generator.onFileCreated.listen(_onProgress); @@ -204,6 +205,8 @@ ArgParser _createArgsParser() { 'Learn more at https://goo.gl/gktN6F.'); parser.addFlag('include-source', help: 'Show source code blocks', negatable: true, defaultsTo: true); + parser.addOption('favicon', + help: 'A path to a favicon for the generated docs'); return parser; } diff --git a/lib/dartdoc.dart b/lib/dartdoc.dart index 5a035c900c..1a54e4fc35 100644 --- a/lib/dartdoc.dart +++ b/lib/dartdoc.dart @@ -45,14 +45,16 @@ final String defaultOutDir = p.join('doc', 'api'); /// Initialize and setup the generators. Future> initGenerators(String url, List headerFilePaths, - List footerFilePaths, String relCanonicalPrefix) async { + List footerFilePaths, String relCanonicalPrefix, + {String faviconPath}) async { return [ await HtmlGenerator.create( url: url, headers: headerFilePaths, footers: footerFilePaths, relCanonicalPrefix: relCanonicalPrefix, - toolVersion: version) + toolVersion: version, + faviconPath: faviconPath) ]; } diff --git a/lib/src/html/html_generator.dart b/lib/src/html/html_generator.dart index 716fd1941d..9b93482850 100644 --- a/lib/src/html/html_generator.dart +++ b/lib/src/html/html_generator.dart @@ -39,6 +39,7 @@ class HtmlGenerator extends Generator { final String _relCanonicalPrefix; final Templates _templates; final String _toolVersion; + final String faviconPath; final StreamController _onFileCreated = new StreamController(sync: true); @@ -51,7 +52,8 @@ class HtmlGenerator extends Generator { List headers, List footers, String relCanonicalPrefix, - String toolVersion}) async { + String toolVersion, + String faviconPath}) async { var templates = await Templates.create(headerPaths: headers, footerPaths: footers); @@ -59,15 +61,18 @@ class HtmlGenerator extends Generator { toolVersion = 'unknown'; } - return new HtmlGenerator._(url, relCanonicalPrefix, templates, toolVersion); + return new HtmlGenerator._(url, relCanonicalPrefix, templates, toolVersion, + faviconPath: faviconPath); } HtmlGenerator._( - this._url, this._relCanonicalPrefix, this._templates, this._toolVersion); + this._url, this._relCanonicalPrefix, this._templates, this._toolVersion, + {this.faviconPath}); Future generate(Package package, Directory out) { return new HtmlGeneratorInstance(_toolVersion, _url, _templates, package, - out, _onFileCreated, _relCanonicalPrefix) + out, _onFileCreated, _relCanonicalPrefix, + faviconPath: faviconPath) .generate(); } } diff --git a/lib/src/html/html_generator_instance.dart b/lib/src/html/html_generator_instance.dart index 4198ae69d7..3e4fb364b1 100644 --- a/lib/src/html/html_generator_instance.dart +++ b/lib/src/html/html_generator_instance.dart @@ -24,9 +24,11 @@ class HtmlGeneratorInstance implements HtmlOptions { final StreamController _onFileCreated; final String relCanonicalPrefix; final String toolVersion; + final String faviconPath; HtmlGeneratorInstance(this.toolVersion, this.url, this._templates, - this.package, this.out, this._onFileCreated, this.relCanonicalPrefix); + this.package, this.out, this._onFileCreated, this.relCanonicalPrefix, + {this.faviconPath}); Future generate() async { if (!out.existsSync()) out.createSync(); @@ -34,10 +36,13 @@ class HtmlGeneratorInstance implements HtmlOptions { if (package != null) { _generateDocs(); _generateSearchIndex(); - // TODO: generate sitemap } await _copyResources(); + if (faviconPath != null) { + File file = new File(path.join(out.path, 'static-assets', 'favicon.png')); + file.writeAsBytesSync(new File(faviconPath).readAsBytesSync()); + } } void _generateSearchIndex() {