diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-07-17 16:36:09 +0200 |
---|---|---|
committer | Paweł Marks <pmarks@virtuslab.com> | 2020-07-17 16:36:09 +0200 |
commit | 6996b1135f61c7d2cb60b0652c6a2691dda31990 (patch) | |
tree | d568096c25e31c28d14d518a63458b5a7526b896 /plugins/xml/src | |
parent | de56cab76f556e5b4af0b8c8cb08d8b482b86d0a (diff) | |
parent | 1c3530dcbb50c347f80bef694829dbefe89eca77 (diff) | |
download | dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.gz dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.tar.bz2 dokka-6996b1135f61c7d2cb60b0652c6a2691dda31990.zip |
Merge branch 'dev-0.11.0'
Diffstat (limited to 'plugins/xml/src')
3 files changed, 65 insertions, 0 deletions
diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt new file mode 100644 index 00000000..e19b76b3 --- /dev/null +++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt @@ -0,0 +1,63 @@ +package org.jetbrains.dokka.xml + +import org.jetbrains.dokka.CoreExtensions +import org.jetbrains.dokka.model.Documentable +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.DokkaPlugin +import org.jetbrains.dokka.plugability.single +import org.jetbrains.dokka.transformers.descriptors.XMLMega +import org.jetbrains.dokka.transformers.pages.PageNodeTransformer + +class XmlPlugin : DokkaPlugin() { + val transformer by extending { + CoreExtensions.pageTransformer providing ::XmlTransformer + } +} + +class XmlTransformer(private val dokkaContext: DokkaContext) : PageNodeTransformer { + private val commentsToContentConverter by lazy { dokkaContext.single(CoreExtensions.commentsToContentConverter) } + + enum class XMLKind : Kind { + Main, XmlList + } + + override fun invoke(input: RootPageNode): RootPageNode = + input.transformPageNodeTree { if (it is ModulePageNode) transformModule(it) else it } + + private fun transformModule(module: ModulePageNode) = module.transformContentPagesTree { node -> + if (node !is ClasslikePageNode) node + else { + val refs = + node.documentable?.extra?.filterIsInstance<XMLMega>()?.filter { it.key == "@attr ref" } + .orEmpty() + val elementsToAdd = mutableListOf<Documentable>() + + refs.forEach { ref -> + module.documentable?.dfs { it.dri == ref.dri }?.let { elementsToAdd.add(it) } + } + val platformData = node.platforms().toSet() + val refTable = DefaultPageContentBuilder.group( + node.dri, + platformData, + XMLKind.XmlList, + commentsToContentConverter, + dokkaContext.logger + ) { + block("XML Attributes", 2, XMLKind.XmlList, elementsToAdd, platformData) { element -> + link(element.dri, XMLKind.XmlList) { + text(element.name ?: "<unnamed>", XMLKind.Main) + } + text(element.briefDocTagString, XMLKind.XmlList) + } + } + + val content = node.content as ContentGroup + val children = (node.content as ContentGroup).children + node.modified(content = content.copy(children = children + refTable)) + } + } + + private fun ContentPage.platforms() = this.content.platforms.toList() +}
\ No newline at end of file diff --git a/plugins/xml/src/main/kotlin/utils.kt b/plugins/xml/src/main/kotlin/utils.kt new file mode 100644 index 00000000..2f5f1893 --- /dev/null +++ b/plugins/xml/src/main/kotlin/utils.kt @@ -0,0 +1 @@ +package org.jetbrains.dokka.xml
\ 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 |