diff options
author | Simon Ogorodnik <sem-oro@yandex.ru> | 2016-11-29 15:53:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-29 15:53:53 +0300 |
commit | 37cbd962b7493aef63067a9f6b7f4abbaa56bc80 (patch) | |
tree | 9535169caa2899dab75417b0b788f1ec341b4b0b /core/src/main/kotlin/Formats | |
parent | edda34b73bbbd9537eb499668c47a7a901b284c2 (diff) | |
parent | 875e7e5e39c6c1668729685bbc7f51bc07aed4b6 (diff) | |
download | dokka-37cbd962b7493aef63067a9f6b7f4abbaa56bc80.tar.gz dokka-37cbd962b7493aef63067a9f6b7f4abbaa56bc80.tar.bz2 dokka-37cbd962b7493aef63067a9f6b7f4abbaa56bc80.zip |
Merge pull request #111 from Kotlin/website-samples
Tweaked output for kotlin-website samples feature
Diffstat (limited to 'core/src/main/kotlin/Formats')
4 files changed, 45 insertions, 14 deletions
diff --git a/core/src/main/kotlin/Formats/FormatDescriptor.kt b/core/src/main/kotlin/Formats/FormatDescriptor.kt index e384f223..7cc50acb 100644 --- a/core/src/main/kotlin/Formats/FormatDescriptor.kt +++ b/core/src/main/kotlin/Formats/FormatDescriptor.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.Formats import org.jetbrains.dokka.* +import org.jetbrains.dokka.Samples.SampleProcessingService import kotlin.reflect.KClass interface FormatDescriptor { @@ -9,4 +10,5 @@ interface FormatDescriptor { val generatorServiceClass: KClass<out Generator> val packageDocumentationBuilderClass: KClass<out PackageDocumentationBuilder> val javaDocumentationBuilderClass: KClass<out JavaDocumentationBuilder> + val sampleProcessingService: KClass<out SampleProcessingService> } diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt index bc9358ac..ac70bb02 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt @@ -30,11 +30,13 @@ class KotlinWebsiteOutputBuilder(to: StringBuilder, override fun appendStrikethrough(body: () -> Unit) = wrapInTag("s", body) - private fun div(to: StringBuilder, cssClass: String, block: () -> Unit) { - to.append("<div class=\"$cssClass\">") - insideDiv++ + private fun div(to: StringBuilder, cssClass: String, markdown: Boolean = false, block: () -> Unit) { + to.append("<div class=\"$cssClass\"") + if (markdown) to.append(" markdown=\"1\"") + to.append(">") + if (!markdown) insideDiv++ block() - insideDiv-- + if (!markdown) insideDiv-- to.append("</div>\n") } @@ -51,12 +53,23 @@ class KotlinWebsiteOutputBuilder(to: StringBuilder, } } + override fun appendSampleBlockCode(language: String, imports: () -> Unit, body: () -> Unit) { + div(to, "sample", true) { + appendBlockCode(language) { + imports() + wrap("\nfun main(args: Array<String>) {", "}") { + wrap("\n//sampleStart\n", "\n//sampleEnd\n", body) + } + } + } + } + override fun appendAsOverloadGroup(to: StringBuilder, block: () -> Unit) { - to.append("<div class=\"overload-group\" markdown=\"1\">") - ensureParagraph() - block() - ensureParagraph() - to.append("</div>") + div(to, "overload-group", true) { + ensureParagraph() + block() + ensureParagraph() + } } override fun appendLink(href: String, body: () -> Unit) = wrap("<a href=\"$href\">", "</a>", body) diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt index fdc8eb9e..dabde881 100644 --- a/core/src/main/kotlin/Formats/StandardFormats.kt +++ b/core/src/main/kotlin/Formats/StandardFormats.kt @@ -1,6 +1,9 @@ package org.jetbrains.dokka.Formats import org.jetbrains.dokka.* +import org.jetbrains.dokka.Samples.DefaultSampleProcessingService +import org.jetbrains.dokka.Samples.KotlinWebsiteSampleProcessingService +import org.jetbrains.dokka.Samples.SampleProcessingService import kotlin.reflect.KClass abstract class KotlinFormatDescriptorBase : FormatDescriptor { @@ -9,6 +12,7 @@ abstract class KotlinFormatDescriptorBase : FormatDescriptor { override val generatorServiceClass = FileGenerator::class override val outlineServiceClass: KClass<out OutlineFormatService>? = null + override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class } class HtmlFormatDescriptor : KotlinFormatDescriptorBase() { @@ -22,11 +26,13 @@ class HtmlAsJavaFormatDescriptor : FormatDescriptor { override val generatorServiceClass = FileGenerator::class override val packageDocumentationBuilderClass = KotlinAsJavaDocumentationBuilder::class override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class + override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class } class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() { override val formatServiceClass = KotlinWebsiteFormatService::class override val outlineServiceClass = YamlOutlineService::class + override val sampleProcessingService: KClass<out SampleProcessingService> = KotlinWebsiteSampleProcessingService::class } class JekyllFormatDescriptor : KotlinFormatDescriptorBase() { diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index a7a50f91..7896bcd8 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -45,6 +45,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, protected abstract fun ensureParagraph() + open fun appendSampleBlockCode(language: String, imports: () -> Unit, body: () -> Unit) = appendBlockCode(language, body) abstract fun appendBlockCode(language: String, body: () -> Unit) abstract fun appendHeader(level: Int = 1, body: () -> Unit) abstract fun appendParagraph(body: () -> Unit) @@ -140,13 +141,22 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, } } - is ContentBlockCode -> appendBlockCode(content.language) { - for ((index, contentNode) in content.children.withIndex()) { - appendContent(contentNode) - if (index < content.children.size - 1) { - to.append("\n") + is ContentBlockSampleCode, is ContentBlockCode -> { + content as ContentBlockCode + fun ContentBlockCode.appendBlockCodeContent() { + for ((index, contentNode) in this.children.withIndex()) { + appendContent(contentNode) + if (index < this.children.size - 1) { + to.append("\n") + } } } + when (content) { + is ContentBlockSampleCode -> + appendSampleBlockCode(content.language, content.importsBlock::appendBlockCodeContent, { content.appendBlockCodeContent() }) + is ContentBlockCode -> + appendBlockCode(content.language, { content.appendBlockCodeContent() }) + } } is ContentHeading -> appendHeader(content.level) { appendContent(content.children) } is ContentBlock -> appendContent(content.children) |