aboutsummaryrefslogtreecommitdiff
path: root/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-09-16 16:36:54 +0200
committerBłażej Kardyś <bkardys@virtuslab.com>2020-11-27 03:15:02 +0100
commitc8a83153a88fe6f5b50b6f459295421f90a21583 (patch)
tree4ce52c287dde3a8303549287ce67e58174d9f9fc /plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt
parent585178984228a9c2e5bd2af9b675094ac6e3fa46 (diff)
downloaddokka-c8a83153a88fe6f5b50b6f459295421f90a21583.tar.gz
dokka-c8a83153a88fe6f5b50b6f459295421f90a21583.tar.bz2
dokka-c8a83153a88fe6f5b50b6f459295421f90a21583.zip
Extracting dokka generation to the dedicated extension point
Diffstat (limited to 'plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt')
-rw-r--r--plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt b/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt
new file mode 100644
index 00000000..29107136
--- /dev/null
+++ b/plugins/all-module-page/src/main/kotlin/MultimoduleLocationProvider.kt
@@ -0,0 +1,41 @@
+package org.jetbrains.dokka.allModulesPage
+
+import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
+import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider.Companion.identifierToFilename
+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
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.pages.RootPageNode
+import org.jetbrains.dokka.plugability.DokkaContext
+
+class MultimoduleLocationProvider(private val root: RootPageNode, context: DokkaContext) : LocationProvider {
+
+ private val defaultLocationProvider = DokkaLocationProvider(root, context)
+
+ val paths = context.configuration.modules.map {
+ it.name to it.relativePathToOutputDirectory
+ }.toMap()
+
+ override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) =
+ dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames?.let { paths[it] }?.let {
+ "$it/${identifierToFilename(dri.classNames.orEmpty())}/index.html"
+ } ?: defaultLocationProvider.resolve(dri, sourceSets, context)
+
+ override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) =
+ defaultLocationProvider.resolve(node, context, skipExtension)
+
+ override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from)
+
+ override fun ancestors(node: PageNode): List<PageNode> = listOf(root)
+
+ companion object {
+ const val MULTIMODULE_PACKAGE_PLACEHOLDER = ".ext"
+ }
+
+ class Factory(private val context: DokkaContext): LocationProviderFactory {
+ override fun getLocationProvider(pageNode: RootPageNode) =
+ MultimoduleLocationProvider(pageNode, context)
+ }
+} \ No newline at end of file