From c9af371aa18dc50490dc3927ed88dfe8836c1bde Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 20 Aug 2020 19:00:04 +0200 Subject: Improve styles and functionality on module page #1336 --- .../documentables/DefaultPageCreator.kt | 39 +++++++++++++--------- .../documentables/PageContentBuilder.kt | 17 ++++++++++ .../documentables/briefFromContentNodes.kt | 26 +++++++++++++++ 3 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt (limited to 'plugins/base/src/main/kotlin/translators') diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 3f3e157e..30f35003 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -83,11 +83,18 @@ open class DefaultPageCreator( } } +contentForComments(m) + block("Packages", 2, ContentKind.Packages, m.packages, m.sourceSets.toSet()) { + val documentations = it.sourceSets.map { platform -> + it.descriptions[platform]?.also { it.root } + } + val haveSameContent = documentations.all { it?.root == documentations.firstOrNull()?.root && it?.root != null } + link(it.name, it.dri) + if(it.sourceSets.size == 1 || (documentations.isNotEmpty() && haveSameContent)){ + documentations.first()?.let { firstSentenceComment(kind = ContentKind.Comment, content = it) } + } } -// text("Index\n") TODO -// text("Link to allpage here") } protected open fun contentForPackage(p: DPackage) = contentBuilder.contentFor(p) { @@ -261,18 +268,15 @@ open class DefaultPageCreator( protected open fun contentForDescription( d: Documentable ): List { - val tags: GroupedTags = d.documentation.flatMap { (pd, doc) -> - doc.children.asSequence().map { pd to it }.toList() - }.groupBy { it.second::class } - + val tags: GroupedTags = d.groupedTags val platforms = d.sourceSets.toSet() return contentBuilder.contentFor(d, styles = setOf(TextStyle.Block)) { - val description = tags.withTypeUnnamed() - if (description.any { it.value.root.children.isNotEmpty() }) { + val descriptions = d.descriptions + if (descriptions.any { it.value.root.children.isNotEmpty() }) { platforms.forEach { platform -> - description[platform]?.also { - group(sourceSets = setOf(platform)) { + descriptions[platform]?.also { + group(sourceSets = setOf(platform), styles = emptySet()) { comment(it.root) } } @@ -286,7 +290,7 @@ open class DefaultPageCreator( platforms.forEach { platform -> unnamedTags.forEach { pdTag -> pdTag[platform]?.also { tag -> - group(sourceSets = setOf(platform)) { + group(sourceSets = setOf(platform), styles = emptySet()) { header(4, tag.toHeaderString()) comment(tag.root) } @@ -308,10 +312,7 @@ open class DefaultPageCreator( protected open fun contentForComments( d: Documentable ): List { - val tags: GroupedTags = d.documentation.flatMap { (pd, doc) -> - doc.children.asSequence().map { pd to it }.toList() - }.groupBy { it.second::class } - + val tags = d.groupedTags val platforms = d.sourceSets fun DocumentableContentBuilder.contentForParams() { @@ -522,4 +523,12 @@ open class DefaultPageCreator( private val List.sourceSets: Set get() = flatMap { it.sourceSets }.toSet() + + private val Documentable.groupedTags: GroupedTags + get() = documentation.flatMap { (pd, doc) -> + doc.children.asSequence().map { pd to it }.toList() + }.groupBy { it.second::class } + + private val Documentable.descriptions: SourceSetDependent + get() = groupedTags.withTypeUnnamed() } diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index a1f3c002..42700f20 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -7,6 +7,7 @@ import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentCon import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.SourceSetDependent +import org.jetbrains.dokka.model.doc.Description import org.jetbrains.dokka.model.doc.DocTag import org.jetbrains.dokka.model.properties.PropertyContainer import org.jetbrains.dokka.model.toDisplaySourceSets @@ -287,6 +288,22 @@ open class PageContentBuilder( contents += ContentGroup(content, DCI(mainDRI, kind), sourceSets.toDisplaySourceSets(), styles, extra) } + fun firstSentenceComment( + content: Description, + kind: Kind = ContentKind.Comment, + sourceSets: Set = mainSourcesetData, + styles: Set