From 6b85bb2ec2764a2c8b14717ef8e013a0f3c6e99f Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 19 May 2020 19:02:58 +0200 Subject: Merging of platform dependent hints in sourceset tree --- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index dd293e54..64c03bc7 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -6,7 +6,6 @@ import kotlinx.html.stream.createHTML import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.DefaultRenderer import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.DFunction import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext @@ -19,6 +18,12 @@ open class HtmlRenderer( context: DokkaContext ) : DefaultRenderer(context) { + private val sourceSetDependencyMap = with(context.sourceSetCache) { + allSourceSets.map { sourceSet -> + sourceSet to allSourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetName ) } + }.toMap() + } + private val pageList = mutableListOf() override val preprocessors = context.plugin().query { htmlPreprocessors } + @@ -49,16 +54,26 @@ open class HtmlRenderer( ) { div("platform-hinted") { attributes["data-platform-hinted"] = "data-platform-hinted" - val contents = nodes.toList().mapIndexed { index, (sourceSet, elements) -> - sourceSet to createHTML(prettyPrint = false).div(classes = "content") { - if (index == 0) attributes["data-active"] = "" - attributes["data-togglable"] = sourceSet.sourceSetName + var counter = 0 + val contents = nodes.toList().map { (sourceSet, elements) -> + sourceSet to createHTML(prettyPrint = false).div { elements.forEach { buildContentNode(it, pageContext, setOf(sourceSet)) } + }.stripDiv() + }.groupBy(Pair::second, Pair::first).entries.flatMap { (html, sourceSets) -> + sourceSets.filterNot { + sourceSetDependencyMap[it].orEmpty().any { dependency -> sourceSets.contains(dependency) } + }.map { + it to createHTML(prettyPrint = false).div(classes = "content") { + if (counter++ == 0) attributes["data-active"] = "" + attributes["data-togglable"] = it.sourceSetName + unsafe { + +html + } + } } } - if (contents.size != 1) { div("platform-bookmarks-row") { attributes["data-toggle-list"] = "data-toggle-list" -- cgit