diff options
-rw-r--r-- | src/Locations/FoldersLocationService.kt | 10 | ||||
-rw-r--r-- | src/Locations/LocationService.kt | 10 | ||||
-rw-r--r-- | src/Locations/SingleFolderLocationService.kt | 4 | ||||
-rw-r--r-- | test/src/TestAPI.kt | 3 |
4 files changed, 16 insertions, 11 deletions
diff --git a/src/Locations/FoldersLocationService.kt b/src/Locations/FoldersLocationService.kt index 4f56475c..ce202cfe 100644 --- a/src/Locations/FoldersLocationService.kt +++ b/src/Locations/FoldersLocationService.kt @@ -6,14 +6,14 @@ public fun FoldersLocationService(root: String): FoldersLocationService = Folder public class FoldersLocationService(val root: File, val extension: String) : FileLocationService { override fun withExtension(newExtension: String): LocationService = FoldersLocationService(root, newExtension) - override fun location(node: DocumentationNode): FileLocation { - return FileLocation(File(root, relativePathToNode(node)).appendExtension(extension)) + override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation { + return FileLocation(File(root, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) } } -fun relativePathToNode(node: DocumentationNode): String { - val parts = node.path.map { identifierToFilename(it.name) }.filterNot { it.isEmpty() } - return if (node.members.none()) { +fun relativePathToNode(qualifiedName: List<String>, hasMembers: Boolean): String { + val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } + return if (!hasMembers) { // leaf node, use file in owner's folder parts.joinToString("/") } else { diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 500b89f2..cb05535a 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -41,15 +41,19 @@ public data class FileLocation(val file: File): Location { public trait LocationService { fun withExtension(newExtension: String) = this + fun location(node: DocumentationNode): Location = location(node.path.map { it.name }, node.members.any()) + /** - * Calculates location for particular node in output structure + * Calculates a location corresponding to the specified [qualifiedName]. + * @param hasMembers if true, the node for which the location is calculated has member nodes. */ - fun location(node: DocumentationNode): Location + fun location(qualifiedName: List<String>, hasMembers: Boolean): Location } public trait FileLocationService: LocationService { - override fun location(node: DocumentationNode): FileLocation + override fun location(node: DocumentationNode): FileLocation = location(node.path.map { it.name }, node.members.any()) + override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation } diff --git a/src/Locations/SingleFolderLocationService.kt b/src/Locations/SingleFolderLocationService.kt index e136a6b2..c26d2b34 100644 --- a/src/Locations/SingleFolderLocationService.kt +++ b/src/Locations/SingleFolderLocationService.kt @@ -7,8 +7,8 @@ public class SingleFolderLocationService(val root: File, val extension: String) override fun withExtension(newExtension: String): LocationService = SingleFolderLocationService(root, newExtension) - override fun location(node: DocumentationNode): FileLocation { - val filename = node.path.map { identifierToFilename(it.name) }.joinToString("-") + override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation { + val filename = qualifiedName.map { identifierToFilename(it) }.joinToString("-") return FileLocation(File(root, filename).appendExtension(extension)) } }
\ No newline at end of file diff --git a/test/src/TestAPI.kt b/test/src/TestAPI.kt index 285ffa28..33688053 100644 --- a/test/src/TestAPI.kt +++ b/test/src/TestAPI.kt @@ -105,7 +105,8 @@ class InMemoryLocation(override val path: String): Location { } object InMemoryLocationService: LocationService { - override fun location(node: DocumentationNode) = InMemoryLocation(relativePathToNode(node)) + override fun location(qualifiedName: List<String>, hasMembers: Boolean) = + InMemoryLocation(relativePathToNode(qualifiedName, hasMembers)) } val tempLocation = InMemoryLocation("") |