diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-09-27 18:22:10 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-09-27 18:22:10 +0300 |
commit | 31af10e09963096389a4201ec1b0f8d9a11bb7f6 (patch) | |
tree | b8ff5b2b8156faceff4e019f736b3649799b90c5 /core/src/main/kotlin | |
parent | 960e022f7b94d858942f938dd9f7b877f2435964 (diff) | |
download | dokka-31af10e09963096389a4201ec1b0f8d9a11bb7f6.tar.gz dokka-31af10e09963096389a4201ec1b0f8d9a11bb7f6.tar.bz2 dokka-31af10e09963096389a4201ec1b0f8d9a11bb7f6.zip |
Insert platforms on dokka side
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt index 718c8d35..d2321ad9 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt @@ -122,22 +122,32 @@ open class KotlinWebsiteHtmlOutputBuilder( else -> "identifier" } - fun calculateDataAttributes(platforms: Set<String>): String { + private fun calculatePlatforms(platforms: Set<String>): Map<String, List<String>> { + fun String.isKotlinVersion() = this.startsWith("Kotlin") fun String.isJREVersion() = this.startsWith("JRE") - val kotlinVersion = platforms.singleOrNull(String::isKotlinVersion) + val kotlinVersion = platforms.singleOrNull(String::isKotlinVersion)?.removePrefix("Kotlin ") val jreVersion = platforms.singleOrNull(String::isJREVersion) val targetPlatforms = platforms.filterNot { it.isKotlinVersion() || it.isJREVersion() } .takeUnless { it.intersect(impliedPlatforms).containsAll(impliedPlatforms) } .orEmpty() + return mapOf( + "platform" to targetPlatforms, + "kotlin-version" to listOfNotNull(kotlinVersion), + "jre-version" to listOfNotNull(jreVersion) + ) + } - val kotlinVersionAttr = kotlinVersion?.let { " data-kotlin-version=\"$it\"" } ?: "" - val jreVersionAttr = jreVersion?.let { " data-jre-version=\"$it\"" } ?: "" - val platformsAttr = targetPlatforms.ifNotEmpty { " data-platform=\"${targetPlatforms.joinToString()}\"" } ?: "" - return "$platformsAttr$kotlinVersionAttr$jreVersionAttr" + private fun calculateDataAttributes(platforms: Set<String>): String { + val platformsByKind = calculatePlatforms(platforms) + return platformsByKind + .entries.filterNot { it.value.isEmpty() } + .joinToString(separator = " ") { (kind, values) -> + "data-$kind=\"${values.joinToString()}\"" + } } override fun appendIndexRow(platforms: Set<String>, block: () -> Unit) { @@ -148,7 +158,16 @@ open class KotlinWebsiteHtmlOutputBuilder( } override fun appendPlatforms(platforms: Set<String>) { - div(to, "tags") {} + val platformsToKind = calculatePlatforms(platforms) + div(to, "tags") { + platformsToKind.entries.forEach { (kind, values) -> + values.forEach { value -> + div(to, "tags__tag $kind") { + to.append(value) + } + } + } + } } override fun appendBreadcrumbSeparator() { @@ -179,7 +198,7 @@ open class KotlinWebsiteHtmlOutputBuilder( override fun appendAsPlatformDependentBlock(platforms: Set<String>, block: (Set<String>) -> Unit) { if (platforms.isNotEmpty()) - wrap("<div${calculateDataAttributes(platforms)}>", "</div>") { + wrap("<div ${calculateDataAttributes(platforms)}>", "</div>") { block(platforms) } else |