aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers/external/DokkaExternalLocationProviderFactory.kt
blob: ff9186f7c56b6ab235e13b45ca41b49370254339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.jetbrains.dokka.base.resolvers.external

import org.jetbrains.dokka.base.resolvers.local.identifierToFilename
import org.jetbrains.dokka.links.DRI


class DokkaExternalLocationProviderFactory : ExternalLocationProviderFactory by ExternalLocationProviderFactoryWithCache(
    object : ExternalLocationProviderFactory {
        override fun getExternalLocationProvider(param: String): ExternalLocationProvider? =
            when (param) {
                "kotlin-website-html", "html" -> DokkaExternalLocationProvider(param, ".html")
                "markdown" -> DokkaExternalLocationProvider(param, ".md")
                else -> null
            }
    }
)

class DokkaExternalLocationProvider(override val param: String, val extension: String) : ExternalLocationProvider {

    override fun DRI.toLocation(): String { // TODO: classes without packages?

        val classNamesChecked = classNames ?: return "${packageName ?: ""}/index$extension"

        val classLink = (listOfNotNull(packageName) + classNamesChecked.split('.')).joinToString(
            "/",
            transform = ::identifierToFilename
        )

        val callableChecked = callable ?: return "$classLink/index$extension"

        return "$classLink/${identifierToFilename(
            callableChecked.name
        )}$extension"
    }
}