aboutsummaryrefslogtreecommitdiff
path: root/src/Formats
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-14 15:00:33 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-14 15:00:33 +0400
commita0bfdbd8cc365cb11c26e81ee7587f0ec25df79d (patch)
treec68610d2003d2a4712b3fbc95561ac20390a161d /src/Formats
parent6168541bd5bb141c40a1e2a909afa84441b35ed5 (diff)
downloaddokka-a0bfdbd8cc365cb11c26e81ee7587f0ec25df79d.tar.gz
dokka-a0bfdbd8cc365cb11c26e81ee7587f0ec25df79d.tar.bz2
dokka-a0bfdbd8cc365cb11c26e81ee7587f0ec25df79d.zip
Location services, formatting services, initial self-documentation output.
Diffstat (limited to 'src/Formats')
-rw-r--r--src/Formats/FormatService.kt8
-rw-r--r--src/Formats/HtmlFormatService.kt62
-rw-r--r--src/Formats/MarkdownFormatService.kt34
-rw-r--r--src/Formats/TextFormatService.kt19
4 files changed, 123 insertions, 0 deletions
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("<h2>")
+ appendln("Summary for ${node.name}")
+ appendln("</h2>")
+ appendln("<code>")
+ appendln(signatureGenerator.render(node))
+ appendln("</code>")
+ appendln()
+ appendln("<p>")
+ appendln(node.doc.summary)
+ appendln("</p>")
+ appendln("<hr/>")
+
+ for (section in node.doc.sections) {
+ appendln("<h3>")
+ appendln(section.label)
+ appendln("</h3>")
+ appendln("<p>")
+ appendln(section.text)
+ appendln("</p>")
+ }
+
+ appendln("<h3>")
+ appendln("Members")
+ appendln("</h3>")
+ appendln("<table>")
+
+ appendln("<thead>")
+ appendln("<tr>")
+ appendln("<td>Member</td>")
+ appendln("<td>Signature</td>")
+ appendln("<td>Summary</td>")
+ appendln("</tr>")
+ appendln("</thead>")
+
+ appendln("<tbody>")
+ for (member in node.members.sortBy { it.name }) {
+ val relativePath = locationService.relativeLocation(node, member, extension)
+ appendln("<tr>")
+ appendln("<td>")
+ append("<a href=\"${relativePath}\">${member.name}</a>")
+ appendln("</td>")
+ appendln("<td>")
+ append("${signatureGenerator.render(member)}")
+ appendln("</td>")
+ appendln("<td>")
+ append("${member.doc.summary}")
+ appendln("</td>")
+ appendln("</tr>")
+ }
+ appendln("</tbody>")
+ appendln("</table>")
+
+ }
+ }
+} \ 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