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 --- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 39 +++++++++++++++------- .../documentables/DefaultPageCreator.kt | 39 +++++++++++++--------- .../documentables/PageContentBuilder.kt | 17 ++++++++++ .../documentables/briefFromContentNodes.kt | 26 +++++++++++++++ .../base/src/main/resources/dokka/styles/style.css | 21 +++++++----- 5 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 plugins/base/src/main/kotlin/translators/documentables/briefFromContentNodes.kt (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 22fb3e63..0118dcfd 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -386,23 +386,31 @@ open class HtmlRenderer( it.build(this, pageContext, sourceSetRestriction) buildAnchor(anchorName) } - if (ContentKind.shouldBePlatformTagged(node.dci.kind) && (node.sourceSets.size == 1)) + if (ContentKind.shouldBePlatformTagged(node.dci.kind) && (node.sourceSets.size == 1 || pageContext is ModulePage)) createPlatformTags(node) } } } it.filter { it !is ContentLink }.takeIf { it.isNotEmpty() }?.let { - div("platform-dependent-row keyValue") { - val title = it.filter { it.style.contains(ContentStyle.RowTitle) } - div { - title.forEach { + if(pageContext is ModulePage){ + it.forEach { + span(classes = if(it.dci.kind == ContentKind.Comment) "brief-comment" else "") { it.build(this, pageContext, sourceSetRestriction) } } - div("title") { - (it - title).forEach { - it.build(this, pageContext, sourceSetRestriction) + } else { + div("platform-dependent-row keyValue") { + val title = it.filter { it.style.contains(ContentStyle.RowTitle) } + div { + title.forEach { + it.build(this, pageContext, sourceSetRestriction) + } + } + div("title") { + (it - title).forEach { + it.build(this, pageContext, sourceSetRestriction) + } } } } @@ -513,13 +521,20 @@ open class HtmlRenderer( override fun FlowContent.buildNavigation(page: PageNode) = div(classes = "breadcrumbs") { - locationProvider.ancestors(page).asReversed().forEach { node -> - text("/") - if (node.isNavigable) buildLink(node, page) - else text(node.name) + val path = locationProvider.ancestors(page).filterNot { it is RendererSpecificPage }.asReversed() + if(path.isNotEmpty()){ + buildNavigationElement(path.first(), page) + path.drop(1).forEach { node -> + text("/") + buildNavigationElement(node, page) + } } } + private fun FlowContent.buildNavigationElement(node: PageNode, page: PageNode) = + if (node.isNavigable) buildLink(node, page) + else text(node.name) + private fun FlowContent.buildLink(to: PageNode, from: PageNode) = locationProvider.resolve(to, from)?.let { path -> buildLink(path) { 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