From cb97c45aa0b0204ebc61a149794518d50b262814 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 1 Jul 2016 16:39:32 +0200 Subject: introduce GFM output format --- core/src/main/kotlin/Formats/GFMFormatService.kt | 18 ++++++++++++++++++ core/src/main/kotlin/Formats/HtmlFormatService.kt | 2 +- .../main/kotlin/Formats/KotlinWebsiteFormatService.kt | 2 +- core/src/main/kotlin/Formats/MarkdownFormatService.kt | 2 +- core/src/main/kotlin/Formats/StandardFormats.kt | 8 ++++++-- .../src/main/kotlin/Formats/StructuredFormatService.kt | 6 +++--- core/src/main/resources/dokka/format/gfm.properties | 2 ++ 7 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 core/src/main/kotlin/Formats/GFMFormatService.kt create mode 100644 core/src/main/resources/dokka/format/gfm.properties (limited to 'core/src/main') diff --git a/core/src/main/kotlin/Formats/GFMFormatService.kt b/core/src/main/kotlin/Formats/GFMFormatService.kt new file mode 100644 index 00000000..7b1eab85 --- /dev/null +++ b/core/src/main/kotlin/Formats/GFMFormatService.kt @@ -0,0 +1,18 @@ +package org.jetbrains.dokka + +import com.google.inject.Inject + +open class GFMFormatService(locationService: LocationService, + signatureGenerator: LanguageService, + linkExtension: String) +: MarkdownFormatService(locationService, signatureGenerator, linkExtension) { + + @Inject constructor(locationService: LocationService, + signatureGenerator: LanguageService) : this(locationService, signatureGenerator, "md") + + override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) { + to.appendln(columns.joinToString(" | ", "| ", " ")) + to.appendln("|" + "---|".repeat(columns.size)) + body() + } +} diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt index e6635cef..c7443128 100644 --- a/core/src/main/kotlin/Formats/HtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt @@ -49,7 +49,7 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi to.appendln("") } - override fun appendTable(to: StringBuilder, body: () -> Unit) { + override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) { to.appendln("") body() to.appendln("
") diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt index eba82a3a..1f3a3750 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt @@ -77,7 +77,7 @@ class KotlinWebsiteFormatService @Inject constructor(locationService: LocationSe } } - override fun appendTable(to: StringBuilder, body: () -> Unit) { + override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) { to.appendln("") body() to.appendln("
") diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt index 9684b5c1..79177239 100644 --- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt +++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt @@ -75,7 +75,7 @@ open class MarkdownFormatService(locationService: LocationService, appendLine(to) } - override fun appendTable(to: StringBuilder, body: () -> Unit) { + override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) { to.appendln() body() to.appendln() diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt index 94e1b115..fdc8eb9e 100644 --- a/core/src/main/kotlin/Formats/StandardFormats.kt +++ b/core/src/main/kotlin/Formats/StandardFormats.kt @@ -1,12 +1,14 @@ package org.jetbrains.dokka.Formats import org.jetbrains.dokka.* +import kotlin.reflect.KClass abstract class KotlinFormatDescriptorBase : FormatDescriptor { override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class override val generatorServiceClass = FileGenerator::class + override val outlineServiceClass: KClass? = null } class HtmlFormatDescriptor : KotlinFormatDescriptorBase() { @@ -29,10 +31,12 @@ class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() { class JekyllFormatDescriptor : KotlinFormatDescriptorBase() { override val formatServiceClass = JekyllFormatService::class - override val outlineServiceClass = null } class MarkdownFormatDescriptor : KotlinFormatDescriptorBase() { override val formatServiceClass = MarkdownFormatService::class - override val outlineServiceClass = null +} + +class GFMFormatDescriptor : KotlinFormatDescriptorBase() { + override val formatServiceClass = GFMFormatService::class } diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index bb27aab5..72b6833d 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -22,7 +22,7 @@ abstract class StructuredFormatService(locationService: LocationService, abstract fun appendLine(to: StringBuilder, text: String = "") abstract fun appendAnchor(to: StringBuilder, anchor: String) - abstract fun appendTable(to: StringBuilder, body: () -> Unit) + abstract fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) abstract fun appendTableBody(to: StringBuilder, body: () -> Unit) abstract fun appendTableRow(to: StringBuilder, body: () -> Unit) abstract fun appendTableCell(to: StringBuilder, body: () -> Unit) @@ -355,7 +355,7 @@ abstract class StructuredFormatService(locationService: LocationService, val children = if (sortMembers) members.sortedBy { it.name } else members val membersMap = children.groupBy { link(node, it) } - appendTable(to) { + appendTable(to, "Name", "Summary") { appendTableBody(to) { for ((memberLocation, members) in membersMap) { appendTableRow(to) { @@ -404,7 +404,7 @@ abstract class StructuredFormatService(locationService: LocationService, to.append(formatText(location, node.owner!!.summary)) appendHeader(to, "All Types", 3) - appendTable(to) { + appendTable(to, "Name", "Summary") { appendTableBody(to) { for (type in node.members) { appendTableRow(to) { diff --git a/core/src/main/resources/dokka/format/gfm.properties b/core/src/main/resources/dokka/format/gfm.properties new file mode 100644 index 00000000..5e8f7aa8 --- /dev/null +++ b/core/src/main/resources/dokka/format/gfm.properties @@ -0,0 +1,2 @@ +class=org.jetbrains.dokka.Formats.GFMFormatDescriptor +description=Produces documentation in GitHub-flavored markdown format -- cgit