aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorMarcin Aman <maman@virtuslab.com>2020-07-30 15:05:06 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-08-21 15:40:12 +0200
commit3c07bc1966c85de3351602c4e8798fa507c40e49 (patch)
treeef39ea18a4ec699e4cab9dc55489b43fccb1e247 /plugins/base/src/main/kotlin
parentc2b02c1fc17b839075b7cb6fd42498a519473fae (diff)
downloaddokka-3c07bc1966c85de3351602c4e8798fa507c40e49.tar.gz
dokka-3c07bc1966c85de3351602c4e8798fa507c40e49.tar.bz2
dokka-3c07bc1966c85de3351602c4e8798fa507c40e49.zip
Create navigation search component
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt3
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt2
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt59
4 files changed, 52 insertions, 16 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
index 83a0fc5b..3d0ced06 100644
--- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
@@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking
import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.resolvers.local.LocationProvider
+import org.jetbrains.dokka.base.resolvers.local.resolveOrThrow
import org.jetbrains.dokka.model.DisplaySourceSet
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
@@ -168,6 +169,9 @@ abstract class DefaultRenderer<T>(
is RenderingStrategy.Copy -> outputWriter.writeResources(strategy.from, path)
is RenderingStrategy.Write -> outputWriter.write(path, strategy.text, "")
is RenderingStrategy.Callback -> outputWriter.write(path, strategy.instructions(this, page), ".html")
+ is RenderingStrategy.LocationResolvableWrite -> outputWriter.write(path, strategy.contentToResolve { dri, sourcesets ->
+ locationProvider.resolveOrThrow(dri, sourcesets)
+ }, "")
RenderingStrategy.DoNothing -> Unit
}
else -> throw AssertionError(
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 5747c6da..22fb3e63 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -675,6 +675,9 @@ open class HtmlRenderer(
id = "logo"
}
div {
+ id = "paneSearch"
+ }
+ div {
id = "sideMenu"
}
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
index a6a16412..f569ed12 100644
--- a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
@@ -38,7 +38,7 @@ class NavigationPage(val root: NavigationNode) : RendererSpecificPage {
}
}
-class NavigationNode(
+data class NavigationNode(
val name: String,
val dri: DRI,
val sourceSets: Set<DisplaySourceSet>,
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index 407e5899..6e779931 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -1,20 +1,18 @@
package org.jetbrains.dokka.base.renderers.html
+import com.fasterxml.jackson.databind.annotation.JsonSerialize
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer
+import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import kotlinx.html.h1
import kotlinx.html.id
import kotlinx.html.table
import kotlinx.html.tbody
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.Platform
-import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.sourceSets
-import org.jetbrains.dokka.base.resolvers.local.LocationProvider
+import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.DEnumEntry
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.plugin
-import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -40,19 +38,45 @@ object SearchPageInstaller : PageTransformer {
}
object NavigationPageInstaller : PageTransformer {
- override fun invoke(input: RootPageNode) = input.modified(
- children = input.children + NavigationPage(
- input.children.filterIsInstance<ContentPage>().single()
- .let(NavigationPageInstaller::visit)
+ private val mapper = jacksonObjectMapper()
+
+ private data class NavigationNodeView(
+ val name: String,
+ val label: String = name,
+ val searchKey: String = name,
+ @get:JsonSerialize(using = ToStringSerializer::class) val dri: DRI,
+ val location: String
+ ) {
+ companion object {
+ fun from(node: NavigationNode, location: String): NavigationNodeView =
+ NavigationNodeView(name = node.name, dri = node.dri, location = location)
+ }
+ }
+
+ override fun invoke(input: RootPageNode): RootPageNode {
+ val nodes = input.children.filterIsInstance<ContentPage>().single()
+ .let(NavigationPageInstaller::visit)
+
+ val page = RendererSpecificResourcePage(
+ name = "scripts/navigation-pane.json",
+ children = emptyList(),
+ strategy = RenderingStrategy.LocationResolvableWrite { resolver ->
+ val flattened = flattenNavigationNodes(listOf(nodes))
+ val view = flattened.map { NavigationNodeView.from(it, resolver(it.dri, it.sourceSets)) }
+ mapper.writeValueAsString(view)
+ })
+
+ return input.modified(
+ children = input.children + page + NavigationPage(nodes)
)
- )
+ }
private fun visit(page: ContentPage): NavigationNode =
NavigationNode(
- page.name,
- page.dri.first(),
- page.sourceSets(),
- page.navigableChildren()
+ name = page.name,
+ dri = page.dri.first(),
+ sourceSets = page.sourceSets(),
+ children = page.navigableChildren()
)
private fun ContentPage.navigableChildren(): List<NavigationNode> =
@@ -63,6 +87,11 @@ object NavigationPageInstaller : PageTransformer {
children.filter { it is ContentPage && it.documentable is DEnumEntry }.map { visit(it as ContentPage) }
else -> emptyList()
}.sortedBy { it.name.toLowerCase() }
+
+ private tailrec fun flattenNavigationNodes(nodes: List<NavigationNode>, acc: List<NavigationNode> = emptyList()): List<NavigationNode> {
+ if(nodes.isEmpty()) return acc
+ return flattenNavigationNodes(nodes.flatMap { it.children }, nodes.map { it.copy(children = emptyList()) } + acc)
+ }
}
object ResourceInstaller : PageTransformer {