aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/pages/PageBuilder.kt
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2019-11-21 02:10:26 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2019-11-25 17:17:01 +0100
commit193b8c0bcebdcdfd749090a408149cac06203614 (patch)
tree8875ec08e1ddac7a5d6c8708bd1a6a918c4380b0 /core/src/main/kotlin/pages/PageBuilder.kt
parent4f59d3df7a0a3525bf3a0dab8617746a4db30f67 (diff)
downloaddokka-193b8c0bcebdcdfd749090a408149cac06203614.tar.gz
dokka-193b8c0bcebdcdfd749090a408149cac06203614.tar.bz2
dokka-193b8c0bcebdcdfd749090a408149cac06203614.zip
Descriptor independent DocumentationNodes and seperate Page and PageContent builders
Diffstat (limited to 'core/src/main/kotlin/pages/PageBuilder.kt')
-rw-r--r--core/src/main/kotlin/pages/PageBuilder.kt95
1 files changed, 95 insertions, 0 deletions
diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt
new file mode 100644
index 00000000..d20635a4
--- /dev/null
+++ b/core/src/main/kotlin/pages/PageBuilder.kt
@@ -0,0 +1,95 @@
+package org.jetbrains.dokka.pages
+
+import org.jetbrains.dokka.Model.*
+import org.jetbrains.dokka.Model.Function
+
+class DefaultPageBuilder(
+ override val rootContentGroup: RootContentBuilder
+) : PageBuilder {
+
+ override fun pageForModule(m: Module): ModulePageNode =
+ ModulePageNode("root", contentForModule(m), m, m.packages.map { pageForPackage(it) })
+
+ override fun pageForPackage(p: Package) =
+ PackagePageNode(p.name, contentForPackage(p), p.dri, p,
+ p.classes.map { pageForClass(it) } +
+ p.functions.map { pageForMember(it) } +
+ p.properties.map { pageForMember(it) })
+
+ override fun pageForClass(c: Class): ClassPageNode =
+ ClassPageNode(c.name, contentForClass(c), c.dri, c,
+ c.constructors.map { pageForMember(it) } +
+ c.classes.map { pageForClass(it) } +
+ c.functions.map { pageForMember(it) })
+
+ override fun pageForMember(m: CallableNode): MemberPageNode =
+ when (m) {
+ is Function ->
+ MemberPageNode(m.name, contentForFunction(m), m.dri, m)
+ else -> throw IllegalStateException("$m should not be present here")
+ }
+
+ private fun group(node: DocumentationNode, content: PageContentBuilderFunction) =
+ rootContentGroup(node, ContentKind.Main, content)
+
+ private fun contentForModule(m: Module) = group(m) {
+ header(1) { text("root") }
+ block("Packages", 2, ContentKind.Packages, m.packages, m.platformData) {
+ link(it.name, it.dri)
+ }
+ text("Index\n")
+ text("Link to allpage here")
+ }
+
+ private fun contentForPackage(p: Package) = group(p) {
+ header(1) { text("Package ${p.name}") }
+ block("Types", 2, ContentKind.Properties, p.classes, p.platformData) {
+ link(it.name, it.dri)
+ text(it.briefDocstring)
+ }
+ block("Functions", 2, ContentKind.Functions, p.functions, p.platformData) {
+ link(it.name, it.dri)
+ signature(it)
+ text(it.briefDocstring)
+ }
+ }
+
+ private fun contentForClass(c: Class) = group(c) {
+ header(1) { text(c.name) }
+ c.inherited.takeIf { it.isNotEmpty() }?.let {
+ header(2) { text("SuperInterfaces") }
+ linkTable(it)
+ }
+ c.commentsData.forEach { (doc, links) -> comment(doc, links) }
+ block("Constructors", 2, ContentKind.Functions, c.constructors, c.platformData) {
+ link(it.name, it.dri)
+ signature(it)
+ text(it.briefDocstring)
+ }
+ block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) {
+ link(it.name, it.dri)
+ signature(it)
+ text(it.briefDocstring)
+ }
+ }
+
+ private fun contentForFunction(f: Function) = group(f) {
+ header(1) { text(f.name) }
+ signature(f)
+ f.commentsData.forEach { (doc, links) -> markdown(doc, links) }
+ block("Parameters", 2, ContentKind.Parameters, f.children, f.platformData) {
+ text(it.name ?: "<receiver>")
+ it.commentsData.forEach { (doc, links) -> markdown(doc, links) }
+ }
+ }
+}
+
+typealias RootContentBuilder = (DocumentationNode, Kind, PageContentBuilderFunction) -> ContentGroup
+
+interface PageBuilder {
+ val rootContentGroup: RootContentBuilder
+ fun pageForModule(m: Module): ModulePageNode
+ fun pageForPackage(p: Package): PackagePageNode
+ fun pageForMember(m: CallableNode): MemberPageNode
+ fun pageForClass(c: Class): ClassPageNode
+} \ No newline at end of file