diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/Formats/GFMFormatService.kt | 18 | ||||
-rw-r--r-- | core/src/main/kotlin/Formats/HtmlFormatService.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/Formats/MarkdownFormatService.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/Formats/StandardFormats.kt | 8 | ||||
-rw-r--r-- | core/src/main/kotlin/Formats/StructuredFormatService.kt | 6 | ||||
-rw-r--r-- | core/src/main/resources/dokka/format/gfm.properties | 2 | ||||
-rw-r--r-- | core/src/test/kotlin/format/GFMFormatTest.kt | 19 | ||||
-rw-r--r-- | core/testdata/format/gfm/sample.kt | 18 | ||||
-rw-r--r-- | core/testdata/format/gfm/sample.md | 33 |
10 files changed, 102 insertions, 8 deletions
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("<a name=\"${anchor.htmlEscape()}\"></a>") } - override fun appendTable(to: StringBuilder, body: () -> Unit) { + override fun appendTable(to: StringBuilder, vararg columns: String, body: () -> Unit) { to.appendln("<table>") body() to.appendln("</table>") 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("<table class=\"api-docs-table\">") body() to.appendln("</table>") 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<out OutlineFormatService>? = 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 diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt new file mode 100644 index 00000000..7f7ee286 --- /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 00000000..3300d2c8 --- /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 00000000..1555341e --- /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. + + | |