aboutsummaryrefslogtreecommitdiff
path: root/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt')
-rw-r--r--plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt22
1 files changed, 22 insertions, 0 deletions
diff --git a/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt b/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt
new file mode 100644
index 00000000..8035fc83
--- /dev/null
+++ b/plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt
@@ -0,0 +1,22 @@
+package templates
+
+import org.jetbrains.dokka.base.templating.Command
+import org.jetbrains.dokka.base.templating.ReplaceVersionsCommand
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.templates.CommandHandler
+import org.jsoup.nodes.Element
+import org.jsoup.nodes.TextNode
+import java.io.File
+
+class ReplaceVersionCommandHandler(private val context: DokkaContext) : CommandHandler {
+
+ override fun canHandle(command: Command): Boolean = command is ReplaceVersionsCommand
+
+ override fun handleCommand(element: Element, command: Command, input: File, output: File) {
+ val position = element.elementSiblingIndex()
+ val parent = element.parent()
+ element.remove()
+ context.configuration.moduleVersion?.takeIf { it.isNotEmpty() }
+ ?.let { parent.insertChildren(position, TextNode(it)) }
+ }
+} \ No newline at end of file