diff options
Diffstat (limited to 'plugins/templating')
-rw-r--r-- | plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt | 33 | ||||
-rw-r--r-- | plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt | 7 |
2 files changed, 40 insertions, 0 deletions
diff --git a/plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt b/plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt new file mode 100644 index 00000000..11bbc39a --- /dev/null +++ b/plugins/templating/src/main/kotlin/templates/SourcesetDependencyProcessingStrategy.kt @@ -0,0 +1,33 @@ +package templates + +import org.jetbrains.dokka.base.templating.AddToSourcesetDependencies +import org.jetbrains.dokka.base.templating.parseJson +import org.jetbrains.dokka.base.templating.toJsonString +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.templates.TemplateProcessingStrategy +import java.io.File +import java.util.concurrent.ConcurrentHashMap + +private typealias Entry = Map<String, List<String>> + +class SourcesetDependencyProcessingStrategy(val context: DokkaContext) : TemplateProcessingStrategy { + private val fileName = "sourceset_dependencies.js" + private val fragments = ConcurrentHashMap<String, Entry>() + + override fun finish(output: File) { + if (fragments.isNotEmpty()) { + val content = fragments.values.fold(emptyMap<String, List<String>>()) { acc, e -> acc + e } + .let { "sourceset_dependencies = '${toJsonString(it)}'" } + output.resolve("scripts").mkdirs() + output.resolve("scripts/$fileName").writeText(content) + } + } + + override fun process(input: File, output: File): Boolean = + input.takeIf { it.name == fileName } + ?.runCatching { parseJson<AddToSourcesetDependencies>(input.readText()) } + ?.getOrNull() + ?.also { (moduleName, content) -> + fragments += (moduleName to content) + } != null +}
\ 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 546a0443..562b12c6 100644 --- a/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt +++ b/plugins/templating/src/main/kotlin/templates/TemplatingPlugin.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka.templates import org.jetbrains.dokka.allModulesPage.templates.NavigationSearchTemplateStrategy import org.jetbrains.dokka.allModulesPage.templates.PagesSearchTemplateStrategy import org.jetbrains.dokka.plugability.DokkaPlugin +import templates.SourcesetDependencyProcessingStrategy class TemplatingPlugin : DokkaPlugin() { @@ -32,6 +33,12 @@ class TemplatingPlugin : DokkaPlugin() { } } + val sourcesetDependencyProcessingStrategy by extending { + templateProcessingStrategy providing ::SourcesetDependencyProcessingStrategy order { + before(fallbackProcessingStrategy) + } + } + val pagesSearchTemplateStrategy by extending { templateProcessingStrategy providing ::PagesSearchTemplateStrategy order { before(fallbackProcessingStrategy) |