diff options
Diffstat (limited to 'core')
3 files changed, 42 insertions, 18 deletions
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("<div class=\"$cssClass\"") if (markdown) to.append(" markdown=\"1\"") 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<String>) {", "}") { - 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<String>) {", "}") { + 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<out SampleProcessingService> = 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 |