From 3f2a790190da4f40ea6d8a976aa1929b2a1b002b Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 5 May 2020 17:45:12 +0200 Subject: Changing approach from platform-driven to source-set-driven --- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 58 +++++++++++----------- .../main/kotlin/renderers/html/NavigationPage.kt | 4 +- 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'plugins/base/src/main/kotlin/renderers/html') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index c061cabf..caabcda7 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -7,6 +7,7 @@ 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 import org.jetbrains.dokka.plugability.plugin @@ -42,10 +43,10 @@ open class HtmlRenderer( override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) { div("platform-hinted") { attributes["data-platform-hinted"] = "data-platform-hinted" - val contents = content.platforms.mapIndexed { index, platform -> + val contents = content.sourceSets.mapIndexed { index, platform -> platform to createHTML(prettyPrint = false).div(classes = "content") { if (index == 0) attributes["data-active"] = "" - attributes["data-togglable"] = platform.targets.joinToString("-") + attributes["data-togglable"] = platform.sourceSetName buildContentNode(content.inner, pageContext, platform) } } @@ -56,8 +57,8 @@ open class HtmlRenderer( contents.forEachIndexed { index, pair -> button(classes = "platform-bookmark") { if (index == 0) attributes["data-active"] = "" - attributes["data-toggle"] = pair.first.targets.joinToString("-") - text(pair.first.targets.joinToString(", ")); + attributes["data-toggle"] = pair.first.sourceSetName + text(pair.first.sourceSetName) } } } @@ -71,27 +72,27 @@ open class HtmlRenderer( override fun FlowContent.buildList( node: ContentList, pageContext: ContentPage, - platformRestriction: PlatformData? - ) = if (node.ordered) ol { buildListItems(node.children, pageContext, platformRestriction) } - else ul { buildListItems(node.children, pageContext, platformRestriction) } + sourceSetRestriction: SourceSetData? + ) = if (node.ordered) ol { buildListItems(node.children, pageContext, sourceSetRestriction) } + else ul { buildListItems(node.children, pageContext, sourceSetRestriction) } open fun OL.buildListItems( items: List, pageContext: ContentPage, - platformRestriction: PlatformData? = null + sourceSetRestriction: SourceSetData? = null ) { items.forEach { if (it is ContentList) buildList(it, pageContext) else - li { it.build(this, pageContext, platformRestriction) } + li { it.build(this, pageContext, sourceSetRestriction) } } } open fun UL.buildListItems( items: List, pageContext: ContentPage, - platformRestriction: PlatformData? = null + sourceSetRestriction: SourceSetData? = null ) { items.forEach { if (it is ContentList) @@ -118,64 +119,63 @@ open class HtmlRenderer( private fun FlowContent.buildRow( node: ContentGroup, pageContext: ContentPage, - platformRestriction: PlatformData? + sourceSetRestriction: SourceSetData? ) { node.children .filter { - platformRestriction == null || platformRestriction in it.platforms + sourceSetRestriction == null || sourceSetRestriction in it.sourceSets } .takeIf { it.isNotEmpty() } ?.let { div(classes = "table-row") { it.filter { it.dci.kind != ContentKind.Symbol }.takeIf { it.isNotEmpty() }?.let { div("main-subrow ${node.style.joinToString { it.toString().decapitalize() }}") { - it.filter { platformRestriction == null || platformRestriction in it.platforms } + it.filter { sourceSetRestriction == null || sourceSetRestriction in it.sourceSets } .forEach { when(it.dci.kind){ - ContentKind.PlatformDependantHint -> { + ContentKind.SourceSetDependantHint -> { div("platform-dependant-row keyValue"){ div() div("title"){ - it.build(this, pageContext, platformRestriction) + it.build(this, pageContext, sourceSetRestriction) } } } ContentKind.Main -> { div("title-row"){ - it.build(this, pageContext, platformRestriction) + it.build(this, pageContext, sourceSetRestriction) div() - if (ContentKind.shouldBePlatformTagged(node.dci.kind) && node.platforms.size == 1) { + if (ContentKind.shouldBePlatformTagged(node.dci.kind) && node.sourceSets.size == 1) { createPlatformTags(node) } else { div() } } } - else -> div { it.build(this, pageContext, platformRestriction) } + else -> div { it.build(this, pageContext, sourceSetRestriction) } } } } } it.filter { it.dci.kind == ContentKind.Symbol }.takeIf { it.isNotEmpty() }?.let { div("signature-subrow") { - div("signatures"){ + div("signatures") { it.forEach { - it.build(this, pageContext, platformRestriction) + it.build(this, pageContext, sourceSetRestriction) } } } } } - } + } } - private fun FlowContent.createPlatformTags( node: ContentNode ) { + private fun FlowContent.createPlatformTags(node: ContentNode) { div("platform-tags") { - node.platforms.forEach { + node.sourceSets.forEach { div("platform-tag") { - val targets = it.targets.joinToString(", ") - if( targets.equals("common", ignoreCase = true) ) classes = classes + "common" - text(it.targets.joinToString(", ")) + if (it.sourceSetName.equals("common", ignoreCase = true)) classes = classes + "common" + text(it.sourceSetName) } } } @@ -184,11 +184,11 @@ open class HtmlRenderer( override fun FlowContent.buildTable( node: ContentTable, pageContext: ContentPage, - platformRestriction: PlatformData? + sourceSetRestriction: SourceSetData? ) { div(classes = "table") { node.children.forEach { - buildRow(it, pageContext, platformRestriction) + buildRow(it, pageContext, sourceSetRestriction) } } } @@ -221,7 +221,7 @@ open class HtmlRenderer( fun FlowContent.buildLink( to: DRI, - platforms: List, + platforms: List, from: PageNode? = null, block: FlowContent.() -> Unit ) = buildLink(locationProvider.resolve(to, platforms, from), block) diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt index 4b90cc8a..4048c11e 100644 --- a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt +++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt @@ -3,8 +3,8 @@ package org.jetbrains.dokka.base.renderers.html import kotlinx.html.* import kotlinx.html.stream.createHTML import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.pages.PageNode -import org.jetbrains.dokka.pages.PlatformData import org.jetbrains.dokka.pages.RendererSpecificPage import org.jetbrains.dokka.pages.RenderingStrategy @@ -41,7 +41,7 @@ class NavigationPage(val root: NavigationNode) : RendererSpecificPage { class NavigationNode( val name: String, val dri: DRI, - val platforms: List, + val platforms: List, val children: List ) -- cgit