From ca3d34cc9e5be2d9616cfde3d2cac489c07bf102 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 20 Nov 2019 15:20:04 +0100 Subject: Initial XML plugin 2 --- plugins/xml/src/main/kotlin/XmlPlugin.kt | 104 +++++++++++++++++++++ .../org.jetbrains.dokka.plugability.DokkaPlugin | 1 + 2 files changed, 105 insertions(+) create mode 100644 plugins/xml/src/main/kotlin/XmlPlugin.kt create mode 100644 plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin (limited to 'plugins/xml/src') diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt new file mode 100644 index 00000000..4a932062 --- /dev/null +++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt @@ -0,0 +1,104 @@ +package org.jetbrains.dokka.xml + +import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.DefaultExtra +import org.jetbrains.dokka.Model.DocumentationNode +import org.jetbrains.dokka.Model.dfs +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.transformers.PageNodeTransformer + +class XmlPlugin : DokkaPlugin() { + val transformer by extending { + CoreExtensions.pageTransformer with XmlTransformer + } +} + +private const val ANNOTATION = "@usesMathJax" +private const val LIB_PATH = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" + +object XmlTransformer : PageNodeTransformer { + enum class XMLKind : Kind { + Main, XmlList + } + + override fun invoke(original: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode { + original.findAll { it is ClassPageNode }.forEach { node -> + val refs = node.documentationNode?.extra?.filterIsInstance()?.filter { it.key == "@attr ref"}.orEmpty() + val elementsToAdd = mutableListOf>() + + refs.forEach { ref -> + val toFind = DRI.from(ref.value) + original.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) } + } + + val refTable = ContentGroup( + listOf( + ContentHeader( + listOf( + ContentText( + "XML Attributes", + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + 2, + DCI(node.dri, XMLKind.Main), + node.platforms().toSet(), emptySet(), emptySet() + ), + ContentTable( + emptyList(), + elementsToAdd.map { + ContentGroup( + listOf( + ContentDRILink( + listOf( + ContentText( + it.descriptors.first().name.toString(), + DCI(node.dri, XMLKind.Main), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + it.dri, + DCI(it.dri, XMLKind.XmlList), + it.platformData.toSet(), emptySet(), emptySet() + ), + ContentText( + it.briefDocstring, + DCI(it.dri, XMLKind.XmlList), + it.platformData.toSet(), emptySet(), emptySet() + ) + ), + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + }, + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + ), + DCI(node.dri, XMLKind.XmlList), + node.platforms().toSet(), emptySet(), emptySet() + ) + + val content = node.content as ContentGroup + val children = (node.content as ContentGroup).children + node.content = content.copy(children = children + refTable) + } + return original + } + + private fun PageNode.findAll(predicate: (PageNode) -> Boolean): Set { + val found = mutableSetOf() + if (predicate(this)) { + found.add(this) + } else { + this.children.asSequence().mapNotNull { it.findAll(predicate) }.forEach { found.addAll(it) } + } + return found + } + + private fun PageNode.platforms() = this.content.platforms.toList() +} \ No newline at end of file diff --git a/plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin new file mode 100644 index 00000000..ebc3e551 --- /dev/null +++ b/plugins/xml/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin @@ -0,0 +1 @@ +org.jetbrains.dokka.xml.XmlPlugin -- cgit From 4f59d3df7a0a3525bf3a0dab8617746a4db30f67 Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 20 Nov 2019 17:42:45 +0100 Subject: XML plugin refactoring --- plugins/xml/src/main/kotlin/XmlPlugin.kt | 65 +++------------ plugins/xml/src/main/kotlin/utils.kt | 135 +++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 56 deletions(-) create mode 100644 plugins/xml/src/main/kotlin/utils.kt (limited to 'plugins/xml/src') diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt index 4a932062..4023e1cc 100644 --- a/plugins/xml/src/main/kotlin/XmlPlugin.kt +++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt @@ -16,78 +16,31 @@ class XmlPlugin : DokkaPlugin() { } } -private const val ANNOTATION = "@usesMathJax" -private const val LIB_PATH = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_SVG&latest" - object XmlTransformer : PageNodeTransformer { enum class XMLKind : Kind { Main, XmlList } - override fun invoke(original: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode { - original.findAll { it is ClassPageNode }.forEach { node -> + override fun invoke(input: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode { + input.findAll { it is ClassPageNode }.forEach { node -> val refs = node.documentationNode?.extra?.filterIsInstance()?.filter { it.key == "@attr ref"}.orEmpty() val elementsToAdd = mutableListOf>() refs.forEach { ref -> val toFind = DRI.from(ref.value) - original.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) } + 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) } + } } - - val refTable = ContentGroup( - listOf( - ContentHeader( - listOf( - ContentText( - "XML Attributes", - DCI(node.dri, XMLKind.XmlList), - node.platforms().toSet(), emptySet(), emptySet() - ) - ), - 2, - DCI(node.dri, XMLKind.Main), - node.platforms().toSet(), emptySet(), emptySet() - ), - ContentTable( - emptyList(), - elementsToAdd.map { - ContentGroup( - listOf( - ContentDRILink( - listOf( - ContentText( - it.descriptors.first().name.toString(), - DCI(node.dri, XMLKind.Main), - node.platforms().toSet(), emptySet(), emptySet() - ) - ), - it.dri, - DCI(it.dri, XMLKind.XmlList), - it.platformData.toSet(), emptySet(), emptySet() - ), - ContentText( - it.briefDocstring, - DCI(it.dri, XMLKind.XmlList), - it.platformData.toSet(), emptySet(), emptySet() - ) - ), - DCI(node.dri, XMLKind.XmlList), - node.platforms().toSet(), emptySet(), emptySet() - ) - }, - DCI(node.dri, XMLKind.XmlList), - node.platforms().toSet(), emptySet(), emptySet() - ) - ), - DCI(node.dri, XMLKind.XmlList), - node.platforms().toSet(), emptySet(), emptySet() - ) val content = node.content as ContentGroup val children = (node.content as ContentGroup).children node.content = content.copy(children = children + refTable) } - return original + return input } private fun PageNode.findAll(predicate: (PageNode) -> Boolean): Set { diff --git a/plugins/xml/src/main/kotlin/utils.kt b/plugins/xml/src/main/kotlin/utils.kt new file mode 100644 index 00000000..510f3328 --- /dev/null +++ b/plugins/xml/src/main/kotlin/utils.kt @@ -0,0 +1,135 @@ +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, + val dri: DRI, + val kind: Kind, + val styles: Set