From 7b020f000aa7ea868d5d3037e68eaec621ef9972 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 4 Aug 2022 12:43:54 +0200 Subject: Render nested classlikes in navigation (#2597) --- .../renderers/html/NavigationDataProvider.kt | 24 +++++++++++++++------- .../main/kotlin/renderers/html/NavigationPage.kt | 7 +------ 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'plugins/base/src/main/kotlin') diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt index 647ba687..958488ef 100644 --- a/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt +++ b/plugins/base/src/main/kotlin/renderers/html/NavigationDataProvider.kt @@ -73,18 +73,28 @@ abstract class NavigationDataProvider { } private fun ContentPage.navigableChildren(): List { - return if (this !is ClasslikePageNode) { + return if (this is ClasslikePage) { + return this.navigableChildren() + } else { children .filterIsInstance() .map { visit(it) } .sortedBy { it.name.toLowerCase() } - } else if (documentables.any { it is DEnum }) { - // no sorting for enum entries, should be the same as in source code - children - .filter { child -> child is WithDocumentables && child.documentables.any { it is DEnumEntry } } - .map { visit(it as ContentPage) } + } + } + + private fun ClasslikePage.navigableChildren(): List { + // Classlikes should only have other classlikes as navigable children + val navigableChildren = children + .filterIsInstance() + .map { visit(it) } + + val isEnumPage = documentables.any { it is DEnum } + return if (isEnumPage) { + // no sorting for enum entries, should be the same order as in source code + navigableChildren } else { - emptyList() + navigableChildren.sortedBy { it.name.toLowerCase() } } } } diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt index e5183699..87808add 100644 --- a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt +++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt @@ -49,8 +49,7 @@ class NavigationPage( } } buildLink(node.dri, node.sourceSets.toList()) { - // special condition for Enums as it has children enum entries in navigation - val withIcon = node.icon != null && (node.children.isEmpty() || node.isEnum()) + val withIcon = node.icon != null if (withIcon) { // in case link text is so long that it needs to have word breaks, // and it stretches to two or more lines, make sure the icon @@ -69,10 +68,6 @@ class NavigationPage( node.children.withIndex().forEach { (n, p) -> visit(p, "$navId-$n", renderer) } } } - - private fun NavigationNode.isEnum(): Boolean { - return icon == NavigationNodeIcon.ENUM_CLASS || icon == NavigationNodeIcon.ENUM_CLASS_KT - } } data class NavigationNode( -- cgit