From a0bfdbd8cc365cb11c26e81ee7587f0ec25df79d Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Mon, 14 Jul 2014 15:00:33 +0400 Subject: Location services, formatting services, initial self-documentation output. --- src/Formats/FormatService.kt | 8 +++++ src/Formats/HtmlFormatService.kt | 62 ++++++++++++++++++++++++++++++++++++ src/Formats/MarkdownFormatService.kt | 34 ++++++++++++++++++++ src/Formats/TextFormatService.kt | 19 +++++++++++ 4 files changed, 123 insertions(+) create mode 100644 src/Formats/FormatService.kt create mode 100644 src/Formats/HtmlFormatService.kt create mode 100644 src/Formats/MarkdownFormatService.kt create mode 100644 src/Formats/TextFormatService.kt (limited to 'src/Formats') diff --git a/src/Formats/FormatService.kt b/src/Formats/FormatService.kt new file mode 100644 index 00000000..9e36c400 --- /dev/null +++ b/src/Formats/FormatService.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka + +public trait FormatService { + val extension: String + fun format(node: DocumentationNode, to: StringBuilder) +} + +fun FormatService.format(node: DocumentationNode): String = StringBuilder { format(node, this) }.toString() \ No newline at end of file diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt new file mode 100644 index 00000000..4a0bca6f --- /dev/null +++ b/src/Formats/HtmlFormatService.kt @@ -0,0 +1,62 @@ +package org.jetbrains.dokka + +public class HtmlFormatService(val locationService: LocationService, + val signatureGenerator: SignatureGenerator) : FormatService { + override val extension: String = "html" + override fun format(node: DocumentationNode, to: StringBuilder) { + with (to) { + appendln("

") + appendln("Summary for ${node.name}") + appendln("

") + appendln("") + appendln(signatureGenerator.render(node)) + appendln("") + appendln() + appendln("

") + appendln(node.doc.summary) + appendln("

") + appendln("
") + + for (section in node.doc.sections) { + appendln("

") + appendln(section.label) + appendln("

") + appendln("

") + appendln(section.text) + appendln("

") + } + + appendln("

") + appendln("Members") + appendln("

") + appendln("") + + appendln("") + appendln("") + appendln("") + appendln("") + appendln("") + appendln("") + appendln("") + + appendln("") + for (member in node.members.sortBy { it.name }) { + val relativePath = locationService.relativeLocation(node, member, extension) + appendln("") + appendln("") + appendln("") + appendln("") + appendln("") + } + appendln("") + appendln("
MemberSignatureSummary
") + append("${member.name}") + appendln("") + append("${signatureGenerator.render(member)}") + appendln("") + append("${member.doc.summary}") + appendln("
") + + } + } +} \ No newline at end of file diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt new file mode 100644 index 00000000..032667dd --- /dev/null +++ b/src/Formats/MarkdownFormatService.kt @@ -0,0 +1,34 @@ +package org.jetbrains.dokka + +public class MarkdownFormatService(val locationService: LocationService, + val signatureGenerator: SignatureGenerator) : FormatService { + override val extension: String = "md" + override fun format(node: DocumentationNode, to: StringBuilder) { + with (to) { + appendln(node.path.map { "[${it.name}](${locationService.relativeLocation(node, it, extension)})" }.joinToString(" / ")) + appendln() + append("# ") + appendln(signatureGenerator.render(node)) + appendln() + appendln(node.doc.summary) + appendln() + for (section in node.doc.sections) { + append("### ") + appendln(section.label) + appendln(section.text) + } + + + appendln("### Members") + appendln("| Name | Signature | Summary |") + appendln("|------|-----------|---------|") + for (member in node.members.sortBy { it.name }) { + val relativePath = locationService.relativeLocation(node, member, extension) + append("|[${member.name}](${relativePath})") + append("|${signatureGenerator.render(member)}") + append("|${member.doc.summary} ") + appendln("|") + } + } + } +} \ No newline at end of file diff --git a/src/Formats/TextFormatService.kt b/src/Formats/TextFormatService.kt new file mode 100644 index 00000000..1da1c0d0 --- /dev/null +++ b/src/Formats/TextFormatService.kt @@ -0,0 +1,19 @@ +package org.jetbrains.dokka + +public class TextFormatService(val signatureGenerator: SignatureGenerator) : FormatService { + override val extension: String = "txt" + override fun format(node: DocumentationNode, to: StringBuilder) { + with (to) { + appendln(signatureGenerator.render(node)) + appendln() + appendln(node.doc.summary) + for (n in node.doc.summary.indices) + append("=") + + for (section in node.doc.sections) { + appendln(section.label) + appendln(section.text) + } + } + } +} \ No newline at end of file -- cgit