aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorSzymon Świstun <sswistun@virtuslab.com>2020-02-14 11:38:06 +0100
committerKamil Doległo <kamilok1965@users.noreply.github.com>2020-03-18 14:16:14 +0100
commit5292d776c1860debe8a3fcf49465a974f906f16f (patch)
treeec75898ed5c9044030aea090824407ae08afdf9a /core/src
parent9273d18c9edf7ea2aa265d53a9ae971e3e28a87d (diff)
downloaddokka-5292d776c1860debe8a3fcf49465a974f906f16f.tar.gz
dokka-5292d776c1860debe8a3fcf49465a974f906f16f.tar.bz2
dokka-5292d776c1860debe8a3fcf49465a974f906f16f.zip
page transformer builders
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt b/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt
new file mode 100644
index 00000000..89b22c19
--- /dev/null
+++ b/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt
@@ -0,0 +1,22 @@
+package org.jetbrains.dokka.transformers.pages
+
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.pages.RootPageNode
+
+fun pageScanner(block: PageNode.() -> Unit) = object : PageNodeTransformer {
+ override fun invoke(input: RootPageNode): RootPageNode = input.invokeOnAll(block) as RootPageNode
+}
+
+fun pageMapper(block: PageNode.() -> PageNode) = object : PageNodeTransformer {
+ override fun invoke(input: RootPageNode): RootPageNode = input.alterChildren(block) as RootPageNode
+}
+
+fun pageStructureTransformer(block: RootPageNode.() -> RootPageNode) = object : PageNodeTransformer {
+ override fun invoke(input: RootPageNode): RootPageNode = block(input)
+}
+
+fun PageNode.invokeOnAll(block: PageNode.() -> Unit): PageNode =
+ this.also(block).also { it.children.forEach { it.invokeOnAll(block) } }
+
+fun PageNode.alterChildren(block: PageNode.() -> PageNode): PageNode =
+ block(this).modified(children = this.children.map { it.alterChildren(block) }) \ No newline at end of file