aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/gfm-template-processing
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-11-20 17:23:10 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2020-11-27 03:15:02 +0100
commit3cb4702a68139788de6e1f7b087ced345f2b71ba (patch)
treea383471c9915ae4aaff078b4f3b81bb99a4fde35 /plugins/gfm/gfm-template-processing
parent076a5f421c5e4621539efd814be612f43fef33f5 (diff)
downloaddokka-3cb4702a68139788de6e1f7b087ced345f2b71ba.tar.gz
dokka-3cb4702a68139788de6e1f7b087ced345f2b71ba.tar.bz2
dokka-3cb4702a68139788de6e1f7b087ced345f2b71ba.zip
Changing how multimodule location provider works and improving gfm link substitution
Diffstat (limited to 'plugins/gfm/gfm-template-processing')
-rw-r--r--plugins/gfm/gfm-template-processing/build.gradle.kts14
-rw-r--r--plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt31
-rw-r--r--plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt51
-rw-r--r--plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin1
4 files changed, 97 insertions, 0 deletions
diff --git a/plugins/gfm/gfm-template-processing/build.gradle.kts b/plugins/gfm/gfm-template-processing/build.gradle.kts
new file mode 100644
index 00000000..f95ef0e4
--- /dev/null
+++ b/plugins/gfm/gfm-template-processing/build.gradle.kts
@@ -0,0 +1,14 @@
+import org.jetbrains.registerDokkaArtifactPublication
+
+dependencies {
+ implementation(project(":plugins:base"))
+ implementation(project(":plugins:gfm"))
+ implementation(project(":plugins:all-modules-page"))
+
+ val coroutines_version: String by project
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
+}
+
+registerDokkaArtifactPublication("dokkaGfmTemplateProcessing") {
+ artifactId = "gfm-template-processing-plugin"
+} \ No newline at end of file
diff --git a/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt
new file mode 100644
index 00000000..7df740a5
--- /dev/null
+++ b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingPlugin.kt
@@ -0,0 +1,31 @@
+package org.jetbrains.dokka.gfm.templateProcessing
+
+import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin
+import org.jetbrains.dokka.allModulesPage.MultimoduleLocationProvider
+import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.gfm.GfmPlugin
+import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider
+import org.jetbrains.dokka.plugability.DokkaPlugin
+
+class GfmTemplateProcessingPlugin : DokkaPlugin() {
+
+ private val allModulesPagePlugin by lazy { plugin<AllModulesPagePlugin>() }
+
+ private val gfmPlugin by lazy { plugin<GfmPlugin>() }
+
+ private val dokkaBase by lazy { plugin<DokkaBase>()}
+
+ val gfmTemplateProcessingStrategy by extending {
+ (allModulesPagePlugin.templateProcessingStrategy
+ providing ::GfmTemplateProcessingStrategy
+ order { before(allModulesPagePlugin.fallbackProcessingStrategy) })
+ }
+
+ val gfmLocationProvider by extending {
+ dokkaBase.locationProviderFactory providing MultimoduleLocationProvider::Factory override listOf(gfmPlugin.locationProvider, allModulesPagePlugin.multimoduleLocationProvider)
+ }
+
+ val gfmPartialLocationProvider by extending {
+ allModulesPagePlugin.partialLocationProviderFactory providing MarkdownLocationProvider::Factory override allModulesPagePlugin.baseLocationProviderFactory
+ }
+} \ No newline at end of file
diff --git a/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt
new file mode 100644
index 00000000..b2ef4d06
--- /dev/null
+++ b/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt
@@ -0,0 +1,51 @@
+package org.jetbrains.dokka.gfm.templateProcessing
+
+import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.launch
+import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin
+import org.jetbrains.dokka.allModulesPage.templates.TemplateProcessingStrategy
+import org.jetbrains.dokka.base.templating.parseJson
+import org.jetbrains.dokka.gfm.GfmCommand
+import org.jetbrains.dokka.gfm.GfmCommand.Companion.command
+import org.jetbrains.dokka.gfm.GfmCommand.Companion.label
+import org.jetbrains.dokka.gfm.GfmCommand.Companion.templateCommandRegex
+import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.plugability.plugin
+import org.jetbrains.dokka.plugability.querySingle
+import java.io.File
+
+class GfmTemplateProcessingStrategy(context: DokkaContext) : TemplateProcessingStrategy {
+
+ private val externalModuleLinkResolver = context.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver }
+
+ override suspend fun process(input: File, output: File): Boolean = coroutineScope {
+ if (input.extension == "md") {
+ launch(IO) {
+ input.bufferedReader().use { reader ->
+ output.bufferedWriter().use { writer ->
+ do {
+ val line = reader.readLine()
+ if (line != null) {
+ writer.write(line.replace(templateCommandRegex) {
+ when (val command = parseJson<GfmCommand>(it.command)) {
+ is ResolveLinkGfmCommand -> resolveLink(output, command.dri, it.label)
+ }
+ })
+ writer.newLine()
+ }
+ } while (line != null)
+ }
+ }
+ }
+ true
+ } else false
+ }
+
+ private fun resolveLink(fileContext: File, dri: DRI, label: String): String =
+ externalModuleLinkResolver.resolve(dri, fileContext)?.let { address ->
+ "[$label]($address)"
+ } ?: label
+} \ No newline at end of file
diff --git a/plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin b/plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
new file mode 100644
index 00000000..197823e7
--- /dev/null
+++ b/plugins/gfm/gfm-template-processing/src/main/resources/META-INF/services/org.jetbrains.dokka.plugability.DokkaPlugin
@@ -0,0 +1 @@
+org.jetbrains.dokka.gfm.templateProcessing.GfmTemplateProcessingPlugin \ No newline at end of file