aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-07-17 16:36:09 +0200
committerPaweł Marks <pmarks@virtuslab.com>2020-07-17 16:36:09 +0200
commit6996b1135f61c7d2cb60b0652c6a2691dda31990 (patch)
treed568096c25e31c28d14d518a63458b5a7526b896 /plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
parentde56cab76f556e5b4af0b8c8cb08d8b482b86d0a (diff)
parent1c3530dcbb50c347f80bef694829dbefe89eca77 (diff)
downloaddokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.gz
dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.bz2
dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.zip
Merge branch 'dev-0.11.0'
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt51
1 files changed, 51 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
new file mode 100644
index 00000000..8fe2a6c8
--- /dev/null
+++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
@@ -0,0 +1,51 @@
+package org.jetbrains.dokka.base.renderers.html
+
+import kotlinx.html.*
+import kotlinx.html.stream.createHTML
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.pages.RendererSpecificPage
+import org.jetbrains.dokka.pages.RenderingStrategy
+
+class NavigationPage(val root: NavigationNode) : RendererSpecificPage {
+ override val name = "navigation"
+
+ override val children = emptyList<PageNode>()
+
+ override fun modified(name: String, children: List<PageNode>) = this
+
+ override val strategy = RenderingStrategy<HtmlRenderer> {
+ createHTML().visit(root, "nav-submenu", this)
+ }
+
+ private fun <R> TagConsumer<R>.visit(node: NavigationNode, navId: String, renderer: HtmlRenderer): R =
+ with(renderer) {
+ div("sideMenuPart") {
+ id = navId
+ attributes["pageId"] = node.dri.toString()
+ div("overview") {
+ buildLink(node.dri, node.sourceSets.toList()) { +node.name }
+ if (node.children.isNotEmpty()) {
+ span("navButton") {
+ onClick = """document.getElementById("$navId").classList.toggle("hidden");"""
+ span("navButtonContent")
+ }
+ }
+ }
+ node.children.withIndex().forEach { (n, p) -> visit(p, "$navId-$n", renderer) }
+ }
+ }
+}
+
+class NavigationNode(
+ val name: String,
+ val dri: DRI,
+ val sourceSets: Set<DokkaSourceSet>,
+ val children: List<NavigationNode>
+)
+
+fun NavigationPage.transform(block: (NavigationNode) -> NavigationNode) = NavigationPage(root.transform(block))
+
+fun NavigationNode.transform(block: (NavigationNode) -> NavigationNode) =
+ run(block).let { NavigationNode(it.name, it.dri, it.sourceSets, it.children.map(block)) }