From 9c6ffa354621e2cab39941e98597009917c4cfb6 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 30 Nov 2016 16:55:05 +0300 Subject: Added special format for experimental kotlin website samples format --- .../kotlin/Formats/KotlinWebsiteFormatService.kt | 51 ++++++++++++++-------- core/src/main/kotlin/Formats/StandardFormats.kt | 7 ++- .../dokka/format/kotlin-website-samples.properties | 2 + 3 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 core/src/main/resources/dokka/format/kotlin-website-samples.properties diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt index ac70bb02..007e9353 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt @@ -3,11 +3,11 @@ package org.jetbrains.dokka import com.google.inject.Inject -class KotlinWebsiteOutputBuilder(to: StringBuilder, - location: Location, - locationService: LocationService, - languageService: LanguageService, - extension: String) +open class KotlinWebsiteOutputBuilder(to: StringBuilder, + location: Location, + locationService: LocationService, + languageService: LanguageService, + extension: String) : JekyllOutputBuilder(to, location, locationService, languageService, extension) { private var needHardLineBreaks = false @@ -30,7 +30,7 @@ class KotlinWebsiteOutputBuilder(to: StringBuilder, override fun appendStrikethrough(body: () -> Unit) = wrapInTag("s", body) - private fun div(to: StringBuilder, cssClass: String, markdown: Boolean = false, block: () -> Unit) { + protected fun div(to: StringBuilder, cssClass: String, markdown: Boolean = false, block: () -> Unit) { to.append("
") @@ -53,17 +53,6 @@ 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) {", "}") { - wrap("\n//sampleStart\n", "\n//sampleEnd\n", body) - } - } - } - } - override fun appendAsOverloadGroup(to: StringBuilder, block: () -> Unit) { div(to, "overload-group", true) { ensureParagraph() @@ -162,3 +151,31 @@ class KotlinWebsiteFormatService @Inject constructor(locationService: LocationSe override fun createOutputBuilder(to: StringBuilder, location: Location) = KotlinWebsiteOutputBuilder(to, location, locationService, languageService, extension) } + + +class KotlinWebsiteRunnableSamplesOutputBuilder(to: StringBuilder, + location: Location, + locationService: LocationService, + languageService: LanguageService, + extension: String) + : KotlinWebsiteOutputBuilder(to, location, locationService, languageService, extension) { + + override fun appendSampleBlockCode(language: String, imports: () -> Unit, body: () -> Unit) { + div(to, "sample", true) { + appendBlockCode(language) { + imports() + wrap("\nfun main(args: Array) {", "}") { + wrap("\n//sampleStart\n", "\n//sampleEnd\n", body) + } + } + } + } +} + +class KotlinWebsiteRunnableSamplesFormatService @Inject constructor(locationService: LocationService, + signatureGenerator: LanguageService) + : JekyllFormatService(locationService, signatureGenerator, "html") { + override fun createOutputBuilder(to: StringBuilder, location: Location) = + KotlinWebsiteRunnableSamplesOutputBuilder(to, location, locationService, languageService, extension) +} + diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt index dabde881..6b077444 100644 --- a/core/src/main/kotlin/Formats/StandardFormats.kt +++ b/core/src/main/kotlin/Formats/StandardFormats.kt @@ -32,7 +32,12 @@ class HtmlAsJavaFormatDescriptor : FormatDescriptor { class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() { override val formatServiceClass = KotlinWebsiteFormatService::class override val outlineServiceClass = YamlOutlineService::class - override val sampleProcessingService: KClass = KotlinWebsiteSampleProcessingService::class +} + +class KotlinWebsiteFormatRunnableSamplesDescriptor : KotlinFormatDescriptorBase() { + override val formatServiceClass = KotlinWebsiteRunnableSamplesFormatService::class + override val sampleProcessingService = KotlinWebsiteSampleProcessingService::class + override val outlineServiceClass = YamlOutlineService::class } class JekyllFormatDescriptor : KotlinFormatDescriptorBase() { diff --git a/core/src/main/resources/dokka/format/kotlin-website-samples.properties b/core/src/main/resources/dokka/format/kotlin-website-samples.properties new file mode 100644 index 00000000..bda616a4 --- /dev/null +++ b/core/src/main/resources/dokka/format/kotlin-website-samples.properties @@ -0,0 +1,2 @@ +class=org.jetbrains.dokka.Formats.KotlinWebsiteFormatRunnableSamplesDescriptor +description=Generates Kotlin website documentation \ No newline at end of file -- cgit