aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
-rw-r--r--plugins/base/src/main/kotlin/renderers/PackageListService.kt29
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt10
-rw-r--r--plugins/base/src/main/kotlin/renderers/preprocessors.kt18
3 files changed, 30 insertions, 27 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/PackageListService.kt b/plugins/base/src/main/kotlin/renderers/PackageListService.kt
index 9b753cb1..2bf66ebf 100644
--- a/plugins/base/src/main/kotlin/renderers/PackageListService.kt
+++ b/plugins/base/src/main/kotlin/renderers/PackageListService.kt
@@ -1,6 +1,10 @@
package org.jetbrains.dokka.base.renderers
import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.base.resolvers.shared.LinkFormat
+import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.DOKKA_PARAM_PREFIX
+import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.SINGLE_MODULE_NAME
+import org.jetbrains.dokka.base.resolvers.shared.PackageList.Companion.MODULE_DELIMITER
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
@@ -10,7 +14,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class PackageListService(val context: DokkaContext, val rootPage: RootPageNode) {
- fun createPackageList(module: ModulePage, format: String, linkExtension: String): String {
+ fun createPackageList(module: ModulePage, format: LinkFormat): String {
val packages = mutableSetOf<String>()
val nonStandardLocations = mutableMapOf<String, String>()
@@ -31,7 +35,7 @@ class PackageListService(val context: DokkaContext, val rootPage: RootPageNode)
?: run { context.logger.error("Cannot resolve path for ${node.name}!"); null }
if (dri != DRI.topLevel && locationProvider.expectedLocationForDri(dri) != nodeLocation) {
- nonStandardLocations[dri.toString()] = "$nodeLocation.$linkExtension"
+ nonStandardLocations[dri.toString()] = "$nodeLocation.${format.linkExtension}"
}
}
@@ -39,19 +43,22 @@ class PackageListService(val context: DokkaContext, val rootPage: RootPageNode)
}
visit(module)
+ return renderPackageList(nonStandardLocations, mapOf(SINGLE_MODULE_NAME to packages), format.formatName, format.linkExtension)
+ }
- return buildString {
+ companion object {
+ fun renderPackageList(nonStandardLocations: Map<String, String>, modules: Map<String, Set<String>>, format: String, linkExtension: String): String = buildString {
appendLine("$DOKKA_PARAM_PREFIX.format:${format}")
appendLine("$DOKKA_PARAM_PREFIX.linkExtension:${linkExtension}")
- nonStandardLocations.map { (signature, location) -> "$DOKKA_PARAM_PREFIX.location:$signature\u001f$location" }
- .sorted().joinTo(this, separator = "\n", postfix = "\n")
+ nonStandardLocations.map { (signature, location) ->
+ "$DOKKA_PARAM_PREFIX.location:$signature\u001f$location"
+ }.sorted().joinTo(this, separator = "\n", postfix = "\n")
- packages.sorted().joinTo(this, separator = "\n", postfix = "\n")
+ modules.mapNotNull { (module, packages) ->
+ ("$MODULE_DELIMITER$module\n".takeIf { module != SINGLE_MODULE_NAME }.orEmpty() +
+ packages.filter(String::isNotBlank).sorted().joinToString(separator = "\n"))
+ .takeIf { packages.isNotEmpty() }
+ }.joinTo(this, separator = "\n", postfix = "\n")
}
-
- }
-
- companion object {
- const val DOKKA_PARAM_PREFIX = "\$dokka"
}
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index 92f7324c..ff724f02 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -15,8 +15,8 @@ import org.jetbrains.dokka.plugability.configuration
import org.jetbrains.dokka.transformers.pages.PageTransformer
abstract class NavigationDataProvider {
- open fun navigableChildren(input: RootPageNode): NavigationNode =
- input.children.filterIsInstance<ContentPage>().single().let { visit(it) }
+ open fun navigableChildren(input: RootPageNode): NavigationNode = input.withDescendants()
+ .first { it is ModulePage || it is MultimoduleRootPage }.let { visit(it as ContentPage) }
open fun visit(page: ContentPage): NavigationNode =
NavigationNode(
@@ -167,9 +167,9 @@ private fun List<String>.toRenderSpecificResourcePage(): List<RendererSpecificRe
class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer {
private val name = "scripts/sourceset_dependencies.js"
override fun invoke(input: RootPageNode): RootPageNode {
- val dependenciesMap = context.configuration.sourceSets.map {
+ val dependenciesMap = context.configuration.sourceSets.associate {
it.sourceSetID to it.dependentSourceSets
- }.toMap()
+ }
fun createDependenciesJson(): String =
dependenciesMap.map { (key, values) -> key.toString() to values.map { it.toString() } }.toMap()
@@ -191,4 +191,4 @@ class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer {
children = input.children + deps
).transformContentPagesTree { it.modified(embeddedResources = it.embeddedResources + name) }
}
-} \ No newline at end of file
+}
diff --git a/plugins/base/src/main/kotlin/renderers/preprocessors.kt b/plugins/base/src/main/kotlin/renderers/preprocessors.kt
index b64d2e1f..1a41162d 100644
--- a/plugins/base/src/main/kotlin/renderers/preprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/preprocessors.kt
@@ -1,6 +1,7 @@
package org.jetbrains.dokka.base.renderers
import org.jetbrains.dokka.base.resolvers.shared.LinkFormat
+import org.jetbrains.dokka.model.withDescendants
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -13,25 +14,20 @@ object RootCreator : PageTransformer {
class PackageListCreator(
val context: DokkaContext,
val format: LinkFormat,
- val outputFilesNames: List<String> = listOf("package-list"),
- val removeModulePrefix: Boolean = true
+ val outputFilesNames: List<String> = listOf("package-list")
) : PageTransformer {
- override fun invoke(input: RootPageNode) =
- input.modified(children = input.children.map {
- it.takeUnless { it is ModulePage }
- ?: it.modified(children = it.children + packageList(input, it as ModulePage))
- })
-
+ override fun invoke(input: RootPageNode) = input.transformPageNodeTree { pageNode ->
+ pageNode.takeIf { it is ModulePage }?.let { it.modified(children = it.children + packageList(input, it as ModulePage)) } ?: pageNode
+ }
private fun packageList(rootPageNode: RootPageNode, module: ModulePage): List<RendererSpecificPage> {
val content = PackageListService(context, rootPageNode).createPackageList(
module,
- format.formatName,
- format.linkExtension
+ format
)
return outputFilesNames.map { fileName ->
RendererSpecificResourcePage(
- "${rootPageNode.name}/${fileName}",
+ fileName,
emptyList(),
RenderingStrategy.Write(content)
)