aboutsummaryrefslogtreecommitdiff
path: root/plugins/all-module-page/src/main/kotlin/AllModulesPageGeneration.kt
blob: f654514a41f6e3571e3c6813133b6ff48a6dd907 (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
package org.jetbrains.dokka.allModulesPage

import org.jetbrains.dokka.CoreExtensions
import org.jetbrains.dokka.Timer
import org.jetbrains.dokka.generation.Generation
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle

class AllModulesPageGeneration(private val context: DokkaContext) : Generation {
    override fun Timer.generate() {
        report("Creating all modules page")
        val pages = createAllModulePage()

        report("Transforming pages")
        val transformedPages = transformAllModulesPage(pages)

        report("Rendering")
        render(transformedPages)

        report("Processing submodules")
        context.plugin<AllModulesPagePlugin>().querySingle { templateProcessor }.process()
    }

    override val generationName = "index page for project"

    fun createAllModulePage() = context.single(CoreExtensions.allModulePageCreator).invoke()

    fun transformAllModulesPage(pages: RootPageNode) =
        context[CoreExtensions.allModulePageTransformer].fold(pages) { acc, t -> t(acc) }

    fun render(transformedPages: RootPageNode) {
        context.single(CoreExtensions.renderer).render(transformedPages)
    }
}