diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2022-08-18 19:33:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-18 19:33:53 +0200 |
commit | 50a3323322265ff3b5dab1d861a25bbb1167812a (patch) | |
tree | 0966cfab6d9155724a65439a5c0d1476d66b0a7a /plugins/base/src/main/kotlin/renderers | |
parent | df8d9879b818799c83ff731b3a78e7d2b96fd8e5 (diff) | |
download | dokka-50a3323322265ff3b5dab1d861a25bbb1167812a.tar.gz dokka-50a3323322265ff3b5dab1d861a25bbb1167812a.tar.bz2 dokka-50a3323322265ff3b5dab1d861a25bbb1167812a.zip |
Add deprecation details block (#2622)
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
3 files changed, 43 insertions, 12 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 945fff38..f5c3854c 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -95,6 +95,7 @@ open class HtmlRenderer( childrenCallback() } node.hasStyle(ContentStyle.KDocTag) -> span("kdoc-tag") { childrenCallback() } + node.hasStyle(ContentStyle.Footnote) -> div("footnote") { childrenCallback() } node.hasStyle(TextStyle.BreakableAfter) -> { span { childrenCallback() } wbr { } @@ -124,10 +125,12 @@ open class HtmlRenderer( node.dci.kind == ContentKind.Cover -> div("cover $additionalClasses") { //TODO this can be removed childrenCallback() } + node.dci.kind == ContentKind.Deprecation -> div("deprecation-content") { childrenCallback() } node.hasStyle(TextStyle.Paragraph) -> p(additionalClasses) { childrenCallback() } node.hasStyle(TextStyle.Block) -> div(additionalClasses) { childrenCallback() } node.hasStyle(TextStyle.Quotation) -> blockQuote(additionalClasses) { childrenCallback() } node.hasStyle(TextStyle.FloatingRight) -> span("clearfix") { span("floating-right") { childrenCallback() } } + node.hasStyle(TextStyle.Strikethrough) -> strike { childrenCallback() } node.isAnchorable -> buildAnchor( node.anchor!!, node.anchorLabel!!, diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt index 958488ef..ecce70e8 100644 --- a/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt +++ b/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.base.renderers.html import org.jetbrains.dokka.base.renderers.sourceSets +import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.annotations +import org.jetbrains.dokka.base.transformers.documentables.isDeprecated import org.jetbrains.dokka.base.transformers.documentables.isException import org.jetbrains.dokka.base.translators.documentables.DocumentableLanguage import org.jetbrains.dokka.base.translators.documentables.documentableLanguage @@ -17,6 +19,7 @@ abstract class NavigationDataProvider { dri = page.dri.first(), sourceSets = page.sourceSets(), icon = chooseNavigationIcon(page), + styles = chooseStyles(page), children = page.navigableChildren() ) @@ -31,8 +34,8 @@ abstract class NavigationDataProvider { name } - private fun chooseNavigationIcon(contentPage: ContentPage): NavigationNodeIcon? { - return if (contentPage is WithDocumentables) { + private fun chooseNavigationIcon(contentPage: ContentPage): NavigationNodeIcon? = + if (contentPage is WithDocumentables) { val documentable = contentPage.documentables.firstOrNull() val isJava = documentable?.hasAnyJavaSources() ?: false @@ -61,27 +64,41 @@ abstract class NavigationDataProvider { } else { null } - } private fun Documentable.hasAnyJavaSources(): Boolean { val withSources = this as? WithSources ?: return false return this.sourceSets.any { withSources.documentableLanguage(it) == DocumentableLanguage.JAVA } } - private fun DClass.isAbstract(): Boolean { - return modifier.values.all { it is KotlinModifier.Abstract || it is JavaModifier.Abstract } + private fun DClass.isAbstract() = + modifier.values.all { it is KotlinModifier.Abstract || it is JavaModifier.Abstract } + + private fun chooseStyles(page: ContentPage): Set<Style> = + if (page.containsOnlyDeprecatedDocumentables()) setOf(TextStyle.Strikethrough) else emptySet() + + private fun ContentPage.containsOnlyDeprecatedDocumentables(): Boolean { + if (this !is WithDocumentables) { + return false + } + return this.documentables.isNotEmpty() && this.documentables.all { it.isDeprecatedForAllSourceSets() } + } + + private fun Documentable.isDeprecatedForAllSourceSets(): Boolean { + val sourceSetAnnotations = this.annotations() + return sourceSetAnnotations.isNotEmpty() && sourceSetAnnotations.all { (_, annotations) -> + annotations.any { it.isDeprecated() } + } } - private fun ContentPage.navigableChildren(): List<NavigationNode> { - return if (this is ClasslikePage) { - return this.navigableChildren() + private fun ContentPage.navigableChildren() = + if (this is ClasslikePage) { + this.navigableChildren() } else { children .filterIsInstance<ContentPage>() .map { visit(it) } .sortedBy { it.name.toLowerCase() } } - } private fun ClasslikePage.navigableChildren(): List<NavigationNode> { // Classlikes should only have other classlikes as navigable children diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt index 87808add..fc17983d 100644 --- a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt +++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt @@ -57,17 +57,27 @@ class NavigationPage( span("nav-link-grid") { span("nav-link-child ${node.icon?.style()}") span("nav-link-child") { - buildBreakableText(node.name) + nodeText(node) } } } else { - buildBreakableText(node.name) + nodeText(node) } } } node.children.withIndex().forEach { (n, p) -> visit(p, "$navId-$n", renderer) } } } + + private fun FlowContent.nodeText(node: NavigationNode) { + if (node.styles.contains(TextStyle.Strikethrough)) { + strike { + buildBreakableText(node.name) + } + } else { + buildBreakableText(node.name) + } + } } data class NavigationNode( @@ -75,6 +85,7 @@ data class NavigationNode( val dri: DRI, val sourceSets: Set<DisplaySourceSet>, val icon: NavigationNodeIcon?, + val styles: Set<Style> = emptySet(), override val children: List<NavigationNode> ) : WithChildren<NavigationNode> @@ -108,4 +119,4 @@ fun NavigationPage.transform(block: (NavigationNode) -> NavigationNode) = NavigationPage(root.transform(block), moduleName, context) fun NavigationNode.transform(block: (NavigationNode) -> NavigationNode) = - run(block).let { NavigationNode(it.name, it.dri, it.sourceSets, it.icon, it.children.map(block)) } + run(block).let { NavigationNode(it.name, it.dri, it.sourceSets, it.icon, it.styles, it.children.map(block)) } |