diff options
author | Marcin Aman <maman@virtuslab.com> | 2020-08-20 19:00:04 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-08-25 17:49:30 +0200 |
commit | c9af371aa18dc50490dc3927ed88dfe8836c1bde (patch) | |
tree | 6b974aa9be26d9e3544327d17722d8f26e14cd4d /plugins/base/src/main/kotlin/translators | |
parent | 7196323582dce7ca3f9b07262a1f94ecd8514539 (diff) | |
download | dokka-c9af371aa18dc50490dc3927ed88dfe8836c1bde.tar.gz dokka-c9af371aa18dc50490dc3927ed88dfe8836c1bde.tar.bz2 dokka-c9af371aa18dc50490dc3927ed88dfe8836c1bde.zip |
Improve styles and functionality on module page #1336
Diffstat (limited to 'plugins/base/src/main/kotlin/translators')
3 files changed, 67 insertions, 15 deletions
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<ContentNode> { - 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<Description>() - 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<ContentNode> { - 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<Documentable>.sourceSets: Set<DokkaSourceSet> 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<Description> + get() = groupedTags.withTypeUnnamed<Description>() } 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<DokkaSourceSet> = mainSourcesetData, + styles: Set<Style> = mainStyles, + extra: PropertyContainer<ContentNode> = mainExtra + ){ + val builtDescription = commentsConverter.buildContent( + content.root, + DCI(mainDRI, kind), + sourceSets + ) + + contents += ContentGroup(briefFromContentNodes(builtDescription), DCI(mainDRI, kind), sourceSets.toDisplaySourceSets(), styles, extra) + } + fun group( dri: Set<DRI> = mainDRI, sourceSets: Set<DokkaSourceSet> = mainSourcesetData, diff --git a/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt b/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt new file mode 100644 index 00000000..9fe128dd --- /dev/null +++ b/plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt @@ -0,0 +1,26 @@ +package org.jetbrains.dokka.base.translators.documentables + +import org.jetbrains.dokka.pages.ContentGroup +import org.jetbrains.dokka.pages.ContentNode +import org.jetbrains.dokka.pages.ContentText +import org.jetbrains.dokka.pages.TextStyle + +fun briefFromContentNodes(description: List<ContentNode>): List<ContentNode> { + val firstSentenceRegex = Regex("^((?:[^.?!]|[.!?](?!\\s))*[.!?])") + + var sentenceFound = false + fun lookthrough(node: ContentNode): ContentNode = + if (node is ContentText && firstSentenceRegex.containsMatchIn(node.text)) { + sentenceFound = true + node.copy(text = firstSentenceRegex.find(node.text)?.value.orEmpty()) + } else if (node is ContentGroup) { + node.copy(children = node.children.mapNotNull { + if (!sentenceFound) lookthrough(it) else null + }, style = node.style - TextStyle.Paragraph) + } else { + node + } + return description.mapNotNull { + if (!sentenceFound) lookthrough(it) else null + } +}
\ No newline at end of file |