diff options
Diffstat (limited to 'plugins/templating/src')
-rw-r--r-- | plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt | 22 | ||||
-rw-r--r-- | plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt | 4 |
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 + } } |