aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers/html
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2020-05-05 11:53:16 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-19 09:56:32 +0200
commit430d7d6453a0b63dcabecd54aea915410cd35103 (patch)
treeb9e40e3eaa9f1948590141d7d46491e2f34f2ef9 /plugins/base/src/main/kotlin/renderers/html
parentc1b4669ee227a479516f37ce1b9dff5f2d2bef38 (diff)
downloaddokka-430d7d6453a0b63dcabecd54aea915410cd35103.tar.gz
dokka-430d7d6453a0b63dcabecd54aea915410cd35103.tar.bz2
dokka-430d7d6453a0b63dcabecd54aea915410cd35103.zip
Add a draft version of divergent rendering
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt95
1 files changed, 83 insertions, 12 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index caabcda7..97f0bdbd 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -40,14 +40,40 @@ open class HtmlRenderer(
}
}
- override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) {
+ private fun FlowContent.wrapPlatformTagged(
+ node: ContentGroup,
+ pageContext: ContentPage,
+ childrenCallback: FlowContent.() -> Unit
+ ) {
+ div("platform-tagged") {
+ node.sourceSets.forEach {
+ div("platform-tag") {
+ if (it.sourceSetName.equals("common", ignoreCase = true)) classes = classes + "common"
+ text(it.sourceSetName)
+ }
+ }
+ div("content") {
+ childrenCallback()
+ }
+ }
+ }
+
+ override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) =
+ buildPlatformDependent(content.sourceSets.map { it to setOf(content.inner) }.toMap(), pageContext)
+
+ private fun FlowContent.buildPlatformDependent(
+ nodes: Map<SourceSetData, Collection<ContentNode>>,
+ pageContext: ContentPage
+ ) {
div("platform-hinted") {
attributes["data-platform-hinted"] = "data-platform-hinted"
- val contents = content.sourceSets.mapIndexed { index, platform ->
- platform to createHTML(prettyPrint = false).div(classes = "content") {
+ val contents = nodes.toList().mapIndexed { index, (sourceSet, elements) ->
+ sourceSet to createHTML(prettyPrint = false).div(classes = "content") {
if (index == 0) attributes["data-active"] = ""
- attributes["data-togglable"] = platform.sourceSetName
- buildContentNode(content.inner, pageContext, platform)
+ attributes["data-togglable"] = sourceSet.sourceSetName
+ elements.forEach {
+ buildContentNode(it, pageContext, setOf(sourceSet))
+ }
}
}
@@ -69,17 +95,61 @@ open class HtmlRenderer(
}
}
+ override fun FlowContent.buildDivergent(node: ContentDivergentGroup, pageContext: ContentPage) {
+ val distinct =
+ node.children.map { instance ->
+ instance to Pair(
+ createHTML(prettyPrint = false).div {
+ instance.before?.let { before ->
+ buildContentNode(before, pageContext, instance.sourceSets)
+ }
+ }.drop(5).dropLast(6),
+ createHTML(prettyPrint = false).div {
+ instance.after?.let { after ->
+ buildContentNode(after, pageContext, instance.sourceSets)
+ }
+ }.drop(5).dropLast(6) // TODO: Find a way to do it without arbitrary trims
+ )
+
+ }.groupBy(
+ Pair<ContentDivergentInstance, Pair<String, String>>::second,
+ Pair<ContentDivergentInstance, Pair<String, String>>::first
+ )
+
+ distinct.forEach {
+ consumer.onTagContentUnsafe { +it.key.first }
+ consumer.onTagContentUnsafe {
+ +createHTML(prettyPrint = false).div {
+ if (node.implicitlySourceSetHinted) {
+ buildPlatformDependent(
+ it.value.groupBy { it.sourceSets }
+ .flatMap { (sourceSets, elements) ->
+ sourceSets.map { sourceSet -> sourceSet to elements.map { e -> e.divergent } }
+ }.toMap(),
+ pageContext
+ )
+ } else {
+ it.value.forEach {
+ buildContentNode(it.divergent, pageContext, null)
+ }
+ }
+ }.drop(5).dropLast(6)
+ }
+ consumer.onTagContentUnsafe { +it.key.second }
+ }
+ }
+
override fun FlowContent.buildList(
node: ContentList,
pageContext: ContentPage,
- sourceSetRestriction: SourceSetData?
+ sourceSetRestriction: Set<SourceSetData>?
) = if (node.ordered) ol { buildListItems(node.children, pageContext, sourceSetRestriction) }
else ul { buildListItems(node.children, pageContext, sourceSetRestriction) }
open fun OL.buildListItems(
items: List<ContentNode>,
pageContext: ContentPage,
- sourceSetRestriction: SourceSetData? = null
+ sourceSetRestriction: Set<SourceSetData>? = null
) {
items.forEach {
if (it is ContentList)
@@ -92,7 +162,7 @@ open class HtmlRenderer(
open fun UL.buildListItems(
items: List<ContentNode>,
pageContext: ContentPage,
- sourceSetRestriction: SourceSetData? = null
+ sourceSetRestriction: Set<SourceSetData>? = null
) {
items.forEach {
if (it is ContentList)
@@ -119,18 +189,18 @@ open class HtmlRenderer(
private fun FlowContent.buildRow(
node: ContentGroup,
pageContext: ContentPage,
- sourceSetRestriction: SourceSetData?
+ sourceSetRestriction: Set<SourceSetData>?
) {
node.children
.filter {
- sourceSetRestriction == null || sourceSetRestriction in it.sourceSets
+ sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction }
}
.takeIf { it.isNotEmpty() }
?.let {
div(classes = "table-row") {
it.filter { it.dci.kind != ContentKind.Symbol }.takeIf { it.isNotEmpty() }?.let {
div("main-subrow ${node.style.joinToString { it.toString().decapitalize() }}") {
- it.filter { sourceSetRestriction == null || sourceSetRestriction in it.sourceSets }
+ it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
.forEach {
when(it.dci.kind){
ContentKind.SourceSetDependantHint -> {
@@ -170,6 +240,7 @@ open class HtmlRenderer(
}
}
+
private fun FlowContent.createPlatformTags(node: ContentNode) {
div("platform-tags") {
node.sourceSets.forEach {
@@ -184,7 +255,7 @@ open class HtmlRenderer(
override fun FlowContent.buildTable(
node: ContentTable,
pageContext: ContentPage,
- sourceSetRestriction: SourceSetData?
+ sourceSetRestriction: Set<SourceSetData>?
) {
div(classes = "table") {
node.children.forEach {