aboutsummaryrefslogtreecommitdiff
path: root/src/Generation/ConsoleGenerator.kt
blob: f52c6f4b258d3c1f02f77c881622db241560df15 (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
42
package org.jetbrains.dokka

public class ConsoleGenerator(val signatureGenerator: LanguageService, val locationService: LocationService) {
    val IndentStep = "  "

    public fun generate(node: DocumentationNode, indent: String = "") {
        println("@${locationService.location(node).file}")
        generateHeader(node, indent)
        //generateDetails(node, indent)
        generateMembers(node, indent)
        generateLinks(node, indent)
    }

    public fun generateHeader(node: DocumentationNode, indent: String = "") {
        println(indent + signatureGenerator.render(node))
        val docString = node.content.toString()
        if (!docString.isEmpty())
            println("$indent\"${docString.replace("\n", "\n$indent")}\"")
        println()
    }

    public fun generateMembers(node: DocumentationNode, indent: String = "") {
        val items = node.members.sortBy { it.name }
        for (child in items)
            generate(child, indent + IndentStep)
    }

    public fun generateDetails(node: DocumentationNode, indent: String = "") {
        val items = node.details
        for (child in items)
            generate(child, indent + "  ")
    }

    public fun generateLinks(node: DocumentationNode, indent: String = "") {
        val items = node.links
        if (items.isEmpty())
            return
        println("$indent Links")
        for (child in items)
            generate(child, indent + "  ")
    }
}