diff options
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/PackageListService.kt | 25 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/preprocessors.kt | 20 |
2 files changed, 26 insertions, 19 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/PackageListService.kt b/plugins/base/src/main/kotlin/renderers/PackageListService.kt index 3d631f5c..9b753cb1 100644 --- a/plugins/base/src/main/kotlin/renderers/PackageListService.kt +++ b/plugins/base/src/main/kotlin/renderers/PackageListService.kt @@ -2,25 +2,23 @@ package org.jetbrains.dokka.base.renderers import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.links.DRI -import org.jetbrains.dokka.links.parent import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.kotlin.utils.addToStdlib.safeAs -class PackageListService(val context: DokkaContext) { +class PackageListService(val context: DokkaContext, val rootPage: RootPageNode) { - fun formatPackageList(module: RootPageNode, format: String, linkExtension: String): String { + fun createPackageList(module: ModulePage, format: String, linkExtension: String): String { val packages = mutableSetOf<String>() val nonStandardLocations = mutableMapOf<String, String>() val locationProvider = - context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(module) - - fun visit(node: PageNode, parentDris: Set<DRI>) { + context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(rootPage) + fun visit(node: PageNode) { if (node is PackagePage) { node.name .takeUnless { name -> name.startsWith("[") && name.endsWith("]") } // Do not include the package name for declarations without one @@ -28,18 +26,19 @@ class PackageListService(val context: DokkaContext) { } val contentPage = node.safeAs<ContentPage>() - contentPage?.dri?.forEach { - if (parentDris.isNotEmpty() && it.parent !in parentDris) { - locationProvider.resolve(node) - ?.let { nodeLocation -> nonStandardLocations[it.toString()] = nodeLocation } - ?: context.logger.error("Cannot resolve path for ${node.name}!") + contentPage?.dri?.forEach { dri -> + val nodeLocation = locationProvider.resolve(node, context = module, skipExtension = true) + ?: run { context.logger.error("Cannot resolve path for ${node.name}!"); null } + + if (dri != DRI.topLevel && locationProvider.expectedLocationForDri(dri) != nodeLocation) { + nonStandardLocations[dri.toString()] = "$nodeLocation.$linkExtension" } } - node.children.forEach { visit(it, contentPage?.dri ?: setOf()) } + node.children.forEach { visit(it) } } - visit(module, setOf()) + visit(module) return buildString { appendLine("$DOKKA_PARAM_PREFIX.format:${format}") diff --git a/plugins/base/src/main/kotlin/renderers/preprocessors.kt b/plugins/base/src/main/kotlin/renderers/preprocessors.kt index 2640398c..b64d2e1f 100644 --- a/plugins/base/src/main/kotlin/renderers/preprocessors.kt +++ b/plugins/base/src/main/kotlin/renderers/preprocessors.kt @@ -10,20 +10,28 @@ object RootCreator : PageTransformer { RendererSpecificRootPage("", listOf(input), RenderingStrategy.DoNothing) } - -class PackageListCreator(val context: DokkaContext, val format: LinkFormat, val outputFilesNames: List<String> = listOf("package-list")) : PageTransformer { +class PackageListCreator( + val context: DokkaContext, + val format: LinkFormat, + val outputFilesNames: List<String> = listOf("package-list"), + val removeModulePrefix: Boolean = true +) : PageTransformer { override fun invoke(input: RootPageNode) = input.modified(children = input.children.map { it.takeUnless { it is ModulePage } - ?: it.modified(children = it.children + packageList(input)) // TODO packageList should take module as an input + ?: it.modified(children = it.children + packageList(input, it as ModulePage)) }) - private fun packageList(pageNode: RootPageNode): List<RendererSpecificPage> { - val content = PackageListService(context).formatPackageList(pageNode, format.formatName, format.linkExtension) + private fun packageList(rootPageNode: RootPageNode, module: ModulePage): List<RendererSpecificPage> { + val content = PackageListService(context, rootPageNode).createPackageList( + module, + format.formatName, + format.linkExtension + ) return outputFilesNames.map { fileName -> RendererSpecificResourcePage( - "${pageNode.name}/${fileName}", + "${rootPageNode.name}/${fileName}", emptyList(), RenderingStrategy.Write(content) ) |