aboutsummaryrefslogtreecommitdiff
path: root/src/Formats
diff options
context:
space:
mode:
authorIlya Ryzhenkov <orangy@jetbrains.com>2014-10-03 20:20:02 +0400
committerIlya Ryzhenkov <orangy@jetbrains.com>2014-10-03 20:20:02 +0400
commitd6fd04521ba4c4c430286078dd56309111c180e6 (patch)
treecd02584ade5cd0c0cfa8da30da5ccb0ea7b2131c /src/Formats
parent7c6da4babd01da31c57c5c6c827eb2957c989b1c (diff)
downloaddokka-d6fd04521ba4c4c430286078dd56309111c180e6.tar.gz
dokka-d6fd04521ba4c4c430286078dd56309111c180e6.tar.bz2
dokka-d6fd04521ba4c4c430286078dd56309111c180e6.zip
Cross-reference links on types, relative locations.
Diffstat (limited to 'src/Formats')
-rw-r--r--src/Formats/FormatService.kt8
-rw-r--r--src/Formats/HtmlFormatService.kt7
-rw-r--r--src/Formats/JekyllFormatService.kt7
-rw-r--r--src/Formats/MarkdownFormatService.kt3
-rw-r--r--src/Formats/StructuredFormatService.kt97
-rw-r--r--src/Formats/TextFormatService.kt7
6 files changed, 65 insertions, 64 deletions
diff --git a/src/Formats/FormatService.kt b/src/Formats/FormatService.kt
index f890c34a..9af74590 100644
--- a/src/Formats/FormatService.kt
+++ b/src/Formats/FormatService.kt
@@ -2,9 +2,9 @@ package org.jetbrains.dokka
public trait FormatService {
val extension: String
- fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>)
- fun appendOutline(to: StringBuilder, nodes: Iterable<DocumentationNode>)
+ fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>)
+ fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>)
}
-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
+fun FormatService.format(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder { appendNodes(location, this, nodes) }.toString()
+fun FormatService.formatOutline(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder { appendOutline(location, this, nodes) }.toString() \ No newline at end of file
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt
index c3720956..06b41518 100644
--- a/src/Formats/HtmlFormatService.kt
+++ b/src/Formats/HtmlFormatService.kt
@@ -1,10 +1,9 @@
package org.jetbrains.dokka
public open class HtmlFormatService(locationService: LocationService,
- resolutionService: ResolutionService,
signatureGenerator: LanguageService,
val templateService: HtmlTemplateService = HtmlTemplateService.default())
-: StructuredFormatService(locationService, resolutionService, signatureGenerator) {
+: StructuredFormatService(locationService, signatureGenerator) {
override val extension: String = "html"
override public fun formatText(text: String): String {
@@ -95,9 +94,9 @@ public open class HtmlFormatService(locationService: LocationService,
}
- override fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
templateService.appendHeader(to)
- super<StructuredFormatService>.appendNodes(to, nodes)
+ super<StructuredFormatService>.appendNodes(location, to, nodes)
templateService.appendFooter(to)
}
diff --git a/src/Formats/JekyllFormatService.kt b/src/Formats/JekyllFormatService.kt
index 459b5113..9870c8ee 100644
--- a/src/Formats/JekyllFormatService.kt
+++ b/src/Formats/JekyllFormatService.kt
@@ -1,17 +1,16 @@
package org.jetbrains.dokka
public class JekyllFormatService(locationService: LocationService,
- resolutionService: ResolutionService,
signatureGenerator: LanguageService)
-: MarkdownFormatService(locationService, resolutionService, signatureGenerator) {
+: MarkdownFormatService(locationService, signatureGenerator) {
override fun link(from: DocumentationNode, to: DocumentationNode): FormatLink = link(from, to, "html")
- override fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
to.appendln("---")
to.appendln("layout: api")
to.appendln("title: ${nodes.first().name}")
to.appendln("---")
- super<MarkdownFormatService>.appendNodes(to, nodes)
+ super<MarkdownFormatService>.appendNodes(location, to, nodes)
}
} \ No newline at end of file
diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt
index 7b71f638..cb1d713c 100644
--- a/src/Formats/MarkdownFormatService.kt
+++ b/src/Formats/MarkdownFormatService.kt
@@ -2,9 +2,8 @@ package org.jetbrains.dokka
public open class MarkdownFormatService(locationService: LocationService,
- resolutionService: ResolutionService,
signatureGenerator: LanguageService)
-: StructuredFormatService(locationService, resolutionService, signatureGenerator) {
+: StructuredFormatService(locationService, signatureGenerator) {
override val extension: String = "md"
diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt
index ea8ed36e..b974dcf8 100644
--- a/src/Formats/StructuredFormatService.kt
+++ b/src/Formats/StructuredFormatService.kt
@@ -5,7 +5,6 @@ import java.util.LinkedHashMap
public data class FormatLink(val text: String, val location: Location)
public abstract class StructuredFormatService(val locationService: LocationService,
- val resolutionService: ResolutionService,
val languageService: LanguageService) : FormatService {
abstract public fun appendBlockCode(to: StringBuilder, line: String)
@@ -31,19 +30,24 @@ public abstract class StructuredFormatService(val locationService: LocationServi
public abstract fun formatCode(code: String): String
public abstract fun formatBreadcrumbs(items: Iterable<FormatLink>): String
- open fun formatText(nodes: Iterable<ContentNode>): String {
- return nodes.map { formatText(it) }.join("")
+ open fun formatText(location: Location, nodes: Iterable<ContentNode>): String {
+ return nodes.map { formatText(location, it) }.join("")
}
- open fun formatText(node: ContentNode): String {
+ open fun formatText(location: Location, content: ContentNode): String {
return StringBuilder {
- when (node) {
- is ContentText -> append(node.text)
- is ContentSymbol -> append(formatSymbol(node.text))
- is ContentKeyword -> append(formatKeyword(node.text))
- is ContentIdentifier -> append(formatIdentifier(node.text))
- is ContentEmphasis -> append(formatBold(formatText(node.children)))
- else -> append(formatText(node.children))
+ when (content) {
+ is ContentText -> append(content.text)
+ is ContentSymbol -> append(formatSymbol(content.text))
+ is ContentKeyword -> append(formatKeyword(content.text))
+ is ContentIdentifier -> append(formatIdentifier(content.text))
+ is ContentEmphasis -> append(formatBold(formatText(location, content.children)))
+ is ContentNodeLink -> {
+ val linkTo = locationService.relativeLocation(location, content.node, extension)
+ val linkText = formatText(location, content.children)
+ append(formatLink(linkText, linkTo))
+ }
+ else -> append(formatText(location, content.children))
}
}.toString()
}
@@ -54,71 +58,52 @@ public abstract class StructuredFormatService(val locationService: LocationServi
return FormatLink(to.name, locationService.relativeLocation(from, to, extension))
}
- open public fun appendDescription(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ fun appendDescription(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
val described = nodes.filter { !it.doc.isEmpty }
if (described.any()) {
val single = described.size == 1
appendHeader(to, "Description", 3)
for (node in described) {
if (!single) {
- appendBlockCode(to, formatText(languageService.render(node)))
+ appendBlockCode(to, formatText(location, languageService.render(node)))
}
- appendLine(to, formatText(node.doc.description))
+ appendLine(to, formatText(location,node.doc.description))
appendLine(to)
for ((label, section) in node.doc.sections) {
if (label.startsWith("$"))
continue
appendLine(to, formatBold(formatText(label)))
- appendLine(to, formatText(section))
+ appendLine(to, formatText(location, section))
appendLine(to)
}
}
}
}
- open public fun appendSummary(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ fun appendSummary(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
val breakdownBySummary = nodes.groupByTo(LinkedHashMap()) { node ->
node.doc.summary
}
for ((summary, items) in breakdownBySummary) {
items.forEach {
- appendBlockCode(to, formatText(languageService.render(it)))
+ appendBlockCode(to, formatText(location, languageService.render(it)))
}
- appendLine(to, formatText(summary))
+ appendLine(to, formatText(location, summary))
appendLine(to)
}
}
- open public fun appendLocation(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ fun appendLocation(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
val breakdownByName = nodes.groupBy { node -> node.name }
for ((name, items) in breakdownByName) {
appendHeader(to, formatText(name))
- appendSummary(to, items)
- appendDescription(to, items)
- }
- }
-
- override fun appendNodes(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
- val breakdownByLocation = nodes.groupBy { node ->
- formatBreadcrumbs(node.path.map { link(node, it) })
- }
-
- for ((breadcrumbs, items) in breakdownByLocation) {
- appendLine(to, breadcrumbs)
- appendLine(to)
- appendLocation(to, items)
- }
-
- for (node in nodes) {
- appendSection("Members", node.members, node, to)
- appendSection("Extensions", node.extensions, node, to)
- appendSection("Inheritors", node.inheritors, node, to)
- appendSection("Links", node.links, node, to)
+ appendSummary(location, to, items)
+ appendDescription(location, to, items)
}
}
- private fun StructuredFormatService.appendSection(caption: String, nodes: List<DocumentationNode>, node: DocumentationNode, to: StringBuilder) {
+ private fun StructuredFormatService.appendSection(location : Location, caption: String, nodes: List<DocumentationNode>, node: DocumentationNode, to: StringBuilder) {
if (nodes.any()) {
appendHeader(to, caption, 3)
@@ -127,20 +112,20 @@ public abstract class StructuredFormatService(val locationService: LocationServi
appendTable(to) {
appendTableBody(to) {
- for ((location, members) in membersMap) {
+ for ((memberLocation, members) in membersMap) {
appendTableRow(to) {
appendTableCell(to) {
- appendText(to, formatLink(location))
+ appendText(to, formatLink(memberLocation))
}
appendTableCell(to) {
val breakdownBySummary = members.groupBy { it.doc.summary }
for ((summary, items) in breakdownBySummary) {
for (signature in items) {
- appendBlockCode(to, formatText(languageService.render(signature)))
+ appendBlockCode(to, formatText(location, languageService.render(signature)))
}
if (!summary.isEmpty()) {
- appendText(to, formatText(summary))
+ appendText(to, formatText(location, summary))
}
}
}
@@ -151,10 +136,30 @@ public abstract class StructuredFormatService(val locationService: LocationServi
}
}
+ override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ val breakdownByLocation = nodes.groupBy { node ->
+ formatBreadcrumbs(node.path.map { link(node, it) })
+ }
+
+ for ((breadcrumbs, items) in breakdownByLocation) {
+ appendLine(to, breadcrumbs)
+ appendLine(to)
+ appendLocation(location, to, items)
+ }
+
+ for (node in nodes) {
+ appendSection(location, "Members", node.members, node, to)
+ appendSection(location, "Extensions", node.extensions, node, to)
+ appendSection(location, "Inheritors", node.inheritors, node, to)
+ appendSection(location, "Links", node.links, node, to)
+
+ }
+ }
+
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>) {
+ public override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
for (node in nodes) {
appendOutlineHeader(to, node)
if (node.members.any()) {
diff --git a/src/Formats/TextFormatService.kt b/src/Formats/TextFormatService.kt
index 8fea5a6a..63d2ce42 100644
--- a/src/Formats/TextFormatService.kt
+++ b/src/Formats/TextFormatService.kt
@@ -2,21 +2,20 @@ package org.jetbrains.dokka
public class TextFormatService(val signatureGenerator: LanguageService) : FormatService {
override val extension: String = "txt"
- override fun appendNodes(to: StringBuilder,
- nodes: Iterable<DocumentationNode>) {
+ override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
for (node in nodes) {
with (to) {
appendln(signatureGenerator.render(node))
appendln()
appendln(node.doc.summary)
- for ((label,section) in node.doc.sections) {
+ for ((label, section) in node.doc.sections) {
appendln(label)
}
}
}
}
- override fun appendOutline(to: StringBuilder, nodes: Iterable<DocumentationNode>) {
+ override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) {
}
} \ No newline at end of file