diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2019-10-29 11:46:04 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-10-29 15:49:53 +0100 |
commit | 14a290009098b777521b1dedb551047fb66ba73b (patch) | |
tree | ae68219051b080ff8888308d5521aaeea7431fb4 /core/src/main/kotlin/pages | |
parent | 5f358199788fefb78f5db7791e718480793a77fc (diff) | |
download | dokka-14a290009098b777521b1dedb551047fb66ba73b.tar.gz dokka-14a290009098b777521b1dedb551047fb66ba73b.tar.bz2 dokka-14a290009098b777521b1dedb551047fb66ba73b.zip |
[WIP] new model
Diffstat (limited to 'core/src/main/kotlin/pages')
-rw-r--r-- | core/src/main/kotlin/pages/ContentNodes.kt | 76 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/PageNodes.kt | 39 |
2 files changed, 115 insertions, 0 deletions
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<PlatformData> + val annotations: List<Annotation> +} + +/** Comment consisting of parts, eg. [ContentText]s, [ContentLink]s and so on */ +data class ContentComment(val parts: List<ContentNode>, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = emptyList() +): ContentNode + +/** Simple text */ +data class ContentText(val text: String, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = emptyList() +): ContentNode + +///** Headers */ TODO for next iteration +//data class ContentHeader(val text: String, +// val level: Int, +// override val platforms: List<PlatformData>, +// override val annotations: List<Annotation> = emptyList() +//): ContentNode +// +///** Lists */ +//data class ContentList(val items: List<ContentNode>, +// val ordered: Boolean, +// override val platforms: List<PlatformData>, +// override val annotations: List<Annotation> = emptyList() +//): ContentNode +// +///** Styled elements, eg. bold, strikethrough, emphasis and so on **/ +//data class ContentStyle(val items: List<ContentNode>, +// val ordered: Boolean, +// override val platforms: List<PlatformData>, +// override val annotations: List<Annotation> = emptyList() +//): ContentNode + +/** Code blocks */ +data class ContentCode(val code: String, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = emptyList() +): ContentNode + +/** Symbols, eg. `open fun foo(): String`, or `class Bar`, consisting of parts like [ContentText] and [ContentLink] */ +data class ContentSymbol(val parts: List<ContentNode>, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = emptyList() +): ContentNode + +/** All links that have te be resolved */ +data class ContentLink(val text: String, + val address: DRI, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = emptyList() +): ContentNode + +/** Blocks of [ContentNode]s with name, eg. Functions, Types, Properties, etc. */ +data class ContentBlock(val name: String, + val children: List<ContentNode>, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = emptyList() +): ContentNode + +/** Logical grouping of [ContentNode]s, eg. [ContentLink], [ContentText] and [ContentSymbol] for one entity */ +data class ContentGroup(val children: List<ContentNode>, + override val platforms: List<PlatformData>, + override val annotations: List<Annotation> = 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<ContentNode>, + val parent: PageNode?, + val dri: DRI? +// val declarationNode: DeclarationNode +) { + val children: List<PageNode> + get() = _children + + private val _children: MutableList<PageNode> = mutableListOf() + + fun appendChildren(children: List<PageNode>) = _children.addAll(children) + fun appendChild(child: PageNode) = _children.add(child) + +} + +class ModulePageNode(name: String, content: List<ContentNode>, parent: PageNode?): PageNode(name, content, parent, null) +class PackagePageNode(name: String, content: List<ContentNode>, parent: PageNode, dri: DRI): PageNode(name, content, parent, dri) +class ClassPageNode(name: String, content: List<ContentNode>, parent: PageNode, dri: DRI): PageNode(name, content, parent, dri) // class, companion object +class MemberPageNode(name: String, content: List<ContentNode>, 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<PlatformData> = 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 |