diff options
Diffstat (limited to 'plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt')
-rw-r--r-- | plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt b/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt index cfd0d675..b0fa13d0 100644 --- a/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt +++ b/plugins/all-modules-page/src/main/kotlin/MultimoduleLocationProvider.kt @@ -6,6 +6,7 @@ package org.jetbrains.dokka.allModulesPage import org.jetbrains.dokka.allModulesPage.MultimodulePageCreator.Companion.MULTIMODULE_PACKAGE_PLACEHOLDER import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider +import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet @@ -16,9 +17,10 @@ import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle -open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaContext: DokkaContext, - val extension: String = ".html") : - DokkaBaseLocationProvider(root, dokkaContext) { +public open class MultimoduleLocationProvider( + private val root: RootPageNode, dokkaContext: DokkaContext, + public val extension: String = ".html" +) : DokkaBaseLocationProvider(root, dokkaContext) { private val defaultLocationProvider = dokkaContext.plugin<AllModulesPagePlugin>().querySingle { partialLocationProviderFactory } @@ -26,21 +28,32 @@ open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaCont private val externalModuleLinkResolver = dokkaContext.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver } - override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) = - if (dri == MultimodulePageCreator.MULTIMODULE_ROOT_DRI) pathToRoot(root) + "index" - else dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames - ?.let(externalModuleLinkResolver::resolveLinkToModuleIndex) + override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?): String? { + return if (dri == MultimodulePageCreator.MULTIMODULE_ROOT_DRI) { + pathToRoot(root) + "index" + } else { + dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER } + ?.classNames + ?.let(externalModuleLinkResolver::resolveLinkToModuleIndex) + } + } - override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) = - if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index" + if (!skipExtension) extension else "" - else defaultLocationProvider.resolve(node, context, skipExtension) + override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean): String? { + return if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) { + pathToRoot(root) + "index" + if (!skipExtension) extension else "" + } else { + defaultLocationProvider.resolve(node, context, skipExtension) + } + } override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from) override fun ancestors(node: PageNode): List<PageNode> = listOf(root) - class Factory(private val context: DokkaContext) : LocationProviderFactory { - override fun getLocationProvider(pageNode: RootPageNode) = + public class Factory( + private val context: DokkaContext + ) : LocationProviderFactory { + override fun getLocationProvider(pageNode: RootPageNode): LocationProvider = MultimoduleLocationProvider(pageNode, context) } } |