From 499d082186fcda877a216d536cf9512d0f0265ac Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Tue, 15 Jul 2014 16:18:53 +0400 Subject: Cleaning, generalizing, added outline support (hardcoded yml for now) --- src/Formats/FormatService.kt | 7 ++++--- src/Formats/HtmlFormatService.kt | 11 ++++++++--- src/Formats/JekyllFormatService.kt | 2 +- src/Formats/MarkdownFormatService.kt | 27 ++++++++++++++++++++++++--- src/Formats/StructuredFormatService.kt | 26 ++++++++++++++++++++------ src/Formats/TextFormatService.kt | 5 ++++- 6 files changed, 61 insertions(+), 17 deletions(-) (limited to 'src/Formats') diff --git a/src/Formats/FormatService.kt b/src/Formats/FormatService.kt index b106692a..f890c34a 100644 --- a/src/Formats/FormatService.kt +++ b/src/Formats/FormatService.kt @@ -2,8 +2,9 @@ package org.jetbrains.dokka public trait FormatService { val extension: String - fun appendNodes(to: StringBuilder, - nodes: Iterable) + fun appendNodes(to: StringBuilder, nodes: Iterable) + fun appendOutline(to: StringBuilder, nodes: Iterable) } -fun FormatService.format(nodes: Iterable): String = StringBuilder { appendNodes(this, nodes) }.toString() \ No newline at end of file +fun FormatService.format(nodes: Iterable): String = StringBuilder { appendNodes(this, nodes) }.toString() +fun FormatService.formatOutline(nodes: Iterable): String = StringBuilder { appendOutline(this, nodes) }.toString() \ No newline at end of file diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 6c004509..6f81e8eb 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka -public open class HtmlFormatService(locationService: LocationService, signatureGenerator: SignatureGenerator) +public open class HtmlFormatService(locationService: LocationService, signatureGenerator: LanguageService) : StructuredFormatService(locationService, signatureGenerator) { override val extension: String = "html" @@ -32,8 +32,8 @@ public open class HtmlFormatService(locationService: LocationService, signatureG to.appendln("
") } - override fun formatLink(link: FormatLink): String { - return "${link.text}" + override fun formatLink(text: String, location: Location): String { + return "${text}" } override fun formatBold(text: String): String { @@ -47,4 +47,9 @@ public open class HtmlFormatService(locationService: LocationService, signatureG override fun formatBreadcrumbs(items: Iterable): String { return items.map { formatLink(it) }.joinToString(" / ") } + + override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable) { + } + override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { + } } \ No newline at end of file diff --git a/src/Formats/JekyllFormatService.kt b/src/Formats/JekyllFormatService.kt index ff53827c..aeb1e9ef 100644 --- a/src/Formats/JekyllFormatService.kt +++ b/src/Formats/JekyllFormatService.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka -public class JekyllFormatService(locationService: LocationService, signatureGenerator: SignatureGenerator) +public class JekyllFormatService(locationService: LocationService, signatureGenerator: LanguageService) : MarkdownFormatService(locationService, signatureGenerator) { override fun link(from: DocumentationNode, to: DocumentationNode): FormatLink = link(from, to, "html") diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index 2a91a4a3..6a76343d 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -1,7 +1,7 @@ package org.jetbrains.dokka -public open class MarkdownFormatService(locationService: LocationService, signatureGenerator: SignatureGenerator) +public open class MarkdownFormatService(locationService: LocationService, signatureGenerator: LanguageService) : StructuredFormatService(locationService, signatureGenerator) { override val extension: String = "md" @@ -18,8 +18,8 @@ public open class MarkdownFormatService(locationService: LocationService, signat return "**$text**" } - override public fun formatLink(link: FormatLink): String { - return "[${link.text}](${link.location.path})" + override public fun formatLink(text: String, location: Location): String { + return "[${text}](${location.path})" } override public fun appendLine(to: StringBuilder) { @@ -52,4 +52,25 @@ public open class MarkdownFormatService(locationService: LocationService, signat appendLine(to, line) appendLine(to, "```") } + + 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) { + 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/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index a490df67..bca53f4f 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -6,7 +6,7 @@ import org.jetbrains.dokka.DocumentationNode.Kind public data class FormatLink(val text: String, val location: Location) public abstract class StructuredFormatService(val locationService: LocationService, - val signatureGenerator: SignatureGenerator) : FormatService { + val languageService: LanguageService) : FormatService { abstract public fun appendBlockCode(to: StringBuilder, line: String) abstract public fun appendBlockCode(to: StringBuilder, lines: Iterable) @@ -14,7 +14,10 @@ public abstract class StructuredFormatService(val locationService: LocationServi abstract public fun appendText(to: StringBuilder, text: String) abstract public fun appendLine(to: StringBuilder, text: String) public abstract fun appendLine(to: StringBuilder) - public abstract fun formatLink(link: FormatLink): String + + public abstract fun formatLink(text: String, location: Location): String + public open fun formatLink(link: FormatLink): String = formatLink(link.text, link.location) + public abstract fun formatBold(text: String): String public abstract fun formatCode(code: String): String public abstract fun formatBreadcrumbs(items: Iterable): String @@ -30,7 +33,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi if (described.any()) { appendHeader(to, "Description") for (node in described) { - appendBlockCode(to, signatureGenerator.render(node)) + appendBlockCode(to, languageService.render(node)) appendLine(to, node.doc.description) appendLine(to) for (section in node.doc.sections) { @@ -49,7 +52,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi for ((summary, items) in breakdownBySummary) { appendLine(to, summary) - appendBlockCode(to, items.map { signatureGenerator.render(it) }) + appendBlockCode(to, items.map { languageService.render(it) }) } } @@ -86,7 +89,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi val mainMember = members.first() val displayName = when (mainMember.kind) { Kind.Constructor -> "*.init*" - else -> signatureGenerator.renderName(mainMember).htmlEscape() + else -> languageService.renderName(mainMember).htmlEscape() } appendText(to, "|${formatLink(location)}|") @@ -94,7 +97,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi val breakdownBySummary = members.groupByTo(LinkedHashMap()) { it.doc.summary } for ((summary, items) in breakdownBySummary) { appendLine(to, summary) - appendBlockCode(to, items.map { formatBold("${signatureGenerator.render(it)}") }) + appendBlockCode(to, items.map { formatBold("${languageService.render(it)}") }) } appendLine(to, "|") @@ -104,4 +107,15 @@ public abstract class StructuredFormatService(val locationService: LocationServi } } + abstract public fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) + abstract public fun appendOutlineChildren(to: StringBuilder, nodes: Iterable) + + override public fun appendOutline(to: StringBuilder, nodes: Iterable) { + 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 f309ad96..b7863c25 100644 --- a/src/Formats/TextFormatService.kt +++ b/src/Formats/TextFormatService.kt @@ -1,6 +1,6 @@ package org.jetbrains.dokka -public class TextFormatService(val signatureGenerator: SignatureGenerator) : FormatService { +public class TextFormatService(val signatureGenerator: LanguageService) : FormatService { override val extension: String = "txt" override fun appendNodes(to: StringBuilder, nodes: Iterable) { @@ -19,4 +19,7 @@ public class TextFormatService(val signatureGenerator: SignatureGenerator) : For } } } + + override fun appendOutline(to: StringBuilder, nodes: Iterable) { + } } \ No newline at end of file -- cgit