diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-09-26 22:14:40 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2018-09-26 22:14:40 +0300 |
commit | cffc71e39f20a368f2ffe10bf0c8aa4432dee7fc (patch) | |
tree | 5ca03e0799c82af78036eaf7b8c53c7847ed883e /core/src | |
parent | ebd4b15b8e96cfe6f88d3aed76609a8ce5f2dd67 (diff) | |
download | dokka-cffc71e39f20a368f2ffe10bf0c8aa4432dee7fc.tar.gz dokka-cffc71e39f20a368f2ffe10bf0c8aa4432dee7fc.tar.bz2 dokka-cffc71e39f20a368f2ffe10bf0c8aa4432dee7fc.zip |
Change logic of platforms rendering
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt | 22 | ||||
-rw-r--r-- | core/src/main/kotlin/Formats/StructuredFormatService.kt | 110 |
2 files changed, 66 insertions, 66 deletions
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt index e5dd57a7..66eb60c4 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt @@ -125,16 +125,16 @@ open class KotlinWebsiteHtmlOutputBuilder( fun calculateDataAttributes(platforms: Set<String>): String { fun String.isKotlinVersion() = this.startsWith("Kotlin") fun String.isJREVersion() = this.startsWith("JRE") - fun String.isNoBubbles() = this.startsWith("NoBubbles") + val kotlinVersion = platforms.singleOrNull(String::isKotlinVersion) val jreVersion = platforms.singleOrNull(String::isJREVersion) - val targetPlatforms = platforms.filterNot { it.isKotlinVersion() || it.isJREVersion() || it.isNoBubbles() } + 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()}\"" } ?: "" - val classes = if (NoBubbles in platforms) " class=\"no-bubbles\"" else "" - return "$classes$platformsAttr$kotlinVersionAttr$jreVersionAttr" + return "$platformsAttr$kotlinVersionAttr$jreVersionAttr" } override fun appendIndexRow(platforms: Set<String>, block: () -> Unit) { @@ -144,7 +144,9 @@ open class KotlinWebsiteHtmlOutputBuilder( appendTableRow(block) } - override fun appendPlatforms(platforms: Set<String>) {} + override fun appendPlatforms(platforms: Set<String>) { + div(to, "tags") {} + } override fun appendBreadcrumbSeparator() { to.append(" / ") @@ -172,11 +174,13 @@ open class KotlinWebsiteHtmlOutputBuilder( } } - override fun appendAsBlockWithPlatforms(platforms: Set<String>, block: () -> Unit) { + override fun appendAsPlatformDependentBlock(platforms: Set<String>, block: (Set<String>) -> Unit) { if (platforms.isNotEmpty()) - wrap("<div${calculateDataAttributes(platforms)}>", "</div>", block) + wrap("<div${calculateDataAttributes(platforms)}>", "</div>") { + block(platforms) + } else - block() + block(platforms) } } @@ -192,5 +196,3 @@ class KotlinWebsiteHtmlFormatService @Inject constructor( override fun createOutputBuilder(to: StringBuilder, location: Location) = KotlinWebsiteHtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, templateService) } - -val NoBubbles = "NoBubbles"
\ No newline at end of file diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index c5b6c8eb..04710694 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -83,8 +83,8 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } } - open fun appendAsBlockWithPlatforms(platforms: Set<String>, block: () -> Unit) { - block() + open fun appendAsPlatformDependentBlock(platforms: Set<String>, block: (Set<String>) -> Unit) { + block(platforms) } open fun appendSymbol(text: String) { @@ -311,11 +311,9 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, formatOverloadGroup(breakdownBySummary.values.single(), isSingleNode) } else { for ((_, items) in breakdownBySummary) { - - appendAsOverloadGroup(to, effectivePlatformsForMembers(items)) { + appendAsOverloadGroup(to, effectivePlatformAndVersion(items)) { formatOverloadGroup(items) } - } } } @@ -339,19 +337,23 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } if (item.kind == NodeKind.GroupNode) { - for (origin in item.origins) { - if (origin.content.isEmpty()) continue - appendParagraph { - appendStrong { to.append("Platform and version requirements:") } - to.append(" " + origin.actualPlatforms) - appendContent(origin.summary) + for ((content, origins) in item.origins.groupBy { it.content }) { + if (content.isEmpty()) continue + val platforms = effectivePlatformsForMembers(origins) + appendAsPlatformDependentBlock(platforms) { + appendPlatforms(platforms) + appendParagraph { + appendContent(content) + } } } } else { if (!item.content.isEmpty()) { - appendStrong { to.append("Platform and version requirements:") } - to.append(" " + item.actualPlatforms) - appendContent(item.content.summary) + val platforms = effectivePlatformsForNode(item) + appendAsPlatformDependentBlock(platforms) { + appendPlatforms(platforms) + appendContent(item.content) + } } } @@ -382,26 +384,19 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } for ((sign, nodes) in groupBySignature) { - val first = nodes.first() - first.detailOrNull(NodeKind.Signature)?.let { - if (item.kind !in NodeKind.classLike || !isSingleNode) - appendAnchor(it.name) - } - - appendAsSignature(sign) { - appendCode { appendContent(sign) } - } - first.appendOverrides() - first.appendDeprecation() - + appendAsPlatformDependentBlock(effectivePlatformAndVersion(nodes)) { platforms -> + val first = nodes.first() + first.detailOrNull(NodeKind.Signature)?.let { + if (item.kind !in NodeKind.classLike || !isSingleNode) + appendAnchor(it.name) + } - appendParagraph { - appendStrong { to.append("Platform and version requirements:") } - to.append(" " + nodes - .flatMap { it.actualPlatforms } - .distinct() - .joinToString() - ) + appendAsSignature(sign) { + appendCode { appendContent(sign) } + } + appendPlatforms(platforms) + first.appendOverrides() + first.appendDeprecation() } } @@ -463,7 +458,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } val DocumentationNode.actualPlatforms: Collection<String> - get() = effectivePlatformsForNode(this) + get() = effectivePlatformAndVersion(listOf(this)) // protected fun platformsOfItems(items: List<DocumentationNode>): Set<String> { @@ -572,11 +567,13 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, renderGroupNode(node, true) - for (origin in node.origins) { - if (origin.content.isEmpty()) continue - appendStrong { to.append("Platform and version requirements:") } - to.append(" " + origin.actualPlatforms) - appendContent(origin.content.summary) + for ((content, origins) in node.origins.groupBy { it.content }) { + if (content.isEmpty()) continue + val platforms = effectivePlatformAndVersion(origins) + appendAsPlatformDependentBlock(platforms) { + appendPlatforms(platforms) + appendContent(content) + } } SectionsBuilder(node).build() @@ -679,7 +676,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, appendTable("Name", "Summary") { appendTableBody { for ((memberLocation, members) in membersMap) { - val platforms = effectivePlatformsForMembers(members) + sinceKotlinAsPlatform(effectiveSinceKotlinForNodes(members)) + val platforms = emptySet<String>() // val platforms = if (platformsBasedOnMembers) // members.flatMapTo(mutableSetOf()) { platformsOfItems(it.members) } + elementPlatforms // else @@ -688,12 +685,10 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, appendTableCell { appendParagraph { appendLink(memberLocation) - if (members.singleOrNull()?.kind != NodeKind.ExternalClass) { - appendPlatforms(platforms) - } +// if (members.singleOrNull()?.kind != NodeKind.ExternalClass) { +// appendPlatforms(platforms) +// } } - } - appendTableCell { appendSummarySignatures(members, platformsBasedOnMembers, omitSamePlatforms, platforms) } } @@ -742,9 +737,8 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } } - val platforms = effectivePlatformsForMembers(nodes) - val platformsToAppend = platforms + sinceKotlinAsPlatform(effectiveSinceKotlinForNodes(nodes)) + NoBubbles - appendAsBlockWithPlatforms(platformsToAppend) { + val platformsToAppend = effectivePlatformAndVersion(nodes) + appendAsPlatformDependentBlock(platformsToAppend) { appendContent(summary) appendSoftLineBreak() } @@ -758,21 +752,20 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, omitSamePlatforms: Boolean, parentPlatforms: Set<String> ) { - val platforms = effectivePlatformsForMembers(items) + // val platforms = if (platformsBasedOnMembers) // items.flatMapTo(mutableSetOf()) { platformsOfItems(it.members) } + elementPlatforms // else // elementPlatforms - print("signature>") - val platformsToAppend = platforms + sinceKotlinAsPlatform(effectiveSinceKotlinForNodes(items)) + val platformsToAppend = effectivePlatformAndVersion(items) - appendAsBlockWithPlatforms(platformsToAppend) { - appendPlatforms(platforms) - appendAsSignature(signature) { - signature.appendSignature() - } + appendAsPlatformDependentBlock(platformsToAppend) { + appendAsSignature(signature) { + signature.appendSignature() + } appendSoftLineBreak() + appendPlatforms(platformsToAppend) } } } @@ -904,3 +897,8 @@ fun effectiveSinceKotlinForNodes(nodes: List<DocumentationNode>, baseVersion: St } fun sinceKotlinAsPlatform(version: String): String = "Kotlin $version" + + +fun effectivePlatformAndVersion(nodes: List<DocumentationNode>, baseVersion: String = "1.0"): Set<String> { + return effectivePlatformsForMembers(nodes) + sinceKotlinAsPlatform(effectiveSinceKotlinForNodes(nodes, baseVersion)) +} |