aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-28 11:28:54 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-31 15:10:04 +0200
commit02ccae10e3f717c330dae5d87b49a0e72f798905 (patch)
tree4c63d6039fdc5a20c065724e672adbc5c6a3a0e5 /plugins/base/src/main/kotlin
parent8cd28416817dfd7d28bb66b28e849d97cc09012b (diff)
downloaddokka-02ccae10e3f717c330dae5d87b49a0e72f798905.tar.gz
dokka-02ccae10e3f717c330dae5d87b49a0e72f798905.tar.bz2
dokka-02ccae10e3f717c330dae5d87b49a0e72f798905.zip
Re-use includes form child tasks for all modules page generation
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt60
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt2
2 files changed, 35 insertions, 27 deletions
diff --git a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
index a87d4319..dab06343 100644
--- a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
+++ b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
@@ -1,9 +1,13 @@
package org.jetbrains.dokka.base.allModulePage
-import org.jetbrains.dokka.DokkaConfiguration
+import org.jetbrains.dokka.DokkaConfiguration.DokkaModuleDescription
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.base.parsers.MarkdownParser
+import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.Module
+import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentationParsingContext
+import org.jetbrains.dokka.base.parsers.moduleAndPackage.parseModuleAndPackageDocumentation
+import org.jetbrains.dokka.base.parsers.moduleAndPackage.parseModuleAndPackageDocumentationFragments
import org.jetbrains.dokka.base.resolvers.local.MultimoduleLocationProvider.Companion.MULTIMODULE_PACKAGE_PLACEHOLDER
import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
@@ -11,21 +15,19 @@ import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.model.doc.P
import org.jetbrains.dokka.pages.*
-import org.jetbrains.dokka.base.parsers.MarkdownParser
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageCreator
import org.jetbrains.dokka.utilities.DokkaLogger
-class MultimodulePageCreator(
- val context: DokkaContext
+class MultimodulePageCreator (
+ private val context: DokkaContext,
) : PageCreator {
private val logger: DokkaLogger = context.logger
override fun invoke(): RootPageNode {
val parser = MarkdownParser(logger = logger)
val modules = context.configuration.modules
- modules.forEach(::throwOnMissingModuleDocFile)
val commentsConverter = context.plugin(DokkaBase::class)?.querySingle { commentsToContentConverter }
val signatureProvider = context.plugin(DokkaBase::class)?.querySingle { signatureProvider }
@@ -41,20 +43,22 @@ class MultimodulePageCreator(
) {
header(2, "All modules:")
table(styles = setOf(MultimoduleTable)) {
- modules.mapNotNull { module ->
- val paragraph = module.docFile.readText().let { parser.parse(it).firstParagraph() }
- paragraph?.let {
- val dri = DRI(packageName = MULTIMODULE_PACKAGE_PLACEHOLDER, classNames = module.name)
- val dci = DCI(setOf(dri), ContentKind.Comment)
- val header = linkNode(module.name, dri)
- val content = ContentGroup(
- DocTagToContentConverter.buildContent(it, dci, emptySet()),
- dci,
- emptySet(),
- emptySet()
- )
- ContentGroup(listOf(header, content), dci, emptySet(), emptySet())
- }
+ modules.map { module ->
+ val displayedModuleDocumentation = getDisplayedModuleDocumentation(module)
+ val dri = DRI(packageName = MULTIMODULE_PACKAGE_PLACEHOLDER, classNames = module.name)
+ val dci = DCI(setOf(dri), ContentKind.Comment)
+ val header =
+ ContentHeader(listOf(linkNode(module.name, dri)), 2, dci, emptySet(), emptySet())
+ val content = ContentGroup(
+ children =
+ if (displayedModuleDocumentation != null)
+ DocTagToContentConverter.buildContent(displayedModuleDocumentation, dci, emptySet())
+ else emptyList(),
+ dci = dci,
+ sourceSets = emptySet(),
+ style = emptySet()
+ )
+ ContentGroup(listOf(header, content), dci, emptySet(), emptySet())
}
}
}
@@ -65,12 +69,16 @@ class MultimodulePageCreator(
)
}
- private fun throwOnMissingModuleDocFile(module: DokkaConfiguration.DokkaModuleDescription) {
- if (!module.docFile.exists() || !module.docFile.isFile) {
- throw DokkaException(
- "Missing documentation file for module ${module.name}: ${module.docFile.absolutePath}"
- )
- }
+ private fun getDisplayedModuleDocumentation(module: DokkaModuleDescription): P? {
+ val parsingContext = ModuleAndPackageDocumentationParsingContext(logger)
+ return module.includes
+ .flatMap { include -> parseModuleAndPackageDocumentationFragments(include) }
+ .map { fragment -> parseModuleAndPackageDocumentation(parsingContext, fragment) }
+ .firstOrNull { documentation -> documentation.classifier == Module && documentation.name == module.name }
+ ?.documentation?.children.orEmpty()
+ .flatMap { it.root.children }
+ .filterIsInstance<P>()
+ .firstOrNull()
}
private fun DocumentationNode.firstParagraph() =
diff --git a/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt
index 3e0122bf..b5891dbf 100644
--- a/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt
+++ b/plugins/base/src/main/kotlin/resolvers/local/MultimoduleLocationProvider.kt
@@ -12,7 +12,7 @@ class MultimoduleLocationProvider(private val root: RootPageNode, context: Dokka
private val defaultLocationProvider = DokkaLocationProvider(root, context)
val paths = context.configuration.modules.map {
- it.name to it.path
+ it.name to it.relativePathToOutputDirectory
}.toMap()
override fun resolve(dri: DRI, sourceSets: Set<DisplaySourceSet>, context: PageNode?) =