aboutsummaryrefslogtreecommitdiff
path: root/src/Formats
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-07-15 16:18:53 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-07-15 16:18:53 +0400
commit499d082186fcda877a216d536cf9512d0f0265ac (patch)
treef82c8c5e19cc5c37e4fc3b37706a988fa32b173a /src/Formats
parent62cb509a1a5adf0e5f9ba8d8e7545a93eb8516b2 (diff)
downloaddokka-499d082186fcda877a216d536cf9512d0f0265ac.tar.gz
dokka-499d082186fcda877a216d536cf9512d0f0265ac.tar.bz2
dokka-499d082186fcda877a216d536cf9512d0f0265ac.zip
Cleaning, generalizing, added outline support (hardcoded yml for now)
Diffstat (limited to 'src/Formats')
-rw-r--r--src/Formats/FormatService.kt7
-rw-r--r--src/Formats/HtmlFormatService.kt11
-rw-r--r--src/Formats/JekyllFormatService.kt2
-rw-r--r--src/Formats/MarkdownFormatService.kt27
-rw-r--r--src/Formats/StructuredFormatService.kt26
-rw-r--r--src/Formats/TextFormatService.kt5
6 files changed, 61 insertions, 17 deletions
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<DocumentationNode>)
+ fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>)
+ fun appendOutline(to: StringBuilder, nodes: Iterable<DocumentationNode>)
}
-fun FormatService.format(nodes: Iterable<DocumentationNode>): String = StringBuilder { appendNodes(this, nodes) }.toString() \ No newline at end of file
+fun FormatService.format(nodes: Iterable<DocumentationNode>): String = StringBuilder { appendNodes(this, nodes) }.toString()
+fun FormatService.formatOutline(nodes: Iterable<DocumentationNode>): 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("<br/>")
}
- override fun formatLink(link: FormatLink): String {
- return "<a href=\"${link.location.path}\">${link.text}</a>"
+ override fun formatLink(text: String, location: Location): String {
+ return "<a href=\"${location.path}\">${text}</a>"
}
override fun formatBold(text: String): String {
@@ -47,4 +47,9 @@ public open class HtmlFormatService(locationService: LocationService, signatureG
override fun formatBreadcrumbs(items: Iterable<FormatLink>): String {
return items.map { formatLink(it) }.joinToString("&nbsp;/&nbsp;")
}
+
+ override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ }
+ 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<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/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<String>)
@@ -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<FormatLink>): 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<DocumentationNode>)
+
+ override public fun appendOutline(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 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<DocumentationNode>) {
@@ -19,4 +19,7 @@ public class TextFormatService(val signatureGenerator: SignatureGenerator) : For
}
}
}
+
+ override fun appendOutline(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ }
} \ No newline at end of file