New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a distinct divider between function overloads #2585
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
plugins/base/src/main/kotlin/renderers/html/HtmlContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
Comment on lines
-775
to
-777
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused |
||
|
||
open fun buildHtml(page: PageNode, resources: List<String>, content: FlowContent.() -> Unit): String = | ||
templater.renderFromTemplate(DokkaTemplateTypes.BASE) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This made
buildDivergent
considerably longer, even though this particular function needed no context from it and shared nothing in common, so I don't see a reason why it has to be a nested function.Extracted for the sake of readability of
buildDivergent