aboutsummaryrefslogtreecommitdiff
path: root/plugins/templating/src
diff options
context:
space:
mode:
authorvmishenev <vad-mishenev@yandex.ru>2021-09-01 00:03:13 +0300
committervmishenev <vad-mishenev@yandex.ru>2021-09-20 19:01:44 +0300
commitfc5496fb8bb888c3a50717260dc05d8fe2d54306 (patch)
tree2b61c01babe696065c4b8bafad61cce7479561ad /plugins/templating/src
parent8efe04e127e3bf0aef395b31f3f3d9f49a0afe26 (diff)
downloaddokka-fc5496fb8bb888c3a50717260dc05d8fe2d54306.tar.gz
dokka-fc5496fb8bb888c3a50717260dc05d8fe2d54306.tar.bz2
dokka-fc5496fb8bb888c3a50717260dc05d8fe2d54306.zip
Improve versioning plugin (#2104)
- support for single module projects - version navigator is on all pages - dropdown arrow for version navigator
Diffstat (limited to 'plugins/templating/src')
-rw-r--r--plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt22
-rw-r--r--plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt4
2 files changed, 26 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
diff --git a/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt b/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt
index 1a02d41f..7001b1ba 100644
--- a/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt
+++ b/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt
@@ -4,6 +4,7 @@ import org.jetbrains.dokka.allModulesPage.templates.PackageListProcessingStrateg
import org.jetbrains.dokka.allModulesPage.templates.PagesSearchTemplateStrategy
import org.jetbrains.dokka.plugability.DokkaPlugin
import templates.ProjectNameSubstitutor
+import templates.ReplaceVersionCommandHandler
import templates.SourcesetDependencyProcessingStrategy
class TemplatingPlugin : DokkaPlugin() {
@@ -65,4 +66,7 @@ class TemplatingPlugin : DokkaPlugin() {
val substitutionCommandHandler by extending {
directiveBasedCommandHandlers providing ::SubstitutionCommandHandler
}
+ val replaceVersionCommandHandler by extending {
+ directiveBasedCommandHandlers providing ::ReplaceVersionCommandHandler
+ }
}