blob: 217e95a6ee3694a577408626c09ddf024196156e [file] [log] [blame]
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
/// A library containing an abstract documentation generator.
library dartdoc.generator;
import 'dart:async' show Stream, Future;
import 'package:dartdoc/dartdoc.dart';
import 'package:dartdoc/src/empty_generator.dart';
import 'package:dartdoc/src/model.dart' show PackageGraph;
import 'package:dartdoc/src/html/html_generator.dart';
/// An abstract class that defines a generator that generates documentation for
/// a given package.
///
/// Generators can generate documentation in different formats: html, json etc.
abstract class Generator {
/// Generate the documentation for the given package in the specified
/// directory. Completes the returned future when done.
Future generate(PackageGraph packageGraph, String outputDirectoryPath);
/// Fires when a file is created.
Stream<void> get onFileCreated;
/// Fetches all filenames written by this generator.
Set<String> get writtenFiles;
}
/// Initialize and setup the generators.
Future<List<Generator>> initGenerators(GeneratorContext config) async {
// TODO(jdkoren) this could support multiple generators.
var format = config.format;
switch (format) {
case 'html':
return [await createHtmlGenerator(config)];
case 'md':
return [await createEmptyGenerator(config)];
default:
throw DartdocFailure('Unsupported output format: ${format}');
}
}