| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Functions for working with files and paths. | 5 // Functions for working with files and paths. |
| 6 | 6 |
| 7 /** The path to the file currently being written to, relative to [outdir]. */ | 7 /** The path to the file currently being written to, relative to [outdir]. */ |
| 8 String _filePath; | 8 String _filePath; |
| 9 | 9 |
| 10 /** The file currently being written to. */ | 10 /** The file currently being written to. */ |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 endFile() { | 30 endFile() { |
| 31 String outPath = '$_outdir/$_filePath'; | 31 String outPath = '$_outdir/$_filePath'; |
| 32 world.files.createDirectory(dirname(outPath), recursive: true); | 32 world.files.createDirectory(dirname(outPath), recursive: true); |
| 33 | 33 |
| 34 world.files.writeString(outPath, _file.toString()); | 34 world.files.writeString(outPath, _file.toString()); |
| 35 _filePath = null; | 35 _filePath = null; |
| 36 _file = null; | 36 _file = null; |
| 37 } | 37 } |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Converts [absolute] which is understood to be a full path from the root of | 40 * Converts [fullPath] which is understood to be a full path from the root of |
| 41 * the generated docs to one relative to the current file. | 41 * the generated docs to one relative to the current file. |
| 42 */ | 42 */ |
| 43 String relativePath(String absolute) { | 43 String relativePath(String fullPath) { |
| 44 // Don't make it relative if it's an absolute path. |
| 45 if (isAbsolute(fullPath)) return fullPath; |
| 46 |
| 44 // TODO(rnystrom): Walks all the way up to root each time. Shouldn't do this | 47 // TODO(rnystrom): Walks all the way up to root each time. Shouldn't do this |
| 45 // if the paths overlap. | 48 // if the paths overlap. |
| 46 return repeat('../', countOccurrences(_filePath, '/')) + absolute; | 49 return repeat('../', countOccurrences(_filePath, '/')) + fullPath; |
| 50 } |
| 51 |
| 52 /** Gets whether or not the given URL is absolute or relative. */ |
| 53 bool isAbsolute(String url) { |
| 54 // TODO(rnystrom): This is a bit hackish. We consider any URL that lacks |
| 55 // a scheme to be relative. |
| 56 return const RegExp(@'^\w+:').hasMatch(url); |
| 47 } | 57 } |
| 48 | 58 |
| 49 /** Gets the URL to the documentation for [library]. */ | 59 /** Gets the URL to the documentation for [library]. */ |
| 50 libraryUrl(Library library) => '${sanitize(library.name)}.html'; | 60 libraryUrl(Library library) => '${sanitize(library.name)}.html'; |
| 51 | 61 |
| 52 /** Gets the URL for the documentation for [type]. */ | 62 /** Gets the URL for the documentation for [type]. */ |
| 53 typeUrl(Type type) { | 63 typeUrl(Type type) { |
| 54 // Always get the generic type to strip off any type parameters or arguments. | 64 // Always get the generic type to strip off any type parameters or arguments. |
| 55 // If the type isn't generic, genericType returns `this`, so it works for | 65 // If the type isn't generic, genericType returns `this`, so it works for |
| 56 // non-generic types too. | 66 // non-generic types too. |
| 57 return '${sanitize(type.library.name)}/${type.genericType.name}.html'; | 67 return '${sanitize(type.library.name)}/${type.genericType.name}.html'; |
| 58 } | 68 } |
| 59 | 69 |
| 60 /** Gets the URL for the documentation for [member]. */ | 70 /** Gets the URL for the documentation for [member]. */ |
| 61 memberUrl(Member member) => '${typeUrl(member.declaringType)}#${member.name}'; | 71 memberUrl(Member member) => '${typeUrl(member.declaringType)}#${member.name}'; |
| 62 | 72 |
| 63 /** Gets the anchor id for the document for [member]. */ | 73 /** Gets the anchor id for the document for [member]. */ |
| 64 memberAnchor(Member member) => '${member.name}'; | 74 memberAnchor(Member member) => '${member.name}'; |
| OLD | NEW |