diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-05 00:16:30 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2019-11-05 13:55:38 +0100 |
commit | 61cfbcb990da1fd8fd44c6285e6927a57159d15b (patch) | |
tree | ef32a9099ea4cca7436fca5510e50317d285f382 /core/src/main/kotlin/resolvers/DefaultLocationProvider.kt | |
parent | 78ef161062eefe33633ad912817ad5c0e1555ed6 (diff) | |
download | dokka-61cfbcb990da1fd8fd44c6285e6927a57159d15b.tar.gz dokka-61cfbcb990da1fd8fd44c6285e6927a57159d15b.tar.bz2 dokka-61cfbcb990da1fd8fd44c6285e6927a57159d15b.zip |
Changing path generation for page nodes
Diffstat (limited to 'core/src/main/kotlin/resolvers/DefaultLocationProvider.kt')
-rw-r--r-- | core/src/main/kotlin/resolvers/DefaultLocationProvider.kt | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt index a2756d42..65b27779 100644 --- a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt +++ b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt @@ -8,38 +8,42 @@ import org.jetbrains.dokka.pages.* open class DefaultLocationProvider(private val pageGraphRoot: PageNode, val configuration: DokkaConfiguration, val extension: String): LocationProvider { // TODO: cache override fun resolve(node: PageNode, context: PageNode?): String = pathTo(node, context) + extension - override fun resolve(dri: DRI, platforms: List<PlatformData>, context: PageNode?): String { - findInPageGraph(dri, platforms)?.let { return resolve(it, context) } + override fun resolve(dri: DRI, platforms: List<PlatformData>, context: PageNode?): String = + findInPageGraph(dri, platforms)?.let { resolve(it, context) } ?: // Not found in PageGraph, that means it's an external link - - val externalDocs = configuration.passesConfigurations + ExternalLocationProvider.getLocation(dri, + configuration.passesConfigurations .filter { passConfig -> passConfig.targets.toSet() == platforms.toSet() } // TODO: change targets to something better? .flatMap { it.externalDocumentationLinks }.map { it.packageListUrl }.distinct() - - return ExternalLocationProvider.getLocation(dri, externalDocs) - } + ) protected open fun findInPageGraph(dri: DRI, platforms: List<PlatformData>): PageNode? = pageGraphRoot.dfs { it.dri == dri } - protected open fun pathTo(node: PageNode, context: PageNode?): String { // TODO: can be refactored probably, also we should think about root - fun parentPath(node: PageNode?): String { - if (node == null) return "" - val parts = node.parent?.let(::parentPath) ?: "" - return if(node is PackagePageNode) { - "$parts${node.name}/" - } else if (parts.isNotBlank()) { - "$parts${identifierToFilename(node.name)}/" - } else { - identifierToFilename(node.name) + "/" - } - } - val resolved = parentPath(node.parent) + identifierToFilename(node.name) + - if (node.children.isEmpty()) { - "" - } else { - "/index" - } - return context?.let { resolved.replace(pathTo(it, null).dropLastWhile { it != '/' }, "") } ?: resolved + protected open fun pathTo(node: PageNode, context: PageNode?): String { + + fun getPath(pathNode: PageNode?, path: MutableList<String> = mutableListOf()): List<String> = + if (pathNode == null || pathNode == pageGraphRoot) + path + else + getPath(pathNode.parent, path.apply { + add(if (node is PackagePageNode) { + node.name + } else { + identifierToFilename(node.name) + }) + }) + + val nodePath = getPath(node).reversed() + val contextPath = getPath(context).reversed() + + val commonPathElements = nodePath.zip(contextPath).takeWhile { (a, b) -> a == b }.size + + return ( List(contextPath.size - commonPathElements) { ".." } + nodePath.drop(commonPathElements) ).joinToString("/") + + if(node.children.isNotEmpty()) PAGE_WITH_CHILDREN_SUFFIX else "" + } + + private companion object { + const val PAGE_WITH_CHILDREN_SUFFIX = "/index" } } @@ -76,7 +80,7 @@ fun DRI.toDokkaLocation(extension: String): String { // TODO: classes without pa return "$classLink/${identifierToFilename(callable.name)}$extension" } -private val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out") +private val reservedFilenames = setOf("index", "con", "aux", "lst", "prn", "nul", "eof", "inp", "out") private fun identifierToFilename(name: String): String { if (name.isEmpty()) return "--root--" |