From 852a6ce6c0f43c9b2044320dcceb4c6cc0a3b302 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 11 Aug 2020 21:47:26 +0200 Subject: Refactor location providers --- .../external/DefaultExternalLocationProvider.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt (limited to 'plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt') diff --git a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt new file mode 100644 index 00000000..5e22206b --- /dev/null +++ b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProvider.kt @@ -0,0 +1,22 @@ +package org.jetbrains.dokka.base.resolvers.external + +import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider.Companion.identifierToFilename +import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentationInfo +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.plugability.DokkaContext + +open class DefaultExternalLocationProvider( + val externalDocumentationInfo: ExternalDocumentationInfo, + val extension: String, + val dokkaContext: DokkaContext +) : ExternalLocationProvider { + override fun resolve(dri: DRI): String? { // TODO: classes without packages? + val docURL = externalDocumentationInfo.documentationURL.toString().removeSuffix("/") + "/" + val classNamesChecked = dri.classNames ?: return "$docURL${dri.packageName ?: ""}/index$extension" + val classLink = (listOfNotNull(dri.packageName) + classNamesChecked.split('.')) + .joinToString("/", transform = ::identifierToFilename) + + val callableChecked = dri.callable ?: return "$docURL$classLink/index$extension" + return "$docURL$classLink/" + identifierToFilename(callableChecked.name) + extension + } +} -- cgit