From 31af10e09963096389a4201ec1b0f8d9a11bb7f6 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 27 Sep 2018 18:22:10 +0300 Subject: Insert platforms on dokka side --- .../Formats/KotlinWebsiteHtmlFormatService.kt | 35 +++++++++++++++++----- 1 file 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 { + private fun calculatePlatforms(platforms: Set): Map> { + 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 { + val platformsByKind = calculatePlatforms(platforms) + return platformsByKind + .entries.filterNot { it.value.isEmpty() } + .joinToString(separator = " ") { (kind, values) -> + "data-$kind=\"${values.joinToString()}\"" + } } override fun appendIndexRow(platforms: Set, block: () -> Unit) { @@ -148,7 +158,16 @@ open class KotlinWebsiteHtmlOutputBuilder( } override fun appendPlatforms(platforms: Set) { - 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, block: (Set) -> Unit) { if (platforms.isNotEmpty()) - wrap("", "") { + wrap("
", "
") { block(platforms) } else -- cgit