aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2020-12-17 12:14:40 +0100
committerGitHub <noreply@github.com>2020-12-17 12:14:40 +0100
commitfea7c42733a339ed19fc7471bb064f53de71cc6b (patch)
treeb3386822c1903026d079b8875bf3508ef20171e4 /plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains
parent2f7ee2b82cda39f6bd94c5200b83563418b68dd7 (diff)
downloaddokka-fea7c42733a339ed19fc7471bb064f53de71cc6b.tar.gz
dokka-fea7c42733a339ed19fc7471bb064f53de71cc6b.tar.bz2
dokka-fea7c42733a339ed19fc7471bb064f53de71cc6b.zip
Multimodule tests (#1670)
* Multimodule tests * Multimodule tests
Diffstat (limited to 'plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains')
-rw-r--r--plugins/gfm/gfm-template-processing/src/main/kotlin/org/jetbrains/dokka/gfm/templateProcessing/GfmTemplateProcessingStrategy.kt46
1 files changed, 33 insertions, 13 deletions
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
index b2ef4d06..3f2bbd3e 100644
--- 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
@@ -15,28 +15,35 @@ 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.BufferedWriter
import java.io.File
-class GfmTemplateProcessingStrategy(context: DokkaContext) : TemplateProcessingStrategy {
+class GfmTemplateProcessingStrategy(val context: DokkaContext) : TemplateProcessingStrategy {
- private val externalModuleLinkResolver = context.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver }
+ 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()
+ //This should also work whenever we have a misconfigured dokka and output is pointing to the input
+ //the same way that html processing does
+ if (input.absolutePath == output.absolutePath) {
+ context.logger.info("Attempting to process GFM templates in place for directory $input, this suggests miss configuration.")
+ val lines = reader.readLines()
+ output.bufferedWriter().use { writer ->
+ lines.forEach { line ->
+ writer.processAndWrite(line, output)
}
- } while (line != null)
+
+ }
+ } else {
+ output.bufferedWriter().use { writer ->
+ reader.lineSequence().forEach { line ->
+ writer.processAndWrite(line, output)
+ }
+ }
}
}
}
@@ -44,6 +51,19 @@ class GfmTemplateProcessingStrategy(context: DokkaContext) : TemplateProcessingS
} else false
}
+ private fun BufferedWriter.processAndWrite(line: String, output: File) =
+ processLine(line, output).run {
+ write(this)
+ newLine()
+ }
+
+ private fun processLine(line: String, output: File): String =
+ line.replace(templateCommandRegex) {
+ when (val command = parseJson<GfmCommand>(it.command)) {
+ is ResolveLinkGfmCommand -> resolveLink(output, command.dri, it.label)
+ }
+ }
+
private fun resolveLink(fileContext: File, dri: DRI, label: String): String =
externalModuleLinkResolver.resolve(dri, fileContext)?.let { address ->
"[$label]($address)"