diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2022-08-05 13:25:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-05 13:25:55 +0200 |
commit | efed96e969d8f5afe21197805851aca65ceb643a (patch) | |
tree | a848d331d8db45393452c704ccaf17e704b062eb /plugins/base/src | |
parent | 7b020f000aa7ea868d5d3037e68eaec621ef9972 (diff) | |
download | dokka-efed96e969d8f5afe21197805851aca65ceb643a.tar.gz dokka-efed96e969d8f5afe21197805851aca65ceb643a.tar.bz2 dokka-efed96e969d8f5afe21197805851aca65ceb643a.zip |
Add a distinct divider between function/property overloads (#2585)
Diffstat (limited to 'plugins/base/src')
5 files changed, 72 insertions, 30 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 2a21337f..d773650c 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -36,6 +36,8 @@ abstract class DefaultRenderer<T>( ) abstract fun T.buildLineBreak() + open fun T.buildLineBreak(node: ContentBreakLine, pageContext: ContentPage) = buildLineBreak() + abstract fun T.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) abstract fun T.buildTable( node: ContentTable, @@ -116,7 +118,7 @@ abstract class DefaultRenderer<T>( is ContentList -> buildList(node, pageContext, sourceSetRestriction) is ContentTable -> buildTable(node, pageContext, sourceSetRestriction) is ContentGroup -> buildGroup(node, pageContext, sourceSetRestriction) - is ContentBreakLine -> buildLineBreak() + is ContentBreakLine -> buildLineBreak(node, pageContext) is PlatformHintedContent -> buildPlatformDependent(node, pageContext, sourceSetRestriction) is ContentDivergentGroup -> buildDivergent(node, pageContext) is ContentDivergentInstance -> buildDivergentInstance(node, pageContext) @@ -233,4 +235,4 @@ abstract class DefaultRenderer<T>( internal typealias SerializedBeforeAndAfter = Pair<String, String> internal typealias InstanceWithSource = Pair<ContentDivergentInstance, DisplaySourceSet> -fun ContentPage.sourceSets() = this.content.sourceSets
\ No newline at end of file +fun ContentPage.sourceSets() = this.content.sourceSets diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlContent.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlContent.kt new file mode 100644 index 00000000..a55323f9 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlContent.kt @@ -0,0 +1,14 @@ +package org.jetbrains.dokka.base.renderers.html + +import org.jetbrains.dokka.pages.ContentBreakLine +import org.jetbrains.dokka.pages.Style + + +/** + * Html-specific style that represents <hr> tag if used in conjunction with [ContentBreakLine] + */ +internal object HorizontalBreakLineStyle : Style { + // this exists as a simple internal solution to avoid introducing unnecessary public API on content level. + // If you have the need to implement proper horizontal divider (i.e to support `---` markdown element), + // consider removing this and providing proper API for all formats and levels +} diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 5d2007d6..53645f06 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -14,16 +14,13 @@ import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider import org.jetbrains.dokka.base.templating.* import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.model.DisplaySourceSet +import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.model.sourceSetIDs -import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.pages.HtmlContent import org.jetbrains.dokka.plugability.* import org.jetbrains.dokka.utilities.htmlEscape import org.jetbrains.kotlin.utils.addIfNotNull -import java.net.URI internal const val TEMPLATE_REPLACEMENT: String = "###" @@ -252,23 +249,6 @@ open class HtmlRenderer( } override fun FlowContent.buildDivergent(node: ContentDivergentGroup, pageContext: ContentPage) { - fun groupDivergentInstancesWithSourceSet( - instances: List<ContentDivergentInstance>, - sourceSet: DisplaySourceSet, - pageContext: ContentPage, - beforeTransformer: (ContentDivergentInstance, ContentPage, DisplaySourceSet) -> String, - afterTransformer: (ContentDivergentInstance, ContentPage, DisplaySourceSet) -> String - ): Map<SerializedBeforeAndAfter, List<ContentDivergentInstance>> = - instances.map { instance -> - instance to Pair( - beforeTransformer(instance, pageContext, sourceSet), - afterTransformer(instance, pageContext, sourceSet) - ) - }.groupBy( - Pair<ContentDivergentInstance, SerializedBeforeAndAfter>::second, - Pair<ContentDivergentInstance, SerializedBeforeAndAfter>::first - ) - if (node.implicitlySourceSetHinted) { val groupedInstancesBySourceSet = node.children.flatMap { instance -> instance.sourceSets.map { sourceSet -> instance to sourceSet } @@ -294,16 +274,28 @@ open class HtmlRenderer( } }.stripDiv() }) + + val isPageWithOverloadedMembers = pageContext is MemberPage && pageContext.documentables().size > 1 + val contentOfSourceSet = mutableListOf<ContentNode>() - distinct.onEachIndexed{ i, (_, distinctInstances) -> + distinct.onEachIndexed{ index, (_, distinctInstances) -> contentOfSourceSet.addIfNotNull(distinctInstances.firstOrNull()?.before) contentOfSourceSet.addAll(distinctInstances.map { it.divergent }) contentOfSourceSet.addIfNotNull( distinctInstances.firstOrNull()?.after - ?: if (i != distinct.size - 1) ContentBreakLine(it.key) else null + ?: if (index != distinct.size - 1) ContentBreakLine(it.key) else null ) - if(node.dci.kind == ContentKind.Main && i != distinct.size - 1) - contentOfSourceSet.add(ContentBreakLine(it.key)) + + // content kind main is important for declarations list to avoid double line breaks + if (node.dci.kind == ContentKind.Main && index != distinct.size - 1) { + if (isPageWithOverloadedMembers) { + // add some spacing and distinction between function/property overloads. + // not ideal, but there's no other place to modify overloads page atm + contentOfSourceSet.add(ContentBreakLine(it.key, style = setOf(HorizontalBreakLineStyle))) + } else { + contentOfSourceSet.add(ContentBreakLine(it.key)) + } + } } contentOfSourceSet } @@ -315,6 +307,27 @@ open class HtmlRenderer( } } + private fun groupDivergentInstancesWithSourceSet( + instances: List<ContentDivergentInstance>, + sourceSet: DisplaySourceSet, + pageContext: ContentPage, + beforeTransformer: (ContentDivergentInstance, ContentPage, DisplaySourceSet) -> String, + afterTransformer: (ContentDivergentInstance, ContentPage, DisplaySourceSet) -> String + ): Map<SerializedBeforeAndAfter, List<ContentDivergentInstance>> = + instances.map { instance -> + instance to Pair( + beforeTransformer(instance, pageContext, sourceSet), + afterTransformer(instance, pageContext, sourceSet) + ) + }.groupBy( + Pair<ContentDivergentInstance, SerializedBeforeAndAfter>::second, + Pair<ContentDivergentInstance, SerializedBeforeAndAfter>::first + ) + + private fun ContentPage.documentables(): List<Documentable> { + return (this as? WithDocumentables)?.documentables ?: emptyList() + } + override fun FlowContent.buildList( node: ContentList, pageContext: ContentPage, @@ -672,6 +685,13 @@ open class HtmlRenderer( override fun buildError(node: ContentNode) = context.logger.error("Unknown ContentNode type: $node") override fun FlowContent.buildLineBreak() = br() + override fun FlowContent.buildLineBreak(node: ContentBreakLine, pageContext: ContentPage) { + if (node.style.contains(HorizontalBreakLineStyle)) { + hr() + } else { + buildLineBreak() + } + } override fun FlowContent.buildLink(address: String, content: FlowContent.() -> Unit) = a(href = address, block = content) @@ -772,9 +792,6 @@ open class HtmlRenderer( content(this, page) } - private val String.isAbsolute: Boolean - get() = URI(this).isAbsolute - open fun buildHtml(page: PageNode, resources: List<String>, content: FlowContent.() -> Unit): String = templater.renderFromTemplate(DokkaTemplateTypes.BASE) { diff --git a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt index 6c12c719..003d68cf 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt @@ -6,6 +6,10 @@ import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.utilities.DokkaLogger +/** + * Merges [MemberPage] elements that have the same name. + * That includes **both** properties and functions. + */ class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStrategy { override fun tryMerge(pages: List<PageNode>, path: List<String>): List<PageNode> { val members = pages.filterIsInstance<MemberPageNode>().takeIf { it.isNotEmpty() } ?: return pages diff --git a/plugins/base/src/main/resources/dokka/styles/style.css b/plugins/base/src/main/resources/dokka/styles/style.css index 50125756..989b54b8 100644 --- a/plugins/base/src/main/resources/dokka/styles/style.css +++ b/plugins/base/src/main/resources/dokka/styles/style.css @@ -115,6 +115,11 @@ html ::-webkit-scrollbar-thumb { margin-right: var(--horizontal-spacing-for-content); } +.main-content .content > hr { + margin: 30px 0; + border-top: 3px double #8c8b8b; +} + .navigation-wrapper { display: flex; flex-wrap: wrap; |