aboutsummaryrefslogtreecommitdiff
path: root/plugins/templating
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
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')
-rw-r--r--plugins/templating/api/templating.api8
-rw-r--r--plugins/templating/src/main/kotlin/templates/ReplaceVersionCommandHandler.kt22
-rw-r--r--plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt4
3 files changed, 34 insertions, 0 deletions
diff --git a/plugins/templating/api/templating.api b/plugins/templating/api/templating.api
index 0965020b..a0fb5122 100644
--- a/plugins/templating/api/templating.api
+++ b/plugins/templating/api/templating.api
@@ -130,6 +130,7 @@ public final class org/jetbrains/dokka/templates/TemplatingPlugin : org/jetbrain
public final fun getPagesSearchTemplateStrategy ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getPathToRootSubstitutor ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getProjectNameSubstitutor ()Lorg/jetbrains/dokka/plugability/Extension;
+ public final fun getReplaceVersionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getSourcesetDependencyProcessingStrategy ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getSubmoduleTemplateProcessor ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getSubstitutionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension;
@@ -156,6 +157,13 @@ public final class templates/ProjectNameSubstitutor : org/jetbrains/dokka/templa
public fun trySubstitute (Lorg/jetbrains/dokka/templates/TemplatingContext;Lkotlin/text/MatchResult;)Ljava/lang/String;
}
+public final class templates/ReplaceVersionCommandHandler : org/jetbrains/dokka/templates/CommandHandler {
+ public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
+ public fun canHandle (Lorg/jetbrains/dokka/base/templating/Command;)Z
+ public fun finish (Ljava/io/File;)V
+ public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
+}
+
public final class templates/SourcesetDependencyProcessingStrategy : org/jetbrains/dokka/templates/TemplateProcessingStrategy {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun finish (Ljava/io/File;)V
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
+ }
}