diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-07-13 13:47:19 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-07-13 18:07:27 +0200 |
commit | b8c11e696e91807ef615a0f76b5bc0199415e544 (patch) | |
tree | ebd4099ed89816e850df242c0dc44e9420b3e58d /plugins/base/src | |
parent | 52e333997dc7af5c01107dd5959b175ee171ffc1 (diff) | |
download | dokka-b8c11e696e91807ef615a0f76b5bc0199415e544.tar.gz dokka-b8c11e696e91807ef615a0f76b5bc0199415e544.tar.bz2 dokka-b8c11e696e91807ef615a0f76b5bc0199415e544.zip |
Single platform bubbles fix
Diffstat (limited to 'plugins/base/src')
4 files changed, 62 insertions, 49 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index dc211502..f1ff9673 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -28,6 +28,10 @@ open class HtmlRenderer( sourceSet to context.configuration.sourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetID) } }.toMap() + private val isMultiplatform by lazy { + sourceSetDependencyMap.size > 1 + } + private val pageList = mutableMapOf<String, Pair<String, String>>() override val preprocessors = context.plugin<DokkaBase>().query { htmlPreprocessors } @@ -99,19 +103,21 @@ open class HtmlRenderer( } private fun FlowContent.filterButtons(group: ContentGroup) { - div(classes = "filter-section") { - id = "filter-section" - group.sourceSets.forEach { - button(classes = "platform-tag platform-selector") { - attributes["data-active"] = "" - attributes["data-filter"] = it.sourceSetID.toString() - when (it.analysisPlatform.key) { - "common" -> classes = classes + "common-like" - "native" -> classes = classes + "native-like" - "jvm" -> classes = classes + "jvm-like" - "js" -> classes = classes + "js-like" + if (isMultiplatform) { + div(classes = "filter-section") { + id = "filter-section" + group.sourceSets.forEach { + button(classes = "platform-tag platform-selector") { + attributes["data-active"] = "" + attributes["data-filter"] = it.sourceSetID.toString() + when (it.analysisPlatform.key) { + "common" -> classes = classes + "common-like" + "native" -> classes = classes + "native-like" + "jvm" -> classes = classes + "jvm-like" + "js" -> classes = classes + "js-like" + } + text(it.displayName) } - text(it.displayName) } } } @@ -182,9 +188,7 @@ open class HtmlRenderer( attributes["data-filterable-set"] = pair.first.sourceSetID.toString() if (index == 0) attributes["data-active"] = "" attributes["data-toggle"] = pair.first.sourceSetID.toString() - when ( - pair.first.analysisPlatform.key - ) { + when (pair.first.analysisPlatform.key) { "common" -> classes = classes + "common-like" "native" -> classes = classes + "native-like" "jvm" -> classes = classes + "jvm-like" @@ -400,16 +404,18 @@ open class HtmlRenderer( } private fun FlowContent.createPlatformTagBubbles(sourceSets: List<DokkaSourceSet>) { - div("platform-tags") { - sourceSets.forEach { - div("platform-tag") { - when (it.analysisPlatform.key) { - "common" -> classes = classes + "common-like" - "native" -> classes = classes + "native-like" - "jvm" -> classes = classes + "jvm-like" - "js" -> classes = classes + "js-like" + if (isMultiplatform) { + div("platform-tags") { + sourceSets.forEach { + div("platform-tag") { + when (it.analysisPlatform.key) { + "common" -> classes = classes + "common-like" + "native" -> classes = classes + "native-like" + "jvm" -> classes = classes + "jvm-like" + "js" -> classes = classes + "js-like" + } + text(it.displayName) } - text(it.displayName) } } } diff --git a/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js b/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js index e295d90b..6f10b08a 100644 --- a/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js +++ b/plugins/base/src/main/resources/dokka/scripts/platformContentHandler.js @@ -8,8 +8,11 @@ window.addEventListener('load', () => { .forEach(elem => elem.addEventListener('click', (event) => togglePlatformDependent(event,elem))) document.querySelectorAll("div[tabs-section]") .forEach(elem => elem.addEventListener('click', (event) => toggleSectionsEventHandler(event))) - document.getElementById('filter-section').addEventListener('click', (event) => filterButtonHandler(event)) - initializeFiltering() + const filterSection = document.getElementById('filter-section') + if (filterSection) { + filterSection.addEventListener('click', (event) => filterButtonHandler(event)) + initializeFiltering() + } initTabs() handleAnchor() }) diff --git a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt index 54d55721..734bea1d 100644 --- a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt @@ -12,28 +12,6 @@ import utils.Span import utils.match class DivergentTest : HtmlRenderingOnlyTestBase() { - private val js = defaultSourceSet.copy( - "root", - "JS", - defaultSourceSet.sourceSetID.copy(sourceSetName = "js"), - analysisPlatform = Platform.js, - sourceRoots = listOf(SourceRootImpl("pl1")) - ) - private val jvm = defaultSourceSet.copy( - "root", - "JVM", - defaultSourceSet.sourceSetID.copy(sourceSetName = "jvm"), - - analysisPlatform = Platform.jvm, - sourceRoots = listOf(SourceRootImpl("pl1")) - ) - private val native = defaultSourceSet.copy( - "root", - "NATIVE", - defaultSourceSet.sourceSetID.copy(sourceSetName = "native"), - analysisPlatform = Platform.native, - sourceRoots = listOf(SourceRootImpl("pl1")) - ) @Test fun simpleWrappingCase() { diff --git a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt index d533988d..b6765fda 100644 --- a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt @@ -1,6 +1,8 @@ package renderers.html import org.jetbrains.dokka.DokkaConfigurationImpl +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.SourceRootImpl import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.DefaultTabSortingStrategy import org.jetbrains.dokka.base.renderers.RootCreator @@ -14,9 +16,33 @@ import org.jsoup.nodes.Node import org.jsoup.nodes.TextNode import renderers.RenderingOnlyTestBase import utils.TestOutputWriter +import renderers.defaultSourceSet abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase<Element>() { + protected val js = defaultSourceSet.copy( + "root", + "JS", + defaultSourceSet.sourceSetID.copy(sourceSetName = "js"), + analysisPlatform = Platform.js, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + protected val jvm = defaultSourceSet.copy( + "root", + "JVM", + defaultSourceSet.sourceSetID.copy(sourceSetName = "jvm"), + + analysisPlatform = Platform.jvm, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + protected val native = defaultSourceSet.copy( + "root", + "NATIVE", + defaultSourceSet.sourceSetID.copy(sourceSetName = "native"), + analysisPlatform = Platform.native, + sourceRoots = listOf(SourceRootImpl("pl1")) + ) + val files = TestOutputWriter() override val context = MockContext( DokkaBase().outputWriter to { _ -> files }, @@ -26,7 +52,7 @@ abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase<Element>() { DokkaBase().externalLocationProviderFactory to { ::DokkaExternalLocationProviderFactory }, DokkaBase().tabSortingStrategy to { DefaultTabSortingStrategy() }, testConfiguration = DokkaConfigurationImpl( - "", null, false, emptyList(), emptyList(), emptyMap(), emptyList(), false + "", null, false, listOf(js, jvm, native), emptyList(), emptyMap(), emptyList(), false ) ) |