aboutsummaryrefslogtreecommitdiff
path: root/plugins/all-modules-page
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-03-26 17:35:44 +0100
committerGitHub <noreply@github.com>2021-03-26 17:35:44 +0100
commit9589161d9861a1d2eb02df1c5858b3ff67ca0c7a (patch)
tree308e7d2bcd682e08812e6b68fc182eb276475562 /plugins/all-modules-page
parentac4b818a8616e4de8f702167fe6ddbe911df5d24 (diff)
downloaddokka-9589161d9861a1d2eb02df1c5858b3ff67ca0c7a.tar.gz
dokka-9589161d9861a1d2eb02df1c5858b3ff67ca0c7a.tar.bz2
dokka-9589161d9861a1d2eb02df1c5858b3ff67ca0c7a.zip
Reintroduce multimodule documentation (#1804)
Diffstat (limited to 'plugins/all-modules-page')
-rw-r--r--plugins/all-modules-page/build.gradle.kts1
-rw-r--r--plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt14
-rw-r--r--plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt65
3 files changed, 80 insertions, 0 deletions
diff --git a/plugins/all-modules-page/build.gradle.kts b/plugins/all-modules-page/build.gradle.kts
index 9c5fe1c3..0fe46579 100644
--- a/plugins/all-modules-page/build.gradle.kts
+++ b/plugins/all-modules-page/build.gradle.kts
@@ -12,6 +12,7 @@ dependencies {
testImplementation(project(":plugins:base:base-test-utils"))
testImplementation(project(":plugins:gfm"))
testImplementation(project(":plugins:gfm:gfm-template-processing"))
+ testImplementation(project(":core:content-matcher-test-utils"))
val coroutines_version: String by project
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
diff --git a/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt b/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt
index c84aef7e..782ee16e 100644
--- a/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt
+++ b/plugins/all-modules-page/src/main/kotlin/MultimodulePageCreator.kt
@@ -3,6 +3,7 @@ package org.jetbrains.dokka.allModulesPage
import org.jetbrains.dokka.DokkaConfiguration.DokkaModuleDescription
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
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
@@ -26,6 +27,7 @@ import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.versioning.ReplaceVersionsCommand
import org.jetbrains.dokka.versioning.VersioningConfiguration
import org.jetbrains.dokka.versioning.VersioningPlugin
+import java.io.File
class MultimodulePageCreator(
private val context: DokkaContext,
@@ -49,6 +51,15 @@ class MultimodulePageCreator(
configuration<VersioningPlugin, VersioningConfiguration>(context)?.let {
group(extra = PropertyContainer.withAll(InsertTemplateExtra(ReplaceVersionsCommand))) { }
}
+ getMultiModuleDocumentation(context.configuration.includes).takeIf { it.isNotEmpty() }?.let { nodes ->
+ group(kind = ContentKind.Cover) {
+ nodes.forEach { node ->
+ group {
+ node.children.forEach { comment(it.root) }
+ }
+ }
+ }
+ }
header(2, "All modules:")
table(styles = setOf(MultimoduleTable)) {
header { group { text("Name") } }
@@ -83,6 +94,9 @@ class MultimodulePageCreator(
)
}
+ private fun getMultiModuleDocumentation(files: Set<File>): List<DocumentationNode> =
+ files.map { MarkdownParser({ null }, it.absolutePath).parse(it.readText()) }
+
private fun getDisplayedModuleDocumentation(module: DokkaModuleDescription): P? {
val parsingContext = ModuleAndPackageDocumentationParsingContext(logger)
diff --git a/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt b/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt
new file mode 100644
index 00000000..11a03bc4
--- /dev/null
+++ b/plugins/all-modules-page/src/test/kotlin/templates/MultiModuleDocumentationTest.kt
@@ -0,0 +1,65 @@
+package org.jetbrains.dokka.allModulesPage.templates
+
+import matchers.content.*
+import org.jetbrains.dokka.allModulesPage.MultiModuleAbstractTest
+import org.jetbrains.dokka.model.dfs
+import org.jetbrains.dokka.pages.ContentKind
+import org.jetbrains.dokka.pages.ContentResolvedLink
+import org.jetbrains.dokka.pages.MultimoduleRootPageNode
+import org.junit.Rule
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
+import org.junit.rules.TemporaryFolder
+import kotlin.test.assertEquals
+
+class MultiModuleDocumentationTest : MultiModuleAbstractTest() {
+ @get:Rule
+ val folder: TemporaryFolder = TemporaryFolder()
+
+ val documentationContent = """
+ # Sample project
+ Sample documentation with [external link](https://www.google.pl)
+ """.trimIndent()
+
+ @BeforeEach
+ fun setup() {
+ folder.create()
+ folder.root.resolve("README.md").writeText(documentationContent)
+ }
+
+ @Test
+ fun `documentation should be included in all modules page`() {
+ val configuration = dokkaConfiguration {
+ includes = listOf(folder.root.resolve("README.md"))
+ }
+
+ testFromData(configuration, preserveOutputLocation = true) {
+ allModulesPageCreationStage = { rootPage ->
+ (rootPage as? MultimoduleRootPageNode)?.content?.dfs { it.dci.kind == ContentKind.Cover }?.children?.firstOrNull()
+ ?.assertNode {
+ group {
+ group {
+ group {
+ header(1) {
+ +"Sample project"
+ }
+ group {
+ +"Sample documentation with "
+ link {
+ +"external link"
+ check {
+ assertEquals(
+ "https://www.google.pl",
+ (this as ContentResolvedLink).address
+ )
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+} \ No newline at end of file