| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * To generate docs for a library, run this script with the path to an | 6 * To generate docs for a library, run this script with the path to an |
| 7 * entrypoint .dart file, like: | 7 * entrypoint .dart file, like: |
| 8 * | 8 * |
| 9 * $ dart dartdoc.dart foo.dart | 9 * $ dart dartdoc.dart foo.dart |
| 10 * | 10 * |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 int get totalLibraries => _totalLibraries; | 230 int get totalLibraries => _totalLibraries; |
| 231 int get totalTypes => _totalTypes; | 231 int get totalTypes => _totalTypes; |
| 232 int get totalMembers => _totalMembers; | 232 int get totalMembers => _totalMembers; |
| 233 | 233 |
| 234 Dartdoc() | 234 Dartdoc() |
| 235 : _comments = new CommentMap() { | 235 : _comments = new CommentMap() { |
| 236 // Patch in support for [:...:]-style code to the markdown parser. | 236 // Patch in support for [:...:]-style code to the markdown parser. |
| 237 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? | 237 // TODO(rnystrom): Markdown already has syntax for this. Phase this out? |
| 238 md.InlineParser.syntaxes.insertRange(0, 1, | 238 md.InlineParser.syntaxes.insertRange(0, 1, |
| 239 new md.CodeSyntax(@'\[\:((?:.|\n)*?)\:\]')); | 239 new md.CodeSyntax(r'\[\:((?:.|\n)*?)\:\]')); |
| 240 | 240 |
| 241 md.setImplicitLinkResolver((name) => resolveNameReference(name, | 241 md.setImplicitLinkResolver((name) => resolveNameReference(name, |
| 242 currentLibrary: _currentLibrary, currentType: _currentType, | 242 currentLibrary: _currentLibrary, currentType: _currentType, |
| 243 currentMember: _currentMember)); | 243 currentMember: _currentMember)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 /** | 246 /** |
| 247 * Returns `true` if [library] is included in the generated documentation. | 247 * Returns `true` if [library] is included in the generated documentation. |
| 248 */ | 248 */ |
| 249 bool shouldIncludeLibrary(LibraryMirror library) { | 249 bool shouldIncludeLibrary(LibraryMirror library) { |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // TODO(3914): Hack to avoid 'file already exists' exception | 532 // TODO(3914): Hack to avoid 'file already exists' exception |
| 533 // thrown due to invalid result from dir.existsSync() (probably due to | 533 // thrown due to invalid result from dir.existsSync() (probably due to |
| 534 // race conditions). | 534 // race conditions). |
| 535 try { | 535 try { |
| 536 dir.createSync(); | 536 dir.createSync(); |
| 537 } on DirectoryIOException catch (e) { | 537 } on DirectoryIOException catch (e) { |
| 538 // Ignore. | 538 // Ignore. |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 String jsonString = JSON.stringify(createNavigationInfo()); | 541 String jsonString = JSON.stringify(createNavigationInfo()); |
| 542 String dartString = jsonString.replaceAll(@"$", @"\$"); | 542 String dartString = jsonString.replaceAll(r"$", r"\$"); |
| 543 final filePath = tmpPath.append('nav.dart'); | 543 final filePath = tmpPath.append('nav.dart'); |
| 544 writeString(new File.fromPath(filePath), | 544 writeString(new File.fromPath(filePath), |
| 545 'get json => $dartString;'); | 545 'get json => $dartString;'); |
| 546 } | 546 } |
| 547 | 547 |
| 548 Path get tmpPath => dartdocPath.append('tmp'); | 548 Path get tmpPath => dartdocPath.append('tmp'); |
| 549 | 549 |
| 550 void cleanup() { | 550 void cleanup() { |
| 551 final dir = new Directory.fromPath(tmpPath); | 551 final dir = new Directory.fromPath(tmpPath); |
| 552 if (dir.existsSync()) { | 552 if (dir.existsSync()) { |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 // this if the paths overlap. | 1222 // this if the paths overlap. |
| 1223 return '${repeat('../', | 1223 return '${repeat('../', |
| 1224 countOccurrences(_filePath.toString(), '/'))}$fullPath'; | 1224 countOccurrences(_filePath.toString(), '/'))}$fullPath'; |
| 1225 } | 1225 } |
| 1226 | 1226 |
| 1227 /** Gets whether or not the given URL is absolute or relative. */ | 1227 /** Gets whether or not the given URL is absolute or relative. */ |
| 1228 bool isAbsolute(String url) { | 1228 bool isAbsolute(String url) { |
| 1229 // TODO(rnystrom): Why don't we have a nice type in the platform for this? | 1229 // TODO(rnystrom): Why don't we have a nice type in the platform for this? |
| 1230 // TODO(rnystrom): This is a bit hackish. We consider any URL that lacks | 1230 // TODO(rnystrom): This is a bit hackish. We consider any URL that lacks |
| 1231 // a scheme to be relative. | 1231 // a scheme to be relative. |
| 1232 return const RegExp(@'^\w+:').hasMatch(url); | 1232 return const RegExp(r'^\w+:').hasMatch(url); |
| 1233 } | 1233 } |
| 1234 | 1234 |
| 1235 /** Gets the URL to the documentation for [library]. */ | 1235 /** Gets the URL to the documentation for [library]. */ |
| 1236 String libraryUrl(LibraryMirror library) { | 1236 String libraryUrl(LibraryMirror library) { |
| 1237 return '${sanitize(library.simpleName)}.html'; | 1237 return '${sanitize(library.simpleName)}.html'; |
| 1238 } | 1238 } |
| 1239 | 1239 |
| 1240 /** Gets the URL for the documentation for [type]. */ | 1240 /** Gets the URL for the documentation for [type]. */ |
| 1241 String typeUrl(ObjectMirror type) { | 1241 String typeUrl(ObjectMirror type) { |
| 1242 if (type is LibraryMirror) { | 1242 if (type is LibraryMirror) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 return makeLink(memberUrl(foundMember)); | 1473 return makeLink(memberUrl(foundMember)); |
| 1474 } | 1474 } |
| 1475 } | 1475 } |
| 1476 | 1476 |
| 1477 // See if it's another type or a member of another type in the current | 1477 // See if it's another type or a member of another type in the current |
| 1478 // library. | 1478 // library. |
| 1479 if (currentLibrary != null) { | 1479 if (currentLibrary != null) { |
| 1480 // See if it's a constructor | 1480 // See if it's a constructor |
| 1481 final constructorLink = (() { | 1481 final constructorLink = (() { |
| 1482 final match = | 1482 final match = |
| 1483 new RegExp(@'new ([\w$]+)(?:\.([\w$]+))?').firstMatch(name); | 1483 new RegExp(r'new ([\w$]+)(?:\.([\w$]+))?').firstMatch(name); |
| 1484 if (match == null) return; | 1484 if (match == null) return; |
| 1485 InterfaceMirror foundtype = findMirror(currentLibrary.types, match[1]); | 1485 InterfaceMirror foundtype = findMirror(currentLibrary.types, match[1]); |
| 1486 if (foundtype == null) return; | 1486 if (foundtype == null) return; |
| 1487 final constructor = | 1487 final constructor = |
| 1488 findMirror(foundtype.constructors, | 1488 findMirror(foundtype.constructors, |
| 1489 match[2] == null ? '' : match[2]); | 1489 match[2] == null ? '' : match[2]); |
| 1490 if (constructor == null) return; | 1490 if (constructor == null) return; |
| 1491 return makeLink(memberUrl(constructor)); | 1491 return makeLink(memberUrl(constructor)); |
| 1492 })(); | 1492 })(); |
| 1493 if (constructorLink != null) return constructorLink; | 1493 if (constructorLink != null) return constructorLink; |
| 1494 | 1494 |
| 1495 // See if it's a member of another type | 1495 // See if it's a member of another type |
| 1496 final foreignMemberLink = (() { | 1496 final foreignMemberLink = (() { |
| 1497 final match = new RegExp(@'([\w$]+)\.([\w$]+)').firstMatch(name); | 1497 final match = new RegExp(r'([\w$]+)\.([\w$]+)').firstMatch(name); |
| 1498 if (match == null) return; | 1498 if (match == null) return; |
| 1499 InterfaceMirror foundtype = findMirror(currentLibrary.types, match[1]); | 1499 InterfaceMirror foundtype = findMirror(currentLibrary.types, match[1]); |
| 1500 if (foundtype == null) return; | 1500 if (foundtype == null) return; |
| 1501 MemberMirror foundMember = findMirror(foundtype.declaredMembers, match[2
]); | 1501 MemberMirror foundMember = findMirror(foundtype.declaredMembers, match[2
]); |
| 1502 if (foundMember == null) return; | 1502 if (foundMember == null) return; |
| 1503 return makeLink(memberUrl(foundMember)); | 1503 return makeLink(memberUrl(foundMember)); |
| 1504 })(); | 1504 })(); |
| 1505 if (foreignMemberLink != null) return foreignMemberLink; | 1505 if (foreignMemberLink != null) return foreignMemberLink; |
| 1506 | 1506 |
| 1507 InterfaceMirror foundType = findMirror(currentLibrary.types, name); | 1507 InterfaceMirror foundType = findMirror(currentLibrary.types, name); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 | 1567 |
| 1568 /** | 1568 /** |
| 1569 * Used to report an unexpected error in the DartDoc tool or the | 1569 * Used to report an unexpected error in the DartDoc tool or the |
| 1570 * underlying data | 1570 * underlying data |
| 1571 */ | 1571 */ |
| 1572 class InternalError { | 1572 class InternalError { |
| 1573 final String message; | 1573 final String message; |
| 1574 const InternalError(this.message); | 1574 const InternalError(this.message); |
| 1575 String toString() => "InternalError: '$message'"; | 1575 String toString() => "InternalError: '$message'"; |
| 1576 } | 1576 } |
| OLD | NEW |