aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers/preprocessors.kt
blob: a3a32651a77b1e0e51ea7cf9e07a4f3cbf3d9b13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.base.renderers

import org.jetbrains.dokka.base.resolvers.shared.LinkFormat
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer

public object RootCreator : PageTransformer {
    override fun invoke(input: RootPageNode): RootPageNode =
        RendererSpecificRootPage("", listOf(input), RenderingStrategy.DoNothing)
}

public class PackageListCreator(
    public val context: DokkaContext,
    public val format: LinkFormat,
    public val outputFilesNames: List<String> = listOf("package-list")
) : PageTransformer {
    override fun invoke(input: RootPageNode): RootPageNode {
        return 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
        )
        return outputFilesNames.map { fileName ->
            RendererSpecificResourcePage(
                fileName,
                emptyList(),
                RenderingStrategy.Write(content)
            )
        }
    }
}