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 +- .../kotlin/Formats/KotlinWebsiteFormatService.kt | 2 +- .../main/kotlin/Formats/MarkdownFormatService.kt | 2 +- core/src/main/kotlin/Formats/StandardFormats.kt | 8 ++++-- .../main/kotlin/Formats/StructuredFormatService.kt | 6 ++-- .../src/main/resources/dokka/format/gfm.properties | 2 ++ core/src/test/kotlin/format/GFMFormatTest.kt | 19 +++++++++++++ core/testdata/format/gfm/sample.kt | 18 ++++++++++++ core/testdata/format/gfm/sample.md | 33 ++++++++++++++++++++++ 10 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 core/src/main/kotlin/Formats/GFMFormatService.kt create mode 100644 core/src/main/resources/dokka/format/gfm.properties create mode 100644 core/src/test/kotlin/format/GFMFormatTest.kt create mode 100644 core/testdata/format/gfm/sample.kt create mode 100644 core/testdata/format/gfm/sample.md diff --git a/core/src/main/kotlin/Formats/GFMFormatService.kt b/core/src/main/kotlin/Formats/GFMFormatService.kt new file mode 100644 index 000000000..7b1eab851 --- /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 e6635cef2..c74431289 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 eba82a3a4..1f3a37509 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 9684b5c16..791772392 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 94e1b115a..fdc8eb9e2 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 bb27aab58..72b6833de 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 000000000..5e8f7aa8c --- /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 diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt new file mode 100644 index 000000000..7f7ee2868 --- /dev/null +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -0,0 +1,19 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.GFMFormatService +import org.jetbrains.dokka.KotlinLanguageService +import org.junit.Test + +class GFMFormatTest { + private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService()) + + @Test fun sample() { + verifyGFMNodeByName("sample", "Foo") + } + + private fun verifyGFMNodeByName(fileName: String, name: String) { + verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> + gfmService.appendNodes(tempLocation, output, model.members.single().members.filter { it.name == name }) + } + } +} diff --git a/core/testdata/format/gfm/sample.kt b/core/testdata/format/gfm/sample.kt new file mode 100644 index 000000000..3300d2c8c --- /dev/null +++ b/core/testdata/format/gfm/sample.kt @@ -0,0 +1,18 @@ +/** + * The class Foo. + */ +class Foo { + /** + * The method bar. + */ + fun bar() { + + } + + /** + * The method baz. + */ + fun baz() { + + } +} \ No newline at end of file diff --git a/core/testdata/format/gfm/sample.md b/core/testdata/format/gfm/sample.md new file mode 100644 index 000000000..1555341e3 --- /dev/null +++ b/core/testdata/format/gfm/sample.md @@ -0,0 +1,33 @@ +[test](test/index) / [Foo](test/-foo/index) + + +# Foo + +`class Foo` + +The class Foo. + + + + +### Constructors + +| Name | Summary +|---|---| +| [<init>](test/-foo/-init-) | `Foo()` +The class Foo. + + | + +### Functions + +| Name | Summary +|---|---| +| [bar](test/-foo/bar) | `fun bar(): Unit` +The method bar. + + | +| [baz](test/-foo/baz) | `fun baz(): Unit` +The method baz. + + | -- cgit v1.2.3