From 6276fd0e68085c9b0994f8f947bf904b9b285b34 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 28 Feb 2017 12:24:31 +0300 Subject: Split data tags for kotlin-website format --- .../kotlin/Formats/KotlinWebsiteFormatService.kt | 17 ++++- .../test/kotlin/format/KotlinWebSiteFormatTest.kt | 24 ++++++- core/testdata/format/website/dataTags/jre7.kt | 11 +++ core/testdata/format/website/dataTags/js.kt | 11 +++ core/testdata/format/website/dataTags/jvm.kt | 11 +++ .../website/dataTags/multiplatform.package.md | 79 ++++++++++++++++++++++ 6 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 core/testdata/format/website/dataTags/jre7.kt create mode 100644 core/testdata/format/website/dataTags/js.kt create mode 100644 core/testdata/format/website/dataTags/jvm.kt create mode 100644 core/testdata/format/website/dataTags/multiplatform.package.md (limited to 'core') diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt index 0444a25a..e5657091 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.google.inject.name.Named import org.jetbrains.dokka.Utilities.impliedPlatformsName +import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty open class KotlinWebsiteOutputBuilder(to: StringBuilder, @@ -147,9 +148,19 @@ open class KotlinWebsiteOutputBuilder(to: StringBuilder, } override fun appendIndexRow(platforms: Set, block: () -> Unit) { - if (platforms.isNotEmpty()) - wrap("", "", block) - else + if (platforms.isNotEmpty()) { + fun String.isKotlinVersion() = this.startsWith("Kotlin") + fun String.isJREVersion() = this.startsWith("JRE") + val kotlinVersion = platforms.singleOrNull(String::isKotlinVersion) + val jreVersion = platforms.singleOrNull(String::isJREVersion) + val targetPlatforms = platforms.filterNot { it.isKotlinVersion() || it.isJREVersion() } + + val kotlinVersionAttr = kotlinVersion?.let { " data-kotlin-version=\"$it\"" } ?: "" + val jreVersionAttr = jreVersion?.let { " data-jre-version=\"$it\"" } ?: "" + val platformsAttr = targetPlatforms.ifNotEmpty { " data-platform=\"${targetPlatforms.joinToString()}\"" } ?: "" + + wrap("", "", block) + } else appendTableRow(block) } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index 27c84aca..2d86ba5b 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -1,7 +1,6 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.KotlinLanguageService -import org.jetbrains.dokka.KotlinWebsiteFormatService +import org.jetbrains.dokka.* import org.junit.Test class KotlinWebSiteFormatTest { @@ -19,9 +18,30 @@ class KotlinWebSiteFormatTest { verifyKWSNodeByName("overloadGroup", "magic") } + @Test fun dataTags() { + val module = buildMultiplePlatforms("dataTags") + verifyMultiplatformPackage(module, "dataTags") + } + private fun verifyKWSNodeByName(fileName: String, name: String) { verifyOutput("testdata/format/website/$fileName.kt", ".md", format = "kotlin-website") { model, output -> kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) } } + + private fun buildMultiplePlatforms(path: String): DocumentationModule { + val module = DocumentationModule("test") + val options = DocumentationOptions("", "html", generateIndexPages = false) + appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) + appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) + appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/website/$path/multiplatform.kt") { model, output -> + kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + } + } + } diff --git a/core/testdata/format/website/dataTags/jre7.kt b/core/testdata/format/website/dataTags/jre7.kt new file mode 100644 index 00000000..d21b8d7b --- /dev/null +++ b/core/testdata/format/website/dataTags/jre7.kt @@ -0,0 +1,11 @@ +package foo + +@SinceKotlin("1.1") +fun jre7New() {} + +fun jre7() {} + +fun shared() {} + +@SinceKotlin("1.1") +fun sharedNew() {} \ No newline at end of file diff --git a/core/testdata/format/website/dataTags/js.kt b/core/testdata/format/website/dataTags/js.kt new file mode 100644 index 00000000..b22d7088 --- /dev/null +++ b/core/testdata/format/website/dataTags/js.kt @@ -0,0 +1,11 @@ +package foo + +@SinceKotlin("1.1") +fun jsNew() {} + +fun js() {} + +fun shared() {} + +@SinceKotlin("1.1") +fun sharedNew() {} \ No newline at end of file diff --git a/core/testdata/format/website/dataTags/jvm.kt b/core/testdata/format/website/dataTags/jvm.kt new file mode 100644 index 00000000..02d04226 --- /dev/null +++ b/core/testdata/format/website/dataTags/jvm.kt @@ -0,0 +1,11 @@ +package foo + +@SinceKotlin("1.1") +fun jvmNew() {} + +fun jvm() {} + +fun shared() {} + +@SinceKotlin("1.1") +fun sharedNew() {} \ No newline at end of file diff --git a/core/testdata/format/website/dataTags/multiplatform.package.md b/core/testdata/format/website/dataTags/multiplatform.package.md new file mode 100644 index 00000000..1dccb6ba --- /dev/null +++ b/core/testdata/format/website/dataTags/multiplatform.package.md @@ -0,0 +1,79 @@ +--- +title: foo - test +layout: api +--- + + + +## Package foo + +### Functions + + + + + + + + + + + + + + + + + + + + +
+jre7 +(JVM, JRE7) + +
fun jre7(): Unit
+ +
+jre7New +(Kotlin 1.1, JVM, JRE7) + +
fun jre7New(): Unit
+ +
+js +(JS) + +
fun js(): Unit
+ +
+jsNew +(Kotlin 1.1, JS) + +
fun jsNew(): Unit
+ +
+jvm +(JVM) + +
fun jvm(): Unit
+ +
+jvmNew +(Kotlin 1.1, JVM) + +
fun jvmNew(): Unit
+ +
+shared +(JVM, JRE7, JS) + +
fun shared(): Unit
+ +
+sharedNew +(Kotlin 1.1, JVM, JRE7, JS) + +
fun sharedNew(): Unit
+ +
-- cgit