Skip to content

add a --favicon flag #1142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ main(List<String> 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);
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ final String defaultOutDir = p.join('doc', 'api');

/// Initialize and setup the generators.
Future<List<Generator>> initGenerators(String url, List<String> headerFilePaths,
List<String> footerFilePaths, String relCanonicalPrefix) async {
List<String> footerFilePaths, String relCanonicalPrefix,
{String faviconPath}) async {
return [
await HtmlGenerator.create(
url: url,
headers: headerFilePaths,
footers: footerFilePaths,
relCanonicalPrefix: relCanonicalPrefix,
toolVersion: version)
toolVersion: version,
faviconPath: faviconPath)
];
}

Expand Down
13 changes: 9 additions & 4 deletions lib/src/html/html_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class HtmlGenerator extends Generator {
final String _relCanonicalPrefix;
final Templates _templates;
final String _toolVersion;
final String faviconPath;

final StreamController<File> _onFileCreated =
new StreamController(sync: true);
Expand All @@ -51,23 +52,27 @@ class HtmlGenerator extends Generator {
List<String> headers,
List<String> footers,
String relCanonicalPrefix,
String toolVersion}) async {
String toolVersion,
String faviconPath}) async {
var templates =
await Templates.create(headerPaths: headers, footerPaths: footers);

if (toolVersion == null) {
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();
}
}
9 changes: 7 additions & 2 deletions lib/src/html/html_generator_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,25 @@ class HtmlGeneratorInstance implements HtmlOptions {
final StreamController<File> _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();

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() {
Expand Down