Skip to content

Support flutter in cross-links and add tests #1680

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 18 commits into from
May 1, 2018
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ branches:
cache:
directories:
- $HOME/.pub-cache
- $HOME/.dartdoc_grinder
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@ Unrecognized options will be ignored. Supported options:
* **linkTo**: For other packages depending on this one, if this map is defined those packages
will use the settings here to control how hyperlinks to the package are generated.
This will override the default for packages hosted on pub.dartlang.org.
* url: A string indicating the base URL for documentation of this package. The following
strings will be substituted in to complete the URL:
* **url**: A string indicating the base URL for documentation of this package. Ordinarily
you do not need to set this in the package: consider --link-to-hosted and
--link-to-sdks instead of this option if you need to build your own website with
dartdoc.

The following strings will be substituted in to complete the URL:
* `%b%`: The branch as indicated by text in the version. 2.0.0-dev.3 is branch "dev".
No branch is considered to be "stable".
* `%n%`: The name of this package, as defined in pubspec.yaml.
* `%v%`: The version of this package as defined in pubspec.yaml.

Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ analyzer:
- 'lib/templates/*.html'
- 'pub.dartlang.org/**'
- 'testing/**'
- 'testing/test_package_flutter_plugin/**'
linter:
rules:
- annotate_overrides
Expand Down
2 changes: 1 addition & 1 deletion bin/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ main(List<String> arguments) async {
logInfo("Generating documentation for '${config.topLevelPackageMeta}' into "
"${outputDir.absolute.path}${Platform.pathSeparator}");

Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(config, outputDir);
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style question: since you're creatine an instance here, I'd have expected a named factory constructor instead of a static; any reason for that?

EDIT: like withoutGenerators(..)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asynchronous factory (or normal) constructors don't work in Dart. dart-lang/sdk#23115

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, right! I didn't notice the await. Thanks for clarifying. 👍


dartdoc.onCheckProgress.listen(logProgress);
await Chain.capture(() async {
Expand Down
55 changes: 28 additions & 27 deletions lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,30 @@ const String dartdocVersion = '0.18.1';
/// directory.
class Dartdoc extends PackageBuilder {
final List<Generator> generators;
final Directory outputDir;
final Set<String> writtenFiles = new Set();
Directory outputDir;

// Fires when the self checks make progress.
final StreamController<String> _onCheckProgress =
new StreamController(sync: true);

Dartdoc._(DartdocOptionContext config, this.generators, this.outputDir)
: super(config) {
Dartdoc._(DartdocOptionContext config, this.generators) : super(config) {
outputDir = new Directory(config.output)..createSync(recursive: true);
generators.forEach((g) => g.onFileCreated.listen(logProgress));
}

/// An asynchronous factory method that builds Dartdoc's file writers
/// and returns a Dartdoc object with them.
static withDefaultGenerators(
DartdocOptionContext config, Directory outputDir) async {
static withDefaultGenerators(DartdocOptionContext config) async {
List<Generator> generators =
await initGenerators(config as GeneratorContext);
return new Dartdoc._(config, generators, outputDir);
return new Dartdoc._(config, generators);
}

/// Basic synchronous factory that gives a stripped down Dartdoc that won't
/// use generators. Useful for testing.
factory Dartdoc.withoutGenerators(
DartdocOptionContext config, Directory outputDir) {
return new Dartdoc._(config, [], outputDir);
factory Dartdoc.withoutGenerators(DartdocOptionContext config) {
return new Dartdoc._(config, []);
}

Stream<String> get onCheckProgress => _onCheckProgress.stream;
Expand Down Expand Up @@ -345,25 +343,28 @@ class Dartdoc extends PackageBuilder {
// (newPathToCheck, newFullPath)
Set<Tuple2<String, String>> toVisit = new Set();

final RegExp ignoreHyperlinks = new RegExp(r'^(https:|http:|mailto:|ftp:)');
for (String href in stringLinks) {
Uri uri;
try {
uri = Uri.parse(href);
} catch (FormatError) {}

if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
var full;
if (baseHref != null) {
full = '${pathLib.dirname(pathToCheck)}/$baseHref/$href';
} else {
full = '${pathLib.dirname(pathToCheck)}/$href';
}
var newPathToCheck = pathLib.normalize(full);
String newFullPath = pathLib.joinAll([origin, newPathToCheck]);
newFullPath = pathLib.normalize(newFullPath);
if (!visited.contains(newFullPath)) {
toVisit.add(new Tuple2(newPathToCheck, newFullPath));
visited.add(newFullPath);
if (!href.startsWith(ignoreHyperlinks)) {
Uri uri;
try {
uri = Uri.parse(href);
} catch (FormatError) {}

if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
var full;
if (baseHref != null) {
full = '${pathLib.dirname(pathToCheck)}/$baseHref/$href';
} else {
full = '${pathLib.dirname(pathToCheck)}/$href';
}
var newPathToCheck = pathLib.normalize(full);
String newFullPath = pathLib.joinAll([origin, newPathToCheck]);
newFullPath = pathLib.normalize(newFullPath);
if (!visited.contains(newFullPath)) {
toVisit.add(new Tuple2(newPathToCheck, newFullPath));
visited.add(newFullPath);
}
}
}
}
Expand Down
Loading