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

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 175693005: Don't assume the pubspec is only one level up from a library (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// **docgen** is a tool for creating machine readable representations of Dart 5 /// **docgen** is a tool for creating machine readable representations of Dart
6 /// code metadata, including: classes, members, comments and annotations. 6 /// code metadata, including: classes, members, comments and annotations.
7 /// 7 ///
8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files.
9 /// 9 ///
10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR]
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 var linkResolver = (name) => Indexable.globalFixReference(name); 1441 var linkResolver = (name) => Indexable.globalFixReference(name);
1442 var contents = markdown.markdownToHtml(readme 1442 var contents = markdown.markdownToHtml(readme
1443 .readAsStringSync(), linkResolver: linkResolver, 1443 .readAsStringSync(), linkResolver: linkResolver,
1444 inlineSyntaxes: _MARKDOWN_SYNTAXES); 1444 inlineSyntaxes: _MARKDOWN_SYNTAXES);
1445 return contents; 1445 return contents;
1446 } 1446 }
1447 1447
1448 /// Given a LibraryMirror that is a library, return the name of the directory 1448 /// Given a LibraryMirror that is a library, return the name of the directory
1449 /// holding that library. 1449 /// holding that library.
1450 static String _getRootdir(LibraryMirror mirror) => 1450 static String _getRootdir(LibraryMirror mirror) =>
1451 path.dirname(path.dirname(mirror.uri.toFilePath())); 1451 _packageDirectoryFor(path.dirname(path.dirname(mirror.uri.toFilePath())));
kevmoo 2014/02/24 17:49:02 Could you break this out and explain why there are
Alan Knight 2014/02/24 18:14:02 Done.
1452 1452
1453 /// Read a pubspec and return the library name given a [LibraryMirror]. 1453 /// Read a pubspec and return the library name given a [LibraryMirror].
1454 static String _packageName(LibraryMirror mirror) { 1454 static String _packageName(LibraryMirror mirror) {
1455 if (mirror.uri.scheme != 'file') return ''; 1455 if (mirror.uri.scheme != 'file') return '';
1456 var rootdir = _getRootdir(mirror); 1456 var rootdir = _getRootdir(mirror);
1457 return packageNameFor(rootdir); 1457 return packageNameFor(rootdir);
1458 } 1458 }
1459 1459
1460 /// Recursively walk up from directory name looking for a pubspec. Return
1461 /// the directory that contains it, or null if none is found.
1462 static String _packageDirectoryFor(String directoryName) {
1463 var dir = directoryName;
1464 while (!_pubspecFor(dir).existsSync()) {
1465 var newDir = path.dirname(dir);
1466 if (newDir == dir) return null;
kevmoo 2014/02/24 17:49:02 What happens in the null case?
Alan Knight 2014/02/24 18:14:02 It should indicate that we're not in a package, so
1467 dir = newDir;
1468 }
1469 return dir;
1470 }
1471
1472 static File _pubspecFor(String directoryName) =>
1473 new File(path.join(directoryName, 'pubspec.yaml'));
1474
1460 /// Read a pubspec and return the library name, given a directory 1475 /// Read a pubspec and return the library name, given a directory
1461 static String packageNameFor(String directoryName) { 1476 static String packageNameFor(String directoryName) {
1462 var pubspecName = path.join(directoryName, 'pubspec.yaml'); 1477 var pubspecName = path.join(directoryName, 'pubspec.yaml');
1463 File pubspec = new File(pubspecName); 1478 File pubspec = new File(pubspecName);
1464 if (!pubspec.existsSync()) return ''; 1479 if (!pubspec.existsSync()) return '';
1465 var contents = pubspec.readAsStringSync(); 1480 var contents = pubspec.readAsStringSync();
1466 var spec = loadYaml(contents); 1481 var spec = loadYaml(contents);
1467 return spec["name"]; 1482 return spec["name"];
1468 } 1483 }
1469 1484
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
2229 .map((e) => originalMirror.getField(e.simpleName).reflectee) 2244 .map((e) => originalMirror.getField(e.simpleName).reflectee)
2230 .where((e) => e != null) 2245 .where((e) => e != null)
2231 .toList(); 2246 .toList();
2232 } 2247 }
2233 2248
2234 Map toMap() => { 2249 Map toMap() => {
2235 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, 2250 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName,
2236 'parameters': parameters 2251 'parameters': parameters
2237 }; 2252 };
2238 } 2253 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698