Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Unified Diff: lib/dartdoc/dartdoc.dart

Issue 10780030: Dartdoc and apidoc updated to use Path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/dartdoc/file_util.dart » ('j') | lib/dartdoc/mirrors/dart2js_mirror.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/dartdoc/dartdoc.dart
diff --git a/lib/dartdoc/dartdoc.dart b/lib/dartdoc/dartdoc.dart
index 90e3b705329c7aaa5ae7c8ac930c373aa3c8dd19..c408c3cab492f2f5ce4c254b8fb2aa3e51bd3dc1 100644
--- a/lib/dartdoc/dartdoc.dart
+++ b/lib/dartdoc/dartdoc.dart
@@ -24,10 +24,8 @@
#import('mirrors/dart2js_mirror.dart', prefix: 'dart2js');
#import('classify.dart');
#import('markdown.dart', prefix: 'md');
-#import('../compiler/implementation/dart2js.dart', prefix: 'dart2js');
#import('../compiler/implementation/scanner/scannerlib.dart',
prefix: 'dart2js');
-#import('file_util.dart');
#source('comment_map.dart');
#source('utils.dart');
@@ -118,20 +116,13 @@ void main() {
return;
}
- // TODO(rnystrom): Note that the following lines get munged by create-sdk to
- // work with the SDK's different file layout. If you change, be sure to test
- // that dartdoc still works when run from the built SDK directory.
- final String libPath = joinPaths(scriptDir, '../');
-
- // The entrypoint of the library to generate docs for.
- // TODO(johnniwinther): Handle absolute/relative paths
- final entrypoint = canonicalizePath(args[args.length - 1]);
+ final entrypoint = new Path.fromNative(args[args.length - 1]);
final dartdoc = new Dartdoc();
if (includeSource != null) dartdoc.includeSource = includeSource;
if (mode != null) dartdoc.mode = mode;
- if (outputDir != null) dartdoc.outputDir = outputDir;
+ if (outputDir != null) dartdoc.outputDir = new Path.fromNative(outputDir);
if (generateAppCache != null) dartdoc.generateAppCache = generateAppCache;
if (omitGenerationTime != null) {
dartdoc.omitGenerationTime = omitGenerationTime;
@@ -144,13 +135,13 @@ void main() {
// Compile the client-side code to JS.
final clientScript = (dartdoc.mode == MODE_STATIC) ? 'static' : 'live-nav';
- compileScript(
- '$scriptDir/client-$clientScript.dart',
- '${dartdoc.outputDir}/client-$clientScript.js');
+ Future compiled = compileScript(
+ scriptDir.append('client-$clientScript.dart'),
+ dartdoc.outputDir.append('client-$clientScript.js'));
- final Future filesCopied = copyFiles('$scriptDir/static', dartdoc.outputDir);
+ Future filesCopied = copyFiles(scriptDir.append('static'), dartdoc.outputDir);
- Futures.wait([filesCopied]).then((_) {
+ Futures.wait([compiled, filesCopied]).then((_) {
Bill Hesse 2012/07/17 13:42:13 I should start using _ as my "ignore" argument. S
Johnni Winther 2012/07/19 08:37:07 I think so.
print('Documented ${dartdoc._totalLibraries} libraries, '
'${dartdoc._totalTypes} types, and '
'${dartdoc._totalMembers} members.');
@@ -163,25 +154,25 @@ Usage dartdoc [options] <entrypoint>
[options] include
--no-code Do not include source code in the documentation.
- --mode=static Generates completely static HTML containing
- everything you need to browse the docs. The only
+ --mode=static Generates completely static HTML containing
+ everything you need to browse the docs. The only
client side behavior is trivial stuff like syntax
highlighting code.
- --mode=live-nav (default) Generated docs do not include baked HTML
- navigation. Instead, a single `nav.json` file is
+ --mode=live-nav (default) Generated docs do not include baked HTML
+ navigation. Instead, a single `nav.json` file is
created and the appropriate navigation is generated
client-side by parsing that and building HTML.
- This dramatically reduces the generated size of
- the HTML since a large fraction of each static page
+ This dramatically reduces the generated size of
+ the HTML since a large fraction of each static page
is just redundant navigation links.
- In this mode, the browser will do a XHR for
- nav.json which means that to preview docs locally,
+ In this mode, the browser will do a XHR for
+ nav.json which means that to preview docs locally,
you will need to enable requesting file:// links in
- your browser or run a little local server like
+ your browser or run a little local server like
`python -m SimpleHTTPServer`.
- --generate-app-cache Generates the App Cache manifest file, enabling
+ --generate-app-cache Generates the App Cache manifest file, enabling
offline doc viewing.
--out=<dir> Generates files into directory <dir>. If omitted
@@ -197,15 +188,22 @@ Usage dartdoc [options] <entrypoint>
* path to the directory containing `dartdoc.dart`. If you're running a script
* that imports dartdoc, it will be the path to that script.
*/
-String get scriptDir() {
- return dirname(new File(new Options().script).fullPathSync());
+Path get scriptDir() {
Bill Hesse 2012/07/17 13:42:13 Lazy intialized statics work perfectly here, I thi
Johnni Winther 2012/07/19 08:37:07 This is not currently supported since current impl
Bill Hesse 2012/07/19 13:36:19 Can we write a TODO to fix this once they are supp
+ return new Path.fromNative(new Options().script).directoryPath;
+}
+
+Path get libPath() {
+ // TODO(rnystrom): Note that the following lines get munged by create-sdk to
+ // work with the SDK's different file layout. If you change, be sure to test
+ // that dartdoc still works when run from the built SDK directory.
+ return scriptDir.append('../..');
Bill Hesse 2012/07/17 13:42:13 Can't we have a const flag or enum, munged by the
Johnni Winther 2012/07/19 08:37:07 Changed to use a bool IN_SDK flag.
}
/**
* Deletes and recreates the output directory at [path] if it exists.
*/
-void cleanOutputDirectory(String path) {
- final outputDir = new Directory(path);
+void cleanOutputDirectory(Path path) {
+ final outputDir = new Directory.fromPath(path);
if (outputDir.existsSync()) {
outputDir.deleteRecursivelySync();
}
@@ -227,18 +225,18 @@ void cleanOutputDirectory(String path) {
* Note: runs asynchronously, so you won't see any files copied until after the
* event loop has had a chance to pump (i.e. after `main()` has returned).
*/
-Future copyFiles(String from, String to) {
+Future copyFiles(Path from, Path to) {
Bill Hesse 2012/07/17 13:42:13 copyDirectory?
Johnni Winther 2012/07/19 08:37:07 Done.
final completer = new Completer();
- final fromDir = new Directory(from);
+ final fromDir = new Directory.fromPath(from);
final lister = fromDir.list(recursive: false);
- lister.onFile = (path) {
- final name = basename(path);
+ lister.onFile = (String path) {
+ final name = new Path.fromNative(path).filename;
// TODO(rnystrom): Hackish. Ignore 'hidden' files like .DS_Store.
if (name.startsWith('.')) return;
new File(path).readAsBytes().then((bytes) {
Bill Hesse 2012/07/17 13:42:13 Copying should work better with File from; File to
Johnni Winther 2012/07/19 08:37:07 Done.
- final outFile = new File('$to/$name');
+ final outFile = new File.fromPath(to.append(name));
final stream = outFile.openOutputStream(FileMode.WRITE);
stream.write(bytes, copyBuffer: false);
stream.close();
@@ -252,17 +250,16 @@ Future copyFiles(String from, String to) {
* Compiles the given Dart script to a JavaScript file at [jsPath] using the
* Dart2js compiler.
*/
-void compileScript(String dartPath, String jsPath) {
- dart2js.compile([
- '--no-colors',
- // TODO(johnniwinther): The following lines get munged by create-sdk to
- // work with the SDK's different file layout. If you change, be sure to
- // test that dartdoc still works when run from the built SDK directory.
- '--library-root=${joinPaths(scriptDir, '../../')}',
- '--out=$jsPath',
- '--throw-on-error',
- '--suppress-warnings',
- dartPath]);
+Future<bool> compileScript(Path dartPath, Path jsPath) {
+ var completer = new Completer<bool>();
+ var compilation = new Compilation(dartPath, libPath);
+ Future<String> result = compilation.compileToJavaScript();
+ result.then((jsCode) {
+ writeString(new File.fromPath(jsPath), jsCode);
+ completer.complete(true);
+ });
+ result.handleException((e) => completer.completeException(e));
+ return completer.future;
}
class Dartdoc {
@@ -283,7 +280,7 @@ class Dartdoc {
bool generateAppCache = false;
/** Path to generate HTML files into. */
- String outputDir = 'docs';
+ Path outputDir = const Path('docs');
/**
* The title used for the overall generated output. Set this to change it.
@@ -354,8 +351,8 @@ class Dartdoc {
new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]'));
md.setImplicitLinkResolver((name) => resolveNameReference(name,
- library: _currentLibrary, type: _currentType,
- member: _currentMember));
+ currentLibrary: _currentLibrary, currentType: _currentType,
+ currentMember: _currentMember));
}
bool includeLibrary(LibraryMirror library) {
@@ -383,13 +380,13 @@ class Dartdoc {
return content;
}
- void documentEntryPoint(String entrypoint, String libPath) {
+ void documentEntryPoint(Path entrypoint, Path libPath) {
final compilation = new Compilation(entrypoint, libPath);
_document(compilation);
}
- void documentLibraries(List<String> libraries, String libPath) {
- final compilation = new Compilation.library(libraries, libPath);
+ void documentLibraries(List<Path> libraryList, Path libPath) {
+ final compilation = new Compilation.library(libraryList, libPath);
_document(compilation);
}
@@ -421,8 +418,8 @@ class Dartdoc {
}
void endFile() {
- final outPath = '$outputDir/$_filePath';
- final dir = new Directory(dirname(outPath));
+ final outPath = outputDir.join(new Path.fromNative(_filePath));
+ final dir = new Directory.fromPath(outPath.directoryPath);
if (!dir.existsSync()) {
// TODO(johnniwinther): Hack to avoid 'file already exists' exception
Bill Hesse 2012/07/17 13:42:13 TODO(3914): There is a bug for this issue: http://
// thrown due to invalid result from dir.existsSync() (probably due to
@@ -434,7 +431,7 @@ class Dartdoc {
}
}
- writeString(new File(outPath), _file.toString());
+ writeString(new File.fromPath(outPath), _file.toString());
_filePath = null;
_file = null;
}
@@ -595,7 +592,7 @@ class Dartdoc {
void docLibraryNavigationJson(LibraryMirror library, Map libraryMap) {
final types = [];
- for (final type in orderByName(library.types().getValues())) {
+ for (InterfaceMirror type in orderByName(library.types().getValues())) {
if (type.isPrivate) continue;
final kind = type.isClass ? 'class' : 'interface';
@@ -637,7 +634,7 @@ class Dartdoc {
final types = <InterfaceMirror>[];
final exceptions = <InterfaceMirror>[];
- for (final type in orderByName(library.types().getValues())) {
+ for (InterfaceMirror type in orderByName(library.types().getValues())) {
if (type.isPrivate) continue;
if (isException(type)) {
@@ -702,7 +699,7 @@ class Dartdoc {
final interfaces = <InterfaceMirror>[];
final exceptions = <InterfaceMirror>[];
- for (final type in orderByName(library.types().getValues())) {
+ for (InterfaceMirror type in orderByName(library.types().getValues())) {
if (type.isPrivate) continue;
if (isException(type)) {
@@ -952,7 +949,7 @@ class Dartdoc {
final instanceMethods = [];
final instanceFields = [];
- for (final member in orderByName(host.declaredMembers().getValues())) {
+ for (MemberMirror member in orderByName(host.declaredMembers().getValues())) {
if (member.isPrivate) continue;
final methods = member.isStatic ? staticMethods : instanceMethods;
@@ -1378,9 +1375,9 @@ class Dartdoc {
* style it appropriately.
*/
md.Node resolveNameReference(String name,
- [MemberMirror member = null,
- ObjectMirror type = null,
- LibraryMirror library = null]) {
+ [MemberMirror currentMember = null,
+ ObjectMirror currentType = null,
+ LibraryMirror currentLibrary = null]) {
makeLink(String href) {
final anchor = new md.Element.text('a', name);
anchor.attributes['href'] = relativePath(href);
@@ -1389,8 +1386,8 @@ class Dartdoc {
}
// See if it's a parameter of the current method.
- if (member is MethodMirror) {
- for (final parameter in member.parameters()) {
+ if (currentMember is MethodMirror) {
+ for (final parameter in currentMember.parameters()) {
if (parameter.simpleName() == name) {
final element = new md.Element.text('span', name);
element.attributes['class'] = 'param';
@@ -1400,25 +1397,25 @@ class Dartdoc {
}
// See if it's another member of the current type.
- if (type != null) {
- final member = findMirror(type.declaredMembers(), name);
- if (member != null) {
- return makeLink(memberUrl(member));
+ if (currentType != null) {
+ final foundMember = findMirror(currentType.declaredMembers(), name);
+ if (foundMember != null) {
+ return makeLink(memberUrl(foundMember));
}
}
// See if it's another type or a member of another type in the current
// library.
- if (library != null) {
+ if (currentLibrary != null) {
// See if it's a constructor
final constructorLink = (() {
final match =
new RegExp(@'new ([\w$]+)(?:\.([\w$]+))?').firstMatch(name);
if (match == null) return;
- final type = findMirror(library.types(), match[1]);
- if (type == null) return;
+ InterfaceMirror foundtype = findMirror(currentLibrary.types(), match[1]);
+ if (foundtype == null) return;
final constructor =
- findMirror(type.constructors(),
+ findMirror(foundtype.constructors(),
match[2] == null ? '' : match[2]);
if (constructor == null) return;
return makeLink(memberUrl(constructor));
@@ -1429,23 +1426,23 @@ class Dartdoc {
final foreignMemberLink = (() {
final match = new RegExp(@'([\w$]+)\.([\w$]+)').firstMatch(name);
if (match == null) return;
- final type = findMirror(library.types(), match[1]);
- if (type == null) return;
- final member = findMirror(type.declaredMembers(), match[2]);
- if (member == null) return;
- return makeLink(memberUrl(member));
+ InterfaceMirror foundtype = findMirror(currentLibrary.types(), match[1]);
+ if (foundtype == null) return;
+ MemberMirror foundMember = findMirror(foundtype.declaredMembers(), match[2]);
+ if (foundMember == null) return;
+ return makeLink(memberUrl(foundMember));
})();
if (foreignMemberLink != null) return foreignMemberLink;
- final type = findMirror(library.types(), name);
- if (type != null) {
- return makeLink(typeUrl(type));
+ InterfaceMirror foundType = findMirror(currentLibrary.types(), name);
+ if (foundType != null) {
+ return makeLink(typeUrl(foundType));
}
// See if it's a top-level member in the current library.
- final member = findMirror(library.declaredMembers(), name);
- if (member != null) {
- return makeLink(memberUrl(member));
+ MemberMirror foundMember = findMirror(currentLibrary.declaredMembers(), name);
+ if (foundMember != null) {
+ return makeLink(memberUrl(foundMember));
}
}
@@ -1463,18 +1460,18 @@ class Dartdoc {
write("# VERSION: ${new Date.now()}\n\n");
write("NETWORK:\n*\n\n");
write("CACHE:\n");
- var toCache = new Directory(outputDir);
- var pathPrefix = new File(outputDir).fullPathSync();
+ var toCache = new Directory.fromPath(outputDir);
+ var pathPrefix = new File.fromPath(outputDir).fullPathSync();
var pathPrefixLength = pathPrefix.length;
- toCache.onFile = (filename) {
+ var toCacheLister = toCache.list(recursive: true);
+ toCacheLister.onFile = (filename) {
if (filename.endsWith('appcache.manifest')) {
return;
}
Bill Hesse 2012/07/17 13:42:13 var relativePath = new Path.fromNative(filename).r
Johnni Winther 2012/07/19 08:37:07 Changed, but a lot of new issues arose. Check the
var relativePath = filename.substring(pathPrefixLength + 1);
write("$relativePath\n");
};
- toCache.onDone = (done) => endFile();
- toCache.list(recursive: true);
+ toCacheLister.onDone = (done) => endFile();
}
/**
« no previous file with comments | « no previous file | lib/dartdoc/file_util.dart » ('j') | lib/dartdoc/mirrors/dart2js_mirror.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698