From 00d88f91c94751e7e6272b0d15e49582fd4f10da Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Thu, 13 Aug 2020 18:18:20 +0200 Subject: Implement shouldRenderSourceSetBubbles --- .../base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 9 ++++----- .../renderers/html/shouldRenderSourceSetBubbles.kt | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 plugins/base/src/main/kotlin/renderers/html/shouldRenderSourceSetBubbles.kt (limited to 'plugins/base/src') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 71a28345..ac2b1d02 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -34,9 +34,7 @@ open class HtmlRenderer( .filter { it in sourceSet.dependentSourceSets } }.toMap() - private val shouldShowSourceSetBubbles by lazy { - sourceSetDependencyMap.size > 1 - } + private var shouldRenderSourceSetBubbles: Boolean = false private val pageList = ConcurrentHashMap>() @@ -109,7 +107,7 @@ open class HtmlRenderer( } private fun FlowContent.filterButtons(page: ContentPage) { - if (shouldShowSourceSetBubbles) { + if (shouldRenderSourceSetBubbles) { div(classes = "filter-section") { id = "filter-section" page.content.withDescendants().flatMap { it.sourceSets }.distinct().forEach { @@ -415,7 +413,7 @@ open class HtmlRenderer( } private fun FlowContent.createPlatformTagBubbles(sourceSets: List) { - if (shouldShowSourceSetBubbles) { + if (shouldRenderSourceSetBubbles) { div("platform-tags") { sourceSets.forEach { div("platform-tag") { @@ -650,6 +648,7 @@ open class HtmlRenderer( .joinToString(prefix = "[", separator = ",\n", postfix = "]") override fun render(root: RootPageNode) { + shouldRenderSourceSetBubbles = shouldRenderSourceSetBubbles(root) super.render(root) runBlocking(Dispatchers.Default) { launch { diff --git a/plugins/base/src/main/kotlin/renderers/html/shouldRenderSourceSetBubbles.kt b/plugins/base/src/main/kotlin/renderers/html/shouldRenderSourceSetBubbles.kt new file mode 100644 index 00000000..3de58870 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/html/shouldRenderSourceSetBubbles.kt @@ -0,0 +1,16 @@ +package org.jetbrains.dokka.base.renderers.html + +import org.jetbrains.dokka.model.withDescendants +import org.jetbrains.dokka.pages.ContentPage +import org.jetbrains.dokka.pages.RootPageNode + +internal fun shouldRenderSourceSetBubbles(page: RootPageNode): Boolean { + return page.withDescendants() + .flatMap { pageNode -> + if (pageNode is ContentPage) pageNode.content.withDescendants() + else emptySequence() + } + .flatMap { contentNode -> contentNode.sourceSets } + .distinct() + .count() > 1 +} -- cgit