aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/OutlineService.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/Formats/OutlineService.kt')
-rw-r--r--src/Formats/OutlineService.kt30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Formats/OutlineService.kt b/src/Formats/OutlineService.kt
new file mode 100644
index 00000000..db1adf3d
--- /dev/null
+++ b/src/Formats/OutlineService.kt
@@ -0,0 +1,30 @@
+package org.jetbrains.dokka
+
+import java.io.File
+
+/**
+ * Service for building the outline of the package contents.
+ */
+public trait 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.sortBy { it.name }
+ appendOutlineLevel(to) {
+ appendOutline(location, to, sortedMembers)
+ }
+ }
+ to.appendln()
+ }
+ }
+
+ fun formatOutline(location: Location, nodes: Iterable<DocumentationNode>): String =
+ StringBuilder { appendOutline(location, this, nodes) }.toString()
+}