aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/OutlineService.kt
blob: 6626cf51f2b5eba2e2b208cecb33bcc7a50b0f50 (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
package org.jetbrains.dokka

import java.io.File

/**
 * Service for building the outline of the package contents.
 */
public interface OutlineFormatService {
    fun getOutlineFileName(location: Location): File

    public fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder)
    public fun appendOutlineLevel(to: StringBuilder, body: () -> Unit)

    /** Appends formatted outline to [StringBuilder](to) using specified [location] */
    public fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
        for (node in nodes) {
            appendOutlineHeader(location, node, to)
            if (node.members.any()) {
                val sortedMembers = node.members.sortedBy { it.name }
                appendOutlineLevel(to) {
                    appendOutline(location, to, sortedMembers)
                }
            }
        }
    }

    fun formatOutline(location: Location, nodes: Iterable<DocumentationNode>): String =
            StringBuilder().apply { appendOutline(location, this, nodes) }.toString()
}