From 14a290009098b777521b1dedb551047fb66ba73b Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Tue, 29 Oct 2019 11:46:04 +0100 Subject: [WIP] new model --- core/src/main/kotlin/pages/ContentNodes.kt | 76 ++++++++++++++++++++++++++++++ core/src/main/kotlin/pages/PageNodes.kt | 39 +++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 core/src/main/kotlin/pages/ContentNodes.kt create mode 100644 core/src/main/kotlin/pages/PageNodes.kt (limited to 'core/src/main/kotlin/pages') diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt new file mode 100644 index 00000000..6519c313 --- /dev/null +++ b/core/src/main/kotlin/pages/ContentNodes.kt @@ -0,0 +1,76 @@ +package org.jetbrains.dokka.pages + +import org.jetbrains.dokka.links.DRI + +interface ContentNode { + val platforms: List + val annotations: List +} + +/** Comment consisting of parts, eg. [ContentText]s, [ContentLink]s and so on */ +data class ContentComment(val parts: List, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +/** Simple text */ +data class ContentText(val text: String, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +///** Headers */ TODO for next iteration +//data class ContentHeader(val text: String, +// val level: Int, +// override val platforms: List, +// override val annotations: List = emptyList() +//): ContentNode +// +///** Lists */ +//data class ContentList(val items: List, +// val ordered: Boolean, +// override val platforms: List, +// override val annotations: List = emptyList() +//): ContentNode +// +///** Styled elements, eg. bold, strikethrough, emphasis and so on **/ +//data class ContentStyle(val items: List, +// val ordered: Boolean, +// override val platforms: List, +// override val annotations: List = emptyList() +//): ContentNode + +/** Code blocks */ +data class ContentCode(val code: String, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +/** Symbols, eg. `open fun foo(): String`, or `class Bar`, consisting of parts like [ContentText] and [ContentLink] */ +data class ContentSymbol(val parts: List, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +/** All links that have te be resolved */ +data class ContentLink(val text: String, + val address: DRI, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +/** Blocks of [ContentNode]s with name, eg. Functions, Types, Properties, etc. */ +data class ContentBlock(val name: String, + val children: List, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +/** Logical grouping of [ContentNode]s, eg. [ContentLink], [ContentText] and [ContentSymbol] for one entity */ +data class ContentGroup(val children: List, + override val platforms: List, + override val annotations: List = emptyList() +): ContentNode + +/** All annotations */ +data class Annotation(val name: String) diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt new file mode 100644 index 00000000..1bd7f02f --- /dev/null +++ b/core/src/main/kotlin/pages/PageNodes.kt @@ -0,0 +1,39 @@ +package org.jetbrains.dokka.pages + +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.links.DRI + +abstract class PageNode( + val name: String, + val content: List, + val parent: PageNode?, + val dri: DRI? +// val declarationNode: DeclarationNode +) { + val children: List + get() = _children + + private val _children: MutableList = mutableListOf() + + fun appendChildren(children: List) = _children.addAll(children) + fun appendChild(child: PageNode) = _children.add(child) + +} + +class ModulePageNode(name: String, content: List, parent: PageNode?): PageNode(name, content, parent, null) +class PackagePageNode(name: String, content: List, parent: PageNode, dri: DRI): PageNode(name, content, parent, dri) +class ClassPageNode(name: String, content: List, parent: PageNode, dri: DRI): PageNode(name, content, parent, dri) // class, companion object +class MemberPageNode(name: String, content: List, parent: PageNode, dri: DRI): PageNode(name, content, parent, dri) // functions, extension functions, properties + + +data class PlatformData(val platformName: String, val platformType: Platform) + +fun PageNode.platforms(): List = this.content.flatMap { it.platforms }.distinct() // TODO: Override equals??? +fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) { this } else { this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() } + + + +// Navigation?? + +// content modifier? +//data class ContentLink(val link: String): ContentNode \ No newline at end of file -- cgit