diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-16 16:55:22 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-01-16 16:55:22 +0100 |
commit | 82de2309e53df4206e99beb36ef51326dbae48a2 (patch) | |
tree | ffca7f8610e5f9527d553a9b88f5fe347cbd8647 /src | |
parent | d75cc63e9b1edc229fad225956ba44fa433e2d0e (diff) | |
download | dokka-82de2309e53df4206e99beb36ef51326dbae48a2.tar.gz dokka-82de2309e53df4206e99beb36ef51326dbae48a2.tar.bz2 dokka-82de2309e53df4206e99beb36ef51326dbae48a2.zip |
refactor outline generation; generate HTML outline
Diffstat (limited to 'src')
-rw-r--r-- | src/Formats/FormatService.kt | 6 | ||||
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 26 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 21 | ||||
-rw-r--r-- | src/Formats/OutlineService.kt | 30 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 12 | ||||
-rw-r--r-- | src/Formats/TextFormatService.kt | 3 | ||||
-rw-r--r-- | src/Formats/YamlOutlineService.kt | 23 | ||||
-rw-r--r-- | src/Generation/FileGenerator.kt | 10 | ||||
-rw-r--r-- | src/Kotlin/KotlinLanguageService.kt | 2 | ||||
-rw-r--r-- | src/main.kt | 21 |
10 files changed, 97 insertions, 57 deletions
diff --git a/src/Formats/FormatService.kt b/src/Formats/FormatService.kt index bb6da985..cc190346 100644 --- a/src/Formats/FormatService.kt +++ b/src/Formats/FormatService.kt @@ -14,13 +14,7 @@ public trait FormatService { /** Appends formatted content to [StringBuilder](to) using specified [location] */ fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) - - /** Appends formatted outline to [StringBuilder](to) using specified [location] */ - fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) } /** Format content to [String] using specified [location] */ fun FormatService.format(location: Location, nodes: Iterable<DocumentationNode>): String = StringBuilder { appendNodes(location, this, nodes) }.toString() - -/** Format outline to [String] using specified [location] */ -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 f76693dc..859c07e0 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -1,9 +1,11 @@ package org.jetbrains.dokka +import java.io.File + public open class HtmlFormatService(locationService: LocationService, signatureGenerator: LanguageService, val templateService: HtmlTemplateService = HtmlTemplateService.default()) -: StructuredFormatService(locationService, signatureGenerator) { +: StructuredFormatService(locationService, signatureGenerator), OutlineFormatService { override val extension: String = "html" override public fun formatText(text: String): String { @@ -120,8 +122,26 @@ public open class HtmlFormatService(locationService: LocationService, templateService.appendFooter(to) } - override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable<DocumentationNode>) { + override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { + templateService.appendHeader(to) + super<OutlineFormatService>.appendOutline(location, to, nodes) + templateService.appendFooter(to) + } + + override fun getOutlineFileName(location: Location): File { + return File("${location.path}-outline.html") } - override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { + + override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) { + val link = ContentNodeLink(node) + link.append(languageService.render(node, LanguageService.RenderMode.FULL)) + val signature = formatText(location, link) + to.appendln("${formatLink(signature, location)}<br/>") + } + + override fun appendOutlineLevel(to: StringBuilder, body: () -> Unit) { + to.appendln("<ul>") + body() + to.appendln("</ul>") } }
\ No newline at end of file diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index a2e3ce55..3598f29d 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -120,25 +120,4 @@ public open class MarkdownFormatService(locationService: LocationService, body() to.append(" |") } - - 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/OutlineService.kt b/src/Formats/OutlineService.kt new file mode 100644 index 00000000..db1adf3d --- /dev/null +++ b/src/Formats/OutlineService.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka + +import java.io.File + +/** + * Service for building the outline of the package contents. + */ +public trait OutlineFormatService { + fun getOutlineFileName(location: Location): File + + public fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) + public fun appendOutlineLevel(to: StringBuilder, body: () -> Unit) + + /** Appends formatted outline to [StringBuilder](to) using specified [location] */ + public fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { + for (node in nodes) { + appendOutlineHeader(location, node, to) + if (node.members.any()) { + val sortedMembers = node.members.sortBy { it.name } + appendOutlineLevel(to) { + appendOutline(location, to, sortedMembers) + } + } + to.appendln() + } + } + + fun formatOutline(location: Location, nodes: Iterable<DocumentationNode>): String = + StringBuilder { appendOutline(location, this, nodes) }.toString() +} diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 458fda35..d2fbdc10 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -263,16 +263,4 @@ public abstract class StructuredFormatService(val locationService: LocationServi } } - - abstract public fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) - abstract public fun appendOutlineChildren(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()) { - appendOutlineChildren(to, node.members) - } - } - } }
\ No newline at end of file diff --git a/src/Formats/TextFormatService.kt b/src/Formats/TextFormatService.kt index 4e43cbcc..9db20dfa 100644 --- a/src/Formats/TextFormatService.kt +++ b/src/Formats/TextFormatService.kt @@ -15,7 +15,4 @@ public class TextFormatService(val signatureGenerator: LanguageService) : Format } } } - - override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { - } }
\ No newline at end of file diff --git a/src/Formats/YamlOutlineService.kt b/src/Formats/YamlOutlineService.kt new file mode 100644 index 00000000..cdab4eeb --- /dev/null +++ b/src/Formats/YamlOutlineService.kt @@ -0,0 +1,23 @@ +package org.jetbrains.dokka + +import java.io.File + +class YamlOutlineService(val locationService: LocationService, + val languageService: LanguageService) : OutlineFormatService { + override fun getOutlineFileName(location: Location): File = File("${location.path}.yml") + + var outlineLevel = 0 + override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) { + val indent = " ".repeat(outlineLevel) + to.appendln("$indent- title: ${languageService.renderName(node)}") + to.appendln("$indent url: ${locationService.location(node).path}") + } + + override fun appendOutlineLevel(to: StringBuilder, body: () -> Unit) { + val indent = " ".repeat(outlineLevel) + to.appendln("$indent content:") + outlineLevel++ + body() + outlineLevel-- + } +} diff --git a/src/Generation/FileGenerator.kt b/src/Generation/FileGenerator.kt index ac146503..128f3260 100644 --- a/src/Generation/FileGenerator.kt +++ b/src/Generation/FileGenerator.kt @@ -5,7 +5,8 @@ import java.io.OutputStreamWriter public class FileGenerator(val signatureGenerator: LanguageService, val locationService: LocationService, - val formatService: FormatService) { + val formatService: FormatService, + val outlineService: OutlineFormatService?) { public fun buildPage(node: DocumentationNode): Unit = buildPages(listOf(node)) public fun buildOutline(node: DocumentationNode): Unit = buildOutlines(listOf(node)) @@ -24,12 +25,15 @@ public class FileGenerator(val signatureGenerator: LanguageService, } public fun buildOutlines(nodes: Iterable<DocumentationNode>) { + if (outlineService == null) { + return + } for ((location, items) in nodes.groupBy { locationService.location(it) }) { - val file = location.file.appendExtension("yml") // TODO: hardcoded + val file = outlineService.getOutlineFileName(location) file.getParentFile()?.mkdirs() FileOutputStream(file).use { OutputStreamWriter(it, Charsets.UTF_8).use { - it.write(formatService.formatOutline(location, items)) + it.write(outlineService.formatOutline(location, items)) } } } diff --git a/src/Kotlin/KotlinLanguageService.kt b/src/Kotlin/KotlinLanguageService.kt index b7723285..04da05d9 100644 --- a/src/Kotlin/KotlinLanguageService.kt +++ b/src/Kotlin/KotlinLanguageService.kt @@ -29,7 +29,7 @@ class KotlinLanguageService : LanguageService { DocumentationNode.Kind.PropertyAccessor -> renderFunction(node) DocumentationNode.Kind.Property, DocumentationNode.Kind.ClassObjectProperty -> renderProperty(node) - else -> ContentText("${node.kind}: ${node.name}") + else -> identifier(node.name) } } } diff --git a/src/main.kt b/src/main.kt index 989e8a36..4782c264 100644 --- a/src/main.kt +++ b/src/main.kt @@ -133,19 +133,24 @@ public fun main(args: Array<String>) { val locationService = FoldersLocationService(arguments.outputDir) val templateService = HtmlTemplateService.default("/dokka/styles/style.css") - val formatter = when (arguments.outputFormat) { - "text" -> TextFormatService(signatureGenerator) - "html" -> HtmlFormatService(locationService, signatureGenerator, templateService) - "markdown" -> MarkdownFormatService(locationService, signatureGenerator) - "jekyll" -> JekyllFormatService(locationService, signatureGenerator) - "kotlin-website" -> KotlinWebsiteFormatService(locationService, signatureGenerator) + val (formatter, outlineFormatter) = when (arguments.outputFormat) { + "text" -> TextFormatService(signatureGenerator) to null + "html" -> { + val htmlFormatService = HtmlFormatService(locationService, signatureGenerator, templateService) + htmlFormatService to htmlFormatService + } + "markdown" -> MarkdownFormatService(locationService, signatureGenerator) to null + "jekyll" -> JekyllFormatService(locationService, signatureGenerator) to null + "kotlin-website" -> KotlinWebsiteFormatService(locationService, signatureGenerator) to + YamlOutlineService(locationService, signatureGenerator) else -> { print("Unrecognized output format ${arguments.outputFormat}") - return + null to null } } + if (formatter == null) return - val generator = FileGenerator(signatureGenerator, locationService, formatter) + val generator = FileGenerator(signatureGenerator, locationService, formatter, outlineFormatter) print("Generating pages... ") generator.buildPage(documentation) generator.buildOutline(documentation) |