diff options
Diffstat (limited to 'src/Formats')
-rw-r--r-- | src/Formats/FormatService.kt | 6 | ||||
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 26 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 21 | ||||
-rw-r--r-- | src/Formats/OutlineService.kt | 30 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 12 | ||||
-rw-r--r-- | src/Formats/TextFormatService.kt | 3 | ||||
-rw-r--r-- | src/Formats/YamlOutlineService.kt | 23 |
7 files changed, 76 insertions, 45 deletions
diff --git a/src/Formats/FormatService.kt b/src/Formats/FormatService.kt index bb6da985..cc190346 100644 --- a/src/Formats/FormatService.kt +++ b/src/Formats/FormatService.kt @@ -14,13 +14,7 @@ public trait FormatService { /** Appends formatted content to [StringBuilder](to) using specified [location] */ fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) - - /** Appends formatted outline to [StringBuilder](to) using specified [location] */ - fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) } /** Format content to [String] using specified [location] */ fun FormatService.format(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder { appendNodes(location, this, nodes) }.toString() - -/** Format outline to [String] using specified [location] */ -fun FormatService.formatOutline(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder { appendOutline(location, this, nodes) }.toString()
\ No newline at end of file diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index f76693dc..859c07e0 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -1,9 +1,11 @@ package org.jetbrains.dokka +import java.io.File + public open class HtmlFormatService(locationService: LocationService, signatureGenerator: LanguageService, val templateService: HtmlTemplateService = HtmlTemplateService.default()) -: StructuredFormatService(locationService, signatureGenerator) { +: StructuredFormatService(locationService, signatureGenerator), OutlineFormatService { override val extension: String = "html" override public fun formatText(text: String): String { @@ -120,8 +122,26 @@ public open class HtmlFormatService(locationService: LocationService, templateService.appendFooter(to) } - override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) { + override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { + templateService.appendHeader(to) + super<OutlineFormatService>.appendOutline(location, to, nodes) + templateService.appendFooter(to) + } + + override fun getOutlineFileName(location: Location): File { + return File("${location.path}-outline.html") } - override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { + + override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) { + val link = ContentNodeLink(node) + link.append(languageService.render(node, LanguageService.RenderMode.FULL)) + val signature = formatText(location, link) + to.appendln("${formatLink(signature, location)}<br/>") + } + + override fun appendOutlineLevel(to: StringBuilder, body: () -> Unit) { + to.appendln("<ul>") + body() + to.appendln("</ul>") } }
\ No newline at end of file diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index a2e3ce55..3598f29d 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -120,25 +120,4 @@ public open class MarkdownFormatService(locationService: LocationService, body() to.append(" |") } - - var outlineLevel = 0 - override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { - val indent = " ".repeat(outlineLevel) - appendLine(to, "$indent- title: ${languageService.renderName(node)}") - appendLine(to, "$indent url: ${locationService.location(node).path}") - } - - override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) { - val indent = " ".repeat(outlineLevel) - appendLine(to, "$indent content:") - outlineLevel++ - for (node in nodes) { - appendOutlineHeader(to, node) - if (node.members.any()) { - appendOutlineChildren(to, node.members) - } - appendLine(to) - } - outlineLevel-- - } } 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() +} diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 458fda35..d2fbdc10 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -263,16 +263,4 @@ public abstract class StructuredFormatService(val locationService: LocationServi } } - - abstract public fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) - abstract public fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) - - public override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { - for (node in nodes) { - appendOutlineHeader(to, node) - if (node.members.any()) { - appendOutlineChildren(to, node.members) - } - } - } }
\ No newline at end of file diff --git a/src/Formats/TextFormatService.kt b/src/Formats/TextFormatService.kt index 4e43cbcc..9db20dfa 100644 --- a/src/Formats/TextFormatService.kt +++ b/src/Formats/TextFormatService.kt @@ -15,7 +15,4 @@ public class TextFormatService(val signatureGenerator: LanguageService) : Format } } } - - override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { - } }
\ No newline at end of file diff --git a/src/Formats/YamlOutlineService.kt b/src/Formats/YamlOutlineService.kt new file mode 100644 index 00000000..cdab4eeb --- /dev/null +++ b/src/Formats/YamlOutlineService.kt @@ -0,0 +1,23 @@ +package org.jetbrains.dokka + +import java.io.File + +class YamlOutlineService(val locationService: LocationService, + val languageService: LanguageService) : OutlineFormatService { + override fun getOutlineFileName(location: Location): File = File("${location.path}.yml") + + var outlineLevel = 0 + override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) { + val indent = " ".repeat(outlineLevel) + to.appendln("$indent- title: ${languageService.renderName(node)}") + to.appendln("$indent url: ${locationService.location(node).path}") + } + + override fun appendOutlineLevel(to: StringBuilder, body: () -> Unit) { + val indent = " ".repeat(outlineLevel) + to.appendln("$indent content:") + outlineLevel++ + body() + outlineLevel-- + } +} |