aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/gfm-all-module-page
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/gfm/gfm-all-module-page')
-rw-r--r--plugins/gfm/gfm-all-module-page/build.gradle.kts3
-rw-r--r--plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt8
-rw-r--r--plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt30
-rw-r--r--plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt45
4 files changed, 59 insertions, 27 deletions
diff --git a/plugins/gfm/gfm-all-module-page/build.gradle.kts b/plugins/gfm/gfm-all-module-page/build.gradle.kts
index 66deb291..85f83587 100644
--- a/plugins/gfm/gfm-all-module-page/build.gradle.kts
+++ b/plugins/gfm/gfm-all-module-page/build.gradle.kts
@@ -4,6 +4,9 @@ dependencies {
implementation(project(":plugins:base"))
implementation(project(":plugins:gfm"))
implementation(project(":plugins:all-module-page"))
+
+ val coroutines_version: String by project
+ implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
}
registerDokkaArtifactPublication("dokkaGfmAllModulePage") {
diff --git a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt
index 8052a762..eb5e7e45 100644
--- a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt
+++ b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmAllModulesPagaPlugin.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.gfm.allModulesPage
import org.jetbrains.dokka.allModulesPage.AllModulesPagePlugin
+import org.jetbrains.dokka.allModulesPage.templates.DefaultTemplateProcessor
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.gfm.GfmPlugin
import org.jetbrains.dokka.plugability.DokkaPlugin
@@ -17,4 +18,11 @@ class GfmAllModulesPagePlugin : DokkaPlugin() {
(dokkaBase.locationProviderFactory providing GfmMultimoduleLocationProvider::Factory
override listOf(allModulesPagePlugin.multimoduleLocationProvider, gfmPlugin.locationProvider))
}
+
+ val defaultTemplateProcessor by extending {
+ (allModulesPagePlugin.templateProcessingStrategy
+ providing ::GfmTemplateProcessingStrategy
+ override allModulesPagePlugin.directiveBasedHtmlTemplateProcessingStrategy
+ order { before(allModulesPagePlugin.fallbackProcessingStrategy) })
+ }
} \ No newline at end of file
diff --git a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt
index d49be426..9f2ee140 100644
--- a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt
+++ b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmMultimoduleLocationProvider.kt
@@ -1,38 +1,14 @@
package org.jetbrains.dokka.gfm.allModulesPage
-import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider
-import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider
+import org.jetbrains.dokka.allModulesPage.MultimoduleLocationProvider
import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory
import org.jetbrains.dokka.gfm.location.MarkdownLocationProvider
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.DisplaySourceSet
-import org.jetbrains.dokka.pages.PageNode
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
-class GfmMultimoduleLocationProvider(private val root: RootPageNode, context: DokkaContext) : DokkaBaseLocationProvider(root, context, ".md") {
+class GfmMultimoduleLocationProvider(root: RootPageNode, context: DokkaContext) : MultimoduleLocationProvider(root, context, ".md") {
- private val defaultLocationProvider = MarkdownLocationProvider(root, context)
-
- val paths = context.configuration.modules.map {
- it.name to it.relativePathToOutputDirectory
- }.toMap()
-
- override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) =
- dri.takeIf { it.packageName == MULTIMODULE_PACKAGE_PLACEHOLDER }?.classNames?.let { paths[it] }?.let {
- "$it/${DokkaLocationProvider.identifierToFilename(dri.classNames.orEmpty())}/index.md"
- } ?: defaultLocationProvider.resolve(dri, sourceSets, context)
-
- override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) =
- defaultLocationProvider.resolve(node, context, skipExtension)
-
- override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from)
-
- override fun ancestors(node: PageNode): List<PageNode> = listOf(root)
-
- companion object {
- const val MULTIMODULE_PACKAGE_PLACEHOLDER = ".ext"
- }
+ override val defaultLocationProvider = MarkdownLocationProvider(root, context)
class Factory(private val context: DokkaContext): LocationProviderFactory {
override fun getLocationProvider(pageNode: RootPageNode) =
diff --git a/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt
new file mode 100644
index 00000000..37226d1e
--- /dev/null
+++ b/plugins/gfm/gfm-all-module-page/src/main/kotlin/org/jetbrains/dokka/gfm/allModulesPage/GfmTemplateProcessingStrategy.kt
@@ -0,0 +1,45 @@
+package org.jetbrains.dokka.gfm.allModulesPage
+
+import kotlinx.coroutines.Dispatchers.IO
+import kotlinx.coroutines.coroutineScope
+import kotlinx.coroutines.launch
+import org.jetbrains.dokka.allModulesPage.templates.ExternalModuleLinkResolver
+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.templateCommandRegex
+import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.plugability.DokkaContext
+import java.io.File
+
+class GfmTemplateProcessingStrategy(val context: DokkaContext) : TemplateProcessingStrategy {
+
+ private val externalModuleLinkResolver = ExternalModuleLinkResolver(context)
+
+ override suspend fun process(input: File, output: File): Boolean = coroutineScope {
+ if (input.extension == "md") {
+ launch(IO) {
+ val reader = input.bufferedReader()
+ val writer = output.bufferedWriter()
+ do {
+ val line = reader.readLine()
+ if (line != null) {
+ writer.write(line.replace(templateCommandRegex) {
+ when (val command = parseJson<GfmCommand>(it.groupValues.last())) {
+ is ResolveLinkGfmCommand -> resolveLink(output, command.dri)
+ }
+ })
+ writer.newLine()
+ }
+ } while (line != null)
+ reader.close()
+ writer.close()
+ }
+ true
+ } else false
+ }
+
+ private fun resolveLink(fileContext: File, dri: DRI): String =
+ externalModuleLinkResolver.resolve(dri, fileContext) ?: ""
+} \ No newline at end of file