diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-07-10 15:20:13 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-07-10 18:02:29 +0200 |
commit | 43957996a2c530d7c22e00d841af9ad349cbf70a (patch) | |
tree | 4c8a267fec26eff8cca2cf7e66371e368b55deea | |
parent | 205c451cdbe238bb8c5841418ab1a7d68410e117 (diff) | |
download | dokka-43957996a2c530d7c22e00d841af9ad349cbf70a.tar.gz dokka-43957996a2c530d7c22e00d841af9ad349cbf70a.tar.bz2 dokka-43957996a2c530d7c22e00d841af9ad349cbf70a.zip |
Fix rendering of classlikes on packages page
6 files changed, 107 insertions, 31 deletions
diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index 1bafa111..b1549729 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -9,13 +9,13 @@ import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentCon import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.Description -import org.jetbrains.dokka.model.doc.NamedTagWrapper import org.jetbrains.dokka.model.doc.Param import org.jetbrains.dokka.model.doc.TagWrapper import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.utilities.DokkaLogger +import kotlin.reflect.KClass open class JavadocPageCreator( commentsToContentConverter: CommentsToContentConverter, @@ -71,12 +71,16 @@ open class JavadocPageCreator( m.jvmSourceSets.toSet() ) { title(m.name, m.brief(), "0.0.1", dri = setOf(m.dri), kind = ContentKind.Main) - list("Packages", "Package", setOf(m.dri), ContentKind.Packages, m.packages.sortedBy { it.name }.map { p -> - RowJavadocListEntry( - LinkJavadocListEntry(p.name, setOf(p.dri), JavadocContentKind.PackageSummary, sourceSets), - p.brief() - ) - }) + leafList(setOf(m.dri), + ContentKind.Packages, JavadocList( + "Packages", "Package", + m.packages.sortedBy { it.name }.map { p -> + RowJavadocListEntry( + LinkJavadocListEntry(p.name, setOf(p.dri), JavadocContentKind.PackageSummary, sourceSets), + p.brief() + ) + } + )) } private fun contentForPackage(p: DPackage): JavadocContentNode = @@ -86,14 +90,30 @@ open class JavadocPageCreator( p.jvmSourceSets.toSet() ) { title(p.name, p.brief(), "0.0.1", dri = setOf(p.dri), kind = ContentKind.Packages) - list("Packages", "Package", setOf(p.dri), ContentKind.Packages, p.classlikes.sortedBy { it.name }.map { c -> - RowJavadocListEntry( - LinkJavadocListEntry(c.name.orEmpty(), setOf(c.dri), JavadocContentKind.Class, sourceSets), - c.brief() - ) - }) + val rootList = p.classlikes.groupBy { it::class }.map { (key, value) -> + JavadocList(key.tabTitle, key.colTitle, value.map { c -> + RowJavadocListEntry( + LinkJavadocListEntry(c.name ?: "", setOf(c.dri), JavadocContentKind.Class, sourceSets), + c.brief() + ) + }) + } + rootList(setOf(p.dri), JavadocContentKind.Class, rootList) } + private val KClass<out DClasslike>.colTitle: String + get() = when(this) { + DClass::class -> "Class" + DObject::class -> "Object" + DAnnotation::class -> "Annotation" + DEnum::class -> "Enum" + DInterface::class -> "Interface" + else -> "" + } + + private val KClass<out DClasslike>.tabTitle: String + get() = colTitle + if(colTitle.last() != 's') "s" else "es" + private fun contentForClasslike(c: DClasslike): JavadocContentNode = JavadocContentGroup( setOf(c.dri), @@ -181,7 +201,8 @@ open class JavadocPageCreator( briefFromContentNodes(paramsToContentNodes(sourceSet).dropWhile { it is ContentDRILink }) private fun ContentNode.asJavadocNode(): JavadocSignatureContentNode = - (this as ContentGroup).firstChildOfTypeOrNull<JavadocSignatureContentNode>() ?: throw IllegalStateException("No content for javadoc signature found") + (this as ContentGroup).firstChildOfTypeOrNull<JavadocSignatureContentNode>() + ?: throw IllegalStateException("No content for javadoc signature found") private fun signatureForNode(documentable: Documentable, sourceSet: DokkaSourceSet): JavadocSignatureContentNode = signatureProvider.signature(documentable).nodeForJvm(sourceSet).asJavadocNode() diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt index 5e24ce9e..d83704a6 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt @@ -20,6 +20,12 @@ abstract class JavadocContentNode( override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = this } +interface JavadocList { + val tabTitle: String + val colTitle: String + val children: List<JavadocListEntry> +} + interface JavadocListEntry { val stringTag: String } @@ -86,7 +92,16 @@ fun JavaContentGroupBuilder.title( list.add(TitleNode(title, subtitle, version, parent, dri, kind, sourceSets)) } -class ListNode( +class RootListNode( + val entries: List<LeafListNode>, + val dri: Set<DRI>, + val kind: Kind, + sourceSets: Set<DokkaSourceSet>, +) : JavadocContentNode(dri, kind, sourceSets) { + override fun hasAnyContent(): Boolean = children.isNotEmpty() +} + +class LeafListNode( val tabTitle: String, val colTitle: String, val entries: List<JavadocListEntry>, @@ -97,16 +112,31 @@ class ListNode( override fun hasAnyContent(): Boolean = children.isNotEmpty() } -fun JavaContentGroupBuilder.list( - tabTitle: String, - colTitle: String, + +fun JavaContentGroupBuilder.rootList( + dri: Set<DRI>, + kind: Kind, + rootList: List<JavadocList> +) { + val children = rootList.map { + LeafListNode(it.tabTitle, it.colTitle, it.children, dri, kind, sourceSets) + } + list.add(RootListNode(children, dri, kind, sourceSets)) +} + +fun JavaContentGroupBuilder.leafList( dri: Set<DRI>, kind: Kind, - children: List<JavadocListEntry> + leafList: JavadocList ) { - list.add(ListNode(tabTitle, colTitle, children, dri, kind, sourceSets)) + list.add(LeafListNode(leafList.tabTitle, leafList.colTitle, leafList.children, dri, kind, sourceSets)) } +fun JavadocList(tabTitle: String, colTitle: String, children: List<JavadocListEntry>) = object : JavadocList { + override val tabTitle = tabTitle + override val colTitle = colTitle + override val children = children +} class LinkJavadocListEntry( val name: String, diff --git a/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt b/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt index 760647fa..0c952fe9 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt @@ -114,7 +114,8 @@ internal class JavadocContentToTemplateMapTranslator( when (node) { is TitleNode -> templateMapForTitleNode(node) is JavadocContentGroup -> templateMapForJavadocContentGroup(node) - is ListNode -> templateMapForListNode(node) + is LeafListNode -> templateMapForLeafListNode(node) + is RootListNode -> templateMapForRootListNode(node) else -> emptyMap() } @@ -195,7 +196,7 @@ internal class JavadocContentToTemplateMapTranslator( } } - private fun templateMapForListNode(node: ListNode): TemplateMap { + private fun templateMapForLeafListNode(node: LeafListNode): TemplateMap { return mapOf( "tabTitle" to node.tabTitle, "colTitle" to node.colTitle, @@ -203,6 +204,12 @@ internal class JavadocContentToTemplateMapTranslator( ) } + private fun templateMapForRootListNode(node: RootListNode): TemplateMap { + return mapOf( + "lists" to node.entries.map { templateMapForLeafListNode(it) } + ) + } + private fun renderInlineParameter(parameter: JavadocParameterNode): String = htmlForContentNode(parameter.type, contextNode) + " ${parameter.name}" diff --git a/plugins/javadoc/src/main/resources/views/components/indexPage.korte b/plugins/javadoc/src/main/resources/views/components/indexPage.korte index 02b94b75..d22b89ea 100644 --- a/plugins/javadoc/src/main/resources/views/components/indexPage.korte +++ b/plugins/javadoc/src/main/resources/views/components/indexPage.korte @@ -9,8 +9,22 @@ <p>See: <a href="#overview_description">Description</a></p> </div> <div class="contentContainer"> - <div class="overviewSummary"> - {% include "components/indexTable.korte" %} - </div> + {% if lists %} + <ul class="blockList"> + {% for item in lists%} + <li class="blockList"> + {% set list = item.list %} + {% set colTitle = item.colTitle %} + {% set tabTitle = item.tabTitle %} + {% set isTypeSummary = "true" %} + {% include "components/indexTable.korte" %} + </li> + {% endfor %} + </ul> + {% else %} + <div class="overviewSummary"> + {% include "components/indexTable.korte" %} + </div> + {% endif %} </div> </main>
\ No newline at end of file diff --git a/plugins/javadoc/src/main/resources/views/components/indexTable.korte b/plugins/javadoc/src/main/resources/views/components/indexTable.korte index 9ee387e1..e1b507b9 100644 --- a/plugins/javadoc/src/main/resources/views/components/indexTable.korte +++ b/plugins/javadoc/src/main/resources/views/components/indexTable.korte @@ -1,4 +1,8 @@ -<table> +{% if isTypeSummary %} + <table class="typeSummary"> +{% else %} + <table> +{% endif %} <caption><span>{{ tabTitle }}</span><span class="tabEnd"> </span></caption> <tr> <th class="colFirst" scope="col">{{ colTitle }}</th> diff --git a/plugins/javadoc/src/test/kotlin/javadoc/JavadocPackageTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/JavadocPackageTemplateMapTest.kt index bb53a571..a1b99ba0 100644 --- a/plugins/javadoc/src/test/kotlin/javadoc/JavadocPackageTemplateMapTest.kt +++ b/plugins/javadoc/src/test/kotlin/javadoc/JavadocPackageTemplateMapTest.kt @@ -28,13 +28,13 @@ internal class JavadocPackageTemplateMapTest : AbstractJavadocTemplateMapTest() """ ) { val map = singlePageOfType<JavadocPackagePageNode>().templateMap - assertEquals("Packages", map["tabTitle"]) - assertEquals("Package", map["colTitle"]) + assertEquals("Classes", ((map["lists"] as List<*>).first() as Map<String, *>)["tabTitle"]) + assertEquals("Class", ((map["lists"] as List<*>).first() as Map<String, *>)["colTitle"]) assertEquals("com.test.package0", map["title"]) assertEquals("", map["subtitle"]) assertEquals("package", map["kind"]) - val list = assertIsInstance<List<*>>(map["list"]) + val list = assertIsInstance<List<*>>(((map["lists"] as List<*>).first() as Map<String, *>)["list"]) val entry = assertIsInstance<RowJavadocListEntry>(list.single()) assertEquals("Test", entry.link.name) assertEquals(JavadocContentKind.Class, entry.link.kind) @@ -69,8 +69,8 @@ internal class JavadocPackageTemplateMapTest : AbstractJavadocTemplateMapTest() val packagePages = allPagesOfType<JavadocPackagePageNode>() packagePages.forEach { page -> val map = page.templateMap - assertEquals("Packages", map["tabTitle"]) - assertEquals("Package", map["colTitle"]) + assertEquals("Classes", ((map["lists"] as List<*>).first() as Map<String, *>)["tabTitle"]) + assertEquals("Class", ((map["lists"] as List<*>).first() as Map<String, *>)["colTitle"]) assertEquals("", map["subtitle"]) assertEquals("package", map["kind"]) } |