aboutsummaryrefslogtreecommitdiff
path: root/src/Formats/HtmlFormatService.kt
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-15 15:54:05 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-15 15:54:05 +0400
commit62cb509a1a5adf0e5f9ba8d8e7545a93eb8516b2 (patch)
tree52e0ad3452a198ee279df8ed3e93c9c0a39a5f6b /src/Formats/HtmlFormatService.kt
parentad884a9ce79f191f3a7b7aed115080e341265ef3 (diff)
downloaddokka-62cb509a1a5adf0e5f9ba8d8e7545a93eb8516b2.tar.gz
dokka-62cb509a1a5adf0e5f9ba8d8e7545a93eb8516b2.tar.bz2
dokka-62cb509a1a5adf0e5f9ba8d8e7545a93eb8516b2.zip
Refactor formatting service to detach grouping logic from markup
Diffstat (limited to 'src/Formats/HtmlFormatService.kt')
-rw-r--r--src/Formats/HtmlFormatService.kt94
1 files changed, 40 insertions, 54 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt
index f3d71215..6c004509 100644
--- a/src/Formats/HtmlFormatService.kt
+++ b/src/Formats/HtmlFormatService.kt
@@ -1,64 +1,50 @@
package org.jetbrains.dokka
-public class HtmlFormatService(val locationService: LocationService,
- val signatureGenerator: SignatureGenerator) : FormatService {
+public open class HtmlFormatService(locationService: LocationService, signatureGenerator: SignatureGenerator)
+: StructuredFormatService(locationService, signatureGenerator) {
override val extension: String = "html"
- override fun format(nodes: Iterable<DocumentationNode>, to: StringBuilder) {
- for (node in nodes) {
- 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>")
- }
+ override fun appendBlockCode(to: StringBuilder, line: String) {
+ to.appendln("<code>")
+ to.appendln(line)
+ to.appendln("</code>")
+ }
+
+ override fun appendBlockCode(to: StringBuilder, lines: Iterable<String>) {
+ to.appendln("<code>")
+ to.appendln(lines.join("\n"))
+ to.appendln("</code>")
+ }
+
+ override fun appendHeader(to: StringBuilder, text: String, level: Int) {
+ to.appendln("<h$level>$text</h$level>")
+ }
+
+ override fun appendText(to: StringBuilder, text: String) {
+ to.appendln("<p>$text</p>")
+ }
- appendln("<h3>")
- appendln("Members")
- appendln("</h3>")
- appendln("<table>")
+ override fun appendLine(to: StringBuilder, text: String) {
+ to.appendln("$text<br/>")
+ }
+
+ override fun appendLine(to: StringBuilder) {
+ to.appendln("<br/>")
+ }
- appendln("<thead>")
- appendln("<tr>")
- appendln("<td>Member</td>")
- appendln("<td>Signature</td>")
- appendln("<td>Summary</td>")
- appendln("</tr>")
- appendln("</thead>")
+ override fun formatLink(link: FormatLink): String {
+ return "<a href=\"${link.location.path}\">${link.text}</a>"
+ }
- 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>")
+ override fun formatBold(text: String): String {
+ return "<b>$text</b>"
+ }
+
+ override fun formatCode(code: String): String {
+ return "<code>$code</code>"
+ }
- }
- }
+ override fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
+ return items.map { formatLink(it) }.joinToString("&nbsp;/&nbsp;")
}
} \ No newline at end of file