aboutsummaryrefslogtreecommitdiff
path: root/plugins/xml/src
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2019-11-26 14:39:06 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2019-11-26 14:39:06 +0100
commit4b1a3a2cbe62f98c9f1b472e70d754645d7f8641 (patch)
treeb66dc9a69905f972c84cdca75bc2f21a02f244a4 /plugins/xml/src
parent193b8c0bcebdcdfd749090a408149cac06203614 (diff)
downloaddokka-4b1a3a2cbe62f98c9f1b472e70d754645d7f8641.tar.gz
dokka-4b1a3a2cbe62f98c9f1b472e70d754645d7f8641.tar.bz2
dokka-4b1a3a2cbe62f98c9f1b472e70d754645d7f8641.zip
Merging PageNode changes with plugins
Diffstat (limited to 'plugins/xml/src')
-rw-r--r--plugins/xml/src/main/kotlin/XmlPlugin.kt62
-rw-r--r--plugins/xml/src/main/kotlin/utils.kt136
2 files changed, 35 insertions, 163 deletions
diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt
index 4023e1cc..5be0eca4 100644
--- a/plugins/xml/src/main/kotlin/XmlPlugin.kt
+++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt
@@ -2,6 +2,7 @@ package org.jetbrains.dokka.xml
import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.DefaultExtra
+import org.jetbrains.dokka.DokkaConsoleLogger
import org.jetbrains.dokka.Model.DocumentationNode
import org.jetbrains.dokka.Model.dfs
import org.jetbrains.dokka.links.DRI
@@ -9,6 +10,7 @@ import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.transformers.PageNodeTransformer
+import javax.xml.bind.annotation.XmlList
class XmlPlugin : DokkaPlugin() {
val transformer by extending {
@@ -21,36 +23,40 @@ object XmlTransformer : PageNodeTransformer {
Main, XmlList
}
- override fun invoke(input: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode {
- input.findAll { it is ClassPageNode }.forEach { node ->
- val refs = node.documentationNode?.extra?.filterIsInstance<DefaultExtra>()?.filter { it.key == "@attr ref"}.orEmpty()
- val elementsToAdd = mutableListOf<DocumentationNode<*>>()
-
- refs.forEach { ref ->
- val toFind = DRI.from(ref.value)
- input.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) }
- }
- val refTable = group(node.platforms().toSet(), node.dri, XMLKind.XmlList) {
- table("XML Attributes", 2, XMLKind.XmlList, elementsToAdd) {
- elementsToAdd.map { row(it) }
+ override fun invoke(input: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode =
+ input.transformPageNodeTree { node ->
+ if (node !is ClassPageNode) node
+ else {
+ val refs =
+ node.documentationNode?.extra?.filterIsInstance<DefaultExtra>()?.filter { it.key == "@attr ref" }
+ .orEmpty()
+ val elementsToAdd = mutableListOf<DocumentationNode>()
+
+ refs.forEach { ref ->
+ val toFind = DRI.from(ref.value)
+ input.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) }
+ }
+ val platformData = node.platforms().toSet()
+ val refTable = DefaultPageContentBuilder.group(
+ node.dri,
+ platformData,
+ XMLKind.XmlList,
+ //Following parameters will soon be drawn from context, so we can leave them like this for the time being
+ MarkdownToContentConverter(DokkaConsoleLogger),
+ DokkaConsoleLogger
+ ) {
+ block("XML Attributes", 2, XMLKind.XmlList, elementsToAdd, platformData) { element ->
+ link(element.dri, XMLKind.XmlList) {
+ text(element.name ?: "<unnamed>", XMLKind.Main)
+ }
+ text(element.briefDocstring, XMLKind.XmlList)
+ }
}
- }
-
- val content = node.content as ContentGroup
- val children = (node.content as ContentGroup).children
- node.content = content.copy(children = children + refTable)
- }
- return input
- }
- private fun PageNode.findAll(predicate: (PageNode) -> Boolean): Set<PageNode> {
- val found = mutableSetOf<PageNode>()
- if (predicate(this)) {
- found.add(this)
- } else {
- this.children.asSequence().mapNotNull { it.findAll(predicate) }.forEach { found.addAll(it) }
- }
- return found
+ val content = node.content as ContentGroup
+ val children = (node.content as ContentGroup).children
+ node.modified(content = content.copy(children = children + refTable))
+ }
}
private fun PageNode.platforms() = this.content.platforms.toList()
diff --git a/plugins/xml/src/main/kotlin/utils.kt b/plugins/xml/src/main/kotlin/utils.kt
index 510f3328..2f5f1893 100644
--- a/plugins/xml/src/main/kotlin/utils.kt
+++ b/plugins/xml/src/main/kotlin/utils.kt
@@ -1,135 +1 @@
-package org.jetbrains.dokka.xml
-
-import org.jetbrains.dokka.Model.DocumentationNode
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.pages.*
-
-internal class ContentBuilder(
- val platforms: Set<PlatformData>,
- val dri: DRI,
- val kind: Kind,
- val styles: Set<Style> = emptySet(),
- val extras: Set<Extra> = emptySet()
-) {
- private val contents = mutableListOf<ContentNode>()
-
- fun build() = ContentGroup(
- contents.toList(),
- DCI(dri, kind),
- platforms,
- styles,
- extras
- )
-
- fun header(level: Int, block: ContentBuilder.() -> Unit) {
- contents += ContentHeader(level, group(ContentKind.Symbol, block))
- }
-
- private fun createText(text: String) =
- ContentText(text, DCI(dri, ContentKind.Symbol), platforms, styles, extras)
-
- fun text(text: String) {
- contents += createText(text)
- }
-
- inline fun <T : Any> block(
- name: String,
- level: Int,
- kind: Kind,
- elements: Iterable<T>,
- platformData: Set<PlatformData>,
- operation: ContentBuilder.(T) -> Unit
- ) {
- header(level) { text(name) }
-
- contents += ContentTable(
- emptyList(),
- elements.map { group(platforms, dri, kind) { operation(it) } },
- DCI(dri, kind),
- platformData, styles, extras
- )
- }
-
- inline fun <T> list(
- elements: List<T>,
- prefix: String = "",
- suffix: String = "",
- separator: String = ", ",
- block: ContentBuilder.(T) -> Unit
- ) {
- if (elements.isNotEmpty()) {
- if (prefix.isNotEmpty()) text(prefix)
- elements.dropLast(1).forEach {
- block(it)
- text(separator)
- }
- block(elements.last())
- if (suffix.isNotEmpty()) text(suffix)
- }
- }
-
- fun link(text: String, address: DRI) {
- contents += ContentDRILink(
- listOf(createText(text)),
- address,
- DCI(dri, ContentKind.Symbol),
- platforms
- )
- }
-
- fun <T: DocumentationNode<*>> table(
- name: String,
- level: Int,
- kind: Kind,
- elements: Iterable<T>,
- operation: ContentBuilder.(T) -> Unit
- ) {
- header(level) { text(name) }
-
- contents += ContentTable(
- emptyList(),
- elements.map { row(it) }.toList(),
- DCI(dri, kind),
- platforms, emptySet(), emptySet()
- )
- }
-
-
- fun row(element: DocumentationNode<*>) =
- ContentGroup(
- listOf(
- ContentDRILink(
- listOf(
- ContentText(
- element.descriptors.first().name.toString(),
- DCI(dri, XmlTransformer.XMLKind.Main),
- platforms, emptySet(), emptySet()
- )
- ),
- element.dri,
- DCI(element.dri, XmlTransformer.XMLKind.XmlList),
- element.platformData.toSet(), emptySet(), emptySet()
- ),
- ContentText(
- element.briefDocstring,
- DCI(element.dri, XmlTransformer.XMLKind.XmlList),
- element.platformData.toSet(), emptySet(), emptySet()
- )
- ),
- DCI(dri, XmlTransformer.XMLKind.XmlList),
- platforms, emptySet(), emptySet()
- )
-
-
- private inline fun group(kind: Kind, block: ContentBuilder.() -> Unit): ContentGroup =
- group(platforms, dri, kind, block)
-}
-
-internal inline fun group(
- platforms: Set<PlatformData>,
- dri: DRI,
- kind: Kind = ContentKind.Main,
- block: ContentBuilder.() -> Unit
-) = ContentBuilder(platforms, dri, kind).apply(block).build()
-
-
+package org.jetbrains.dokka.xml \ No newline at end of file