diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-05-05 11:53:16 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-05-19 09:56:32 +0200 |
commit | 430d7d6453a0b63dcabecd54aea915410cd35103 (patch) | |
tree | b9e40e3eaa9f1948590141d7d46491e2f34f2ef9 /core/src/main/kotlin/pages | |
parent | c1b4669ee227a479516f37ce1b9dff5f2d2bef38 (diff) | |
download | dokka-430d7d6453a0b63dcabecd54aea915410cd35103.tar.gz dokka-430d7d6453a0b63dcabecd54aea915410cd35103.tar.bz2 dokka-430d7d6453a0b63dcabecd54aea915410cd35103.zip |
Add a draft version of divergent rendering
Diffstat (limited to 'core/src/main/kotlin/pages')
-rw-r--r-- | core/src/main/kotlin/pages/ContentNodes.kt | 42 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/utils.kt | 30 |
2 files changed, 68 insertions, 4 deletions
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt index bb669199..e7f027e3 100644 --- a/core/src/main/kotlin/pages/ContentNodes.kt +++ b/core/src/main/kotlin/pages/ContentNodes.kt @@ -90,7 +90,7 @@ data class ContentResolvedLink( copy(extra = newExtras) } -/** All links that do not need to be resolved */ +/** Embedded resources like images */ data class ContentEmbeddedResource( override val children: List<ContentNode> = emptyList(), val address: String, @@ -144,6 +144,43 @@ data class ContentGroup( override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentGroup = copy(extra = newExtras) } +/** + * @property groupName is used for finding and copying [ContentDivergentInstance]s when merging [ContentPage]s + */ +data class ContentDivergentGroup( + override val children: List<ContentDivergentInstance>, + override val dci: DCI, + override val style: Set<Style>, + override val extra: PropertyContainer<ContentNode>, + val groupID: GroupID, + val implicitlySourceSetHinted: Boolean = true +) : ContentComposite { + data class GroupID(val name: String) + + override val sourceSets: Set<SourceSetData> + get() = children.flatMap { it.sourceSets }.distinct().toSet() + + override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentGroup = + copy(extra = newExtras) +} + +/** Instance of a divergent content */ +data class ContentDivergentInstance( + val before: ContentNode?, + val divergent: ContentNode, + val after: ContentNode?, + override val dci: DCI, + override val sourceSets: Set<SourceSetData>, + override val style: Set<Style>, + override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() +) : ContentComposite { + override val children: List<ContentNode> + get() = listOfNotNull(before, divergent, after) + + override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentDivergentInstance = + copy(extra = newExtras) +} + data class PlatformHintedContent( val inner: ContentNode, override val sourceSets: Set<SourceSetData> @@ -163,9 +200,6 @@ data class PlatformHintedContent( throw UnsupportedOperationException("This method should not be called on this PlatformHintedContent") } -/** All extras */ -interface Extra - interface Style interface Kind diff --git a/core/src/main/kotlin/pages/utils.kt b/core/src/main/kotlin/pages/utils.kt new file mode 100644 index 00000000..5292dea1 --- /dev/null +++ b/core/src/main/kotlin/pages/utils.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka.pages + +import kotlin.reflect.KClass + +inline fun <reified T : ContentNode, R : ContentNode> R.mapTransform(noinline operation: (T) -> T): R = + mapTransform(T::class, operation) + +@PublishedApi +@Suppress("UNCHECKED_CAST") +internal fun <T : ContentNode, R : ContentNode> R.mapTransform(type: KClass<T>, operation: (T) -> T): R { + if (this::class == type) { + return operation(this as T) as R + } + val new = when (this) { + is ContentGroup -> this.copy(children.map { it.mapTransform(type, operation) }) + is ContentHeader -> this.copy(children.map { it.mapTransform(type, operation) }) + is ContentCode -> this.copy(children.map { it.mapTransform(type, operation) }) + is ContentTable -> this.copy(children.map { it.mapTransform(type, operation) }) + is ContentList -> this.copy(children.map { it.mapTransform(type, operation) }) + is ContentDivergentGroup -> this.copy(children.map { it.mapTransform(type, operation) }) + is ContentDivergentInstance -> this.copy( + before = before?.mapTransform(type, operation), + divergent = divergent.mapTransform(type, operation), + after = after?.mapTransform(type, operation) + ) + is PlatformHintedContent -> this.copy(inner.mapTransform(type, operation)) + else -> this + } + return new as R +} |