mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 22:31:50 +00:00
Fix build break in dartdoc.
Review URL: https://chromiumcodereview.appspot.com//9318013 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3763 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
e7917dd2e5
commit
a60cd8608d
|
@ -905,6 +905,7 @@ class Dartdoc {
|
|||
|
||||
/** Gets the URL for the documentation for [type]. */
|
||||
String typeUrl(Type type) {
|
||||
if (type.isTop) return '${sanitize(type.library.name)}.html';
|
||||
// Always get the generic type to strip off any type parameters or
|
||||
// arguments. If the type isn't generic, genericType returns `this`, so it
|
||||
// works for non-generic types too.
|
||||
|
@ -913,7 +914,10 @@ class Dartdoc {
|
|||
|
||||
/** Gets the URL for the documentation for [member]. */
|
||||
String memberUrl(Member member) {
|
||||
return '${typeUrl(member.declaringType)}#${member.name}';
|
||||
final typeUrl = typeUrl(member.declaringType);
|
||||
if (!member.isConstructor) return '$typeUrl#${member.name}';
|
||||
if (member.constructorName == '') return '$typeUrl#new:${member.name}';
|
||||
return '$typeUrl#new:${member.name}.${member.constructorName}';
|
||||
}
|
||||
|
||||
/** Gets the anchor id for the document for [member]. */
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
// Copyright (c) 2011, 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.
|
||||
|
||||
// Functions for working with files and paths.
|
||||
|
||||
/** The path to the file currently being written to, relative to [outdir]. */
|
||||
String _filePath;
|
||||
|
||||
/** The file currently being written to. */
|
||||
StringBuffer _file;
|
||||
|
||||
/** Path to generate HTML files into. */
|
||||
final _outdir = 'docs';
|
||||
|
||||
startFile(String path) {
|
||||
_filePath = path;
|
||||
_file = new StringBuffer();
|
||||
}
|
||||
|
||||
write(String s) {
|
||||
_file.add(s);
|
||||
}
|
||||
|
||||
writeln(String s) {
|
||||
write(s);
|
||||
write('\n');
|
||||
}
|
||||
|
||||
endFile() {
|
||||
String outPath = '$_outdir/$_filePath';
|
||||
world.files.createDirectory(dirname(outPath), recursive: true);
|
||||
|
||||
world.files.writeString(outPath, _file.toString());
|
||||
_filePath = null;
|
||||
_file = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts [fullPath] which is understood to be a full path from the root of
|
||||
* the generated docs to one relative to the current file.
|
||||
*/
|
||||
String relativePath(String fullPath) {
|
||||
// Don't make it relative if it's an absolute path.
|
||||
if (isAbsolute(fullPath)) return fullPath;
|
||||
|
||||
// TODO(rnystrom): Walks all the way up to root each time. Shouldn't do this
|
||||
// if the paths overlap.
|
||||
return repeat('../', countOccurrences(_filePath, '/')) + fullPath;
|
||||
}
|
||||
|
||||
/** Gets whether or not the given URL is absolute or relative. */
|
||||
bool isAbsolute(String url) {
|
||||
// TODO(rnystrom): This is a bit hackish. We consider any URL that lacks
|
||||
// a scheme to be relative.
|
||||
return const RegExp(@'^\w+:').hasMatch(url);
|
||||
}
|
||||
|
||||
/** Gets the URL to the documentation for [library]. */
|
||||
libraryUrl(Library library) => '${sanitize(library.name)}.html';
|
||||
|
||||
/** Gets the URL for the documentation for [type]. */
|
||||
typeUrl(Type type) {
|
||||
if (type.isTop) return '${sanitize(type.library.name)}.html';
|
||||
// Always get the generic type to strip off any type parameters or arguments.
|
||||
// If the type isn't generic, genericType returns `this`, so it works for
|
||||
// non-generic types too.
|
||||
return '${sanitize(type.library.name)}/${type.genericType.name}.html';
|
||||
}
|
||||
|
||||
/** Gets the URL for the documentation for [member]. */
|
||||
memberUrl(Member member) {
|
||||
final typeUrl = typeUrl(member.declaringType);
|
||||
if (!member.isConstructor) return '$typeUrl#${member.name}';
|
||||
if (member.constructorName == '') return '$typeUrl#new:${member.name}';
|
||||
return '$typeUrl#new:${member.name}.${member.constructorName}';
|
||||
}
|
||||
|
||||
/** Gets the anchor id for the document for [member]. */
|
||||
memberAnchor(Member member) => '${member.name}';
|
|
@ -2,7 +2,7 @@
|
|||
// 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.
|
||||
|
||||
/// Unit tests for dartdoc.
|
||||
/// Unit tests for doc.
|
||||
#library('dartdoc_tests');
|
||||
|
||||
#import('../../../dartdoc/dartdoc.dart', prefix: 'dd');
|
||||
|
@ -55,64 +55,70 @@ main() {
|
|||
});
|
||||
|
||||
group('isAbsolute', () {
|
||||
final doc = new dd.Dartdoc();
|
||||
|
||||
test('returns false if there is no scheme', () {
|
||||
expect(dd.isAbsolute('index.html')).isFalse();
|
||||
expect(dd.isAbsolute('foo/index.html')).isFalse();
|
||||
expect(dd.isAbsolute('foo/bar/index.html')).isFalse();
|
||||
expect(doc.isAbsolute('index.html')).isFalse();
|
||||
expect(doc.isAbsolute('foo/index.html')).isFalse();
|
||||
expect(doc.isAbsolute('foo/bar/index.html')).isFalse();
|
||||
});
|
||||
|
||||
test('returns true if there is a scheme', () {
|
||||
expect(dd.isAbsolute('http://google.com')).isTrue();
|
||||
expect(dd.isAbsolute('hTtPs://google.com')).isTrue();
|
||||
expect(dd.isAbsolute('mailto:fake@email.com')).isTrue();
|
||||
expect(doc.isAbsolute('http://google.com')).isTrue();
|
||||
expect(doc.isAbsolute('hTtPs://google.com')).isTrue();
|
||||
expect(doc.isAbsolute('mailto:fake@email.com')).isTrue();
|
||||
});
|
||||
});
|
||||
|
||||
group('relativePath', () {
|
||||
final doc = new dd.Dartdoc();
|
||||
|
||||
test('absolute path is unchanged', () {
|
||||
dd.startFile('dir/sub/file.html');
|
||||
expect(dd.relativePath('http://google.com')).equals('http://google.com');
|
||||
doc.startFile('dir/sub/file.html');
|
||||
expect(doc.relativePath('http://foo.com')).equals('http://foo.com');
|
||||
});
|
||||
|
||||
test('from root to root', () {
|
||||
dd.startFile('root.html');
|
||||
expect(dd.relativePath('other.html')).equals('other.html');
|
||||
doc.startFile('root.html');
|
||||
expect(doc.relativePath('other.html')).equals('other.html');
|
||||
});
|
||||
|
||||
test('from root to directory', () {
|
||||
dd.startFile('root.html');
|
||||
expect(dd.relativePath('dir/file.html')).equals('dir/file.html');
|
||||
doc.startFile('root.html');
|
||||
expect(doc.relativePath('dir/file.html')).equals('dir/file.html');
|
||||
});
|
||||
|
||||
test('from root to nested', () {
|
||||
dd.startFile('root.html');
|
||||
expect(dd.relativePath('dir/sub/file.html')).equals('dir/sub/file.html');
|
||||
doc.startFile('root.html');
|
||||
expect(doc.relativePath('dir/sub/file.html')).equals(
|
||||
'dir/sub/file.html');
|
||||
});
|
||||
|
||||
test('from directory to root', () {
|
||||
dd.startFile('dir/file.html');
|
||||
expect(dd.relativePath('root.html')).equals('../root.html');
|
||||
doc.startFile('dir/file.html');
|
||||
expect(doc.relativePath('root.html')).equals('../root.html');
|
||||
});
|
||||
|
||||
test('from nested to root', () {
|
||||
dd.startFile('dir/sub/file.html');
|
||||
expect(dd.relativePath('root.html')).equals('../../root.html');
|
||||
doc.startFile('dir/sub/file.html');
|
||||
expect(doc.relativePath('root.html')).equals('../../root.html');
|
||||
});
|
||||
|
||||
test('from dir to dir with different path', () {
|
||||
dd.startFile('dir/file.html');
|
||||
expect(dd.relativePath('other/file.html')).equals('../other/file.html');
|
||||
doc.startFile('dir/file.html');
|
||||
expect(doc.relativePath('other/file.html')).equals(
|
||||
'../other/file.html');
|
||||
});
|
||||
|
||||
test('from nested to nested with different path', () {
|
||||
dd.startFile('dir/sub/file.html');
|
||||
expect(dd.relativePath('other/sub/file.html')).equals(
|
||||
doc.startFile('dir/sub/file.html');
|
||||
expect(doc.relativePath('other/sub/file.html')).equals(
|
||||
'../../other/sub/file.html');
|
||||
});
|
||||
|
||||
test('from nested to directory with different path', () {
|
||||
dd.startFile('dir/sub/file.html');
|
||||
expect(dd.relativePath('other/file.html')).equals(
|
||||
doc.startFile('dir/sub/file.html');
|
||||
expect(doc.relativePath('other/file.html')).equals(
|
||||
'../../other/file.html');
|
||||
});
|
||||
});
|
||||
|
@ -137,6 +143,8 @@ main() {
|
|||
}
|
||||
|
||||
var doc = new dd.Dartdoc();
|
||||
doc.startFile('someLib/someType.html');
|
||||
|
||||
world.processDartScript(dummyPath);
|
||||
world.resolveAll();
|
||||
var dummy = world.libraries[dummyPath];
|
||||
|
@ -152,38 +160,38 @@ main() {
|
|||
|
||||
test('to a member of the current type', () {
|
||||
expect(render(doc.resolveNameReference('method', type: klass))).
|
||||
equals('<a class="crossref" href="../../dummy/Class.html#method">' +
|
||||
equals('<a class="crossref" href="../dummy/Class.html#method">' +
|
||||
'method</a>');
|
||||
});
|
||||
|
||||
test('to a property with only a getter links to the getter', () {
|
||||
expect(render(doc.resolveNameReference('getterOnly', type: klass))).
|
||||
equals('<a class="crossref" ' +
|
||||
'href="../../dummy/Class.html#get:getterOnly">getterOnly</a>');
|
||||
'href="../dummy/Class.html#get:getterOnly">getterOnly</a>');
|
||||
});
|
||||
|
||||
test('to a property with only a setter links to the setter', () {
|
||||
expect(render(doc.resolveNameReference('setterOnly', type: klass))).
|
||||
equals('<a class="crossref" ' +
|
||||
'href="../../dummy/Class.html#set:setterOnly">setterOnly</a>');
|
||||
'href="../dummy/Class.html#set:setterOnly">setterOnly</a>');
|
||||
});
|
||||
|
||||
test('to a property with a getter and setter links to the getter', () {
|
||||
expect(render(doc.resolveNameReference('getterAndSetter', type: klass))).
|
||||
equals('<a class="crossref" ' +
|
||||
'href="../../dummy/Class.html#get:getterAndSetter">' +
|
||||
'href="../dummy/Class.html#get:getterAndSetter">' +
|
||||
'getterAndSetter</a>');
|
||||
});
|
||||
|
||||
test('to a type in the current library', () {
|
||||
expect(render(doc.resolveNameReference('Class', library: dummy))).
|
||||
equals('<a class="crossref" href="../../dummy/Class.html">Class</a>');
|
||||
equals('<a class="crossref" href="../dummy/Class.html">Class</a>');
|
||||
});
|
||||
|
||||
test('to a top-level member in the current library', () {
|
||||
expect(render(doc.resolveNameReference('topLevelMethod',
|
||||
library: dummy))).
|
||||
equals('<a class="crossref" href="../../dummy.html#topLevelMethod">' +
|
||||
equals('<a class="crossref" href="../dummy.html#topLevelMethod">' +
|
||||
'topLevelMethod</a>');
|
||||
});
|
||||
|
||||
|
@ -195,13 +203,13 @@ main() {
|
|||
|
||||
test('to a member of another class', () {
|
||||
expect(render(doc.resolveNameReference('Class.method', library: dummy))).
|
||||
equals('<a class="crossref" href="../../dummy/Class.html#method">' +
|
||||
equals('<a class="crossref" href="../dummy/Class.html#method">' +
|
||||
'Class.method</a>');
|
||||
});
|
||||
|
||||
test('to a constructor', () {
|
||||
expect(render(doc.resolveNameReference('new Class', library: dummy))).
|
||||
equals('<a class="crossref" href="../../dummy/Class.html#new:Class">' +
|
||||
equals('<a class="crossref" href="../dummy/Class.html#new:Class">' +
|
||||
'new Class</a>');
|
||||
});
|
||||
|
||||
|
@ -209,7 +217,7 @@ main() {
|
|||
expect(render(doc.resolveNameReference('new Class.namedConstructor',
|
||||
library: dummy))).
|
||||
equals('<a class="crossref" ' +
|
||||
'href="../../dummy/Class.html#new:Class.namedConstructor">new ' +
|
||||
'href="../dummy/Class.html#new:Class.namedConstructor">new ' +
|
||||
'Class.namedConstructor</a>');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue