diff options
| author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2016-11-10 18:55:14 +0300 |
|---|---|---|
| committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2016-11-14 14:06:29 +0300 |
| commit | dc99d1fd5c066ac6083f09e23e52cf6c592768e4 (patch) | |
| tree | 3c8fa7d3fe895f0c360d071beb1b56f8bb7c25f3 /core/src/main/kotlin/Formats | |
| parent | af81d5a311125fc30dcf9c14fc9bd9c8680e532b (diff) | |
| download | dokka-dc99d1fd5c066ac6083f09e23e52cf6c592768e4.tar.gz dokka-dc99d1fd5c066ac6083f09e23e52cf6c592768e4.tar.bz2 dokka-dc99d1fd5c066ac6083f09e23e52cf6c592768e4.zip | |
Added //sampleStart //sampleEnd to samples on kotlin website
Diffstat (limited to 'core/src/main/kotlin/Formats')
| -rw-r--r-- | core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt | 9 | ||||
| -rw-r--r-- | core/src/main/kotlin/Formats/StructuredFormatService.kt | 12 |
2 files changed, 13 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt index edae9976..ac70bb02 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteFormatService.kt @@ -53,9 +53,14 @@ class KotlinWebsiteOutputBuilder(to: StringBuilder, } } - override fun appendSampleBlockCode(language: String, body: () -> Unit) { + override fun appendSampleBlockCode(language: String, imports: () -> Unit, body: () -> Unit) { div(to, "sample", true) { - appendBlockCode(language, body) + appendBlockCode(language) { + imports() + wrap("\nfun main(args: Array<String>) {", "}") { + wrap("\n//sampleStart\n", "\n//sampleEnd\n", body) + } + } } } diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt index 3bd06130..183282ea 100644 --- a/core/src/main/kotlin/Formats/StructuredFormatService.kt +++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt @@ -47,7 +47,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, protected abstract fun ensureParagraph() - open fun appendSampleBlockCode(language: String, body: () -> Unit) = appendBlockCode(language, body) + 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) @@ -146,19 +146,19 @@ abstract class StructuredOutputBuilder(val to: StringBuilder, is ContentBlockSampleCode, is ContentBlockCode -> { content as ContentBlockCode - fun appendBlockCodeContent() { - for ((index, contentNode) in content.children.withIndex()) { + fun ContentBlockCode.appendBlockCodeContent() { + for ((index, contentNode) in this.children.withIndex()) { appendContent(contentNode) - if (index < content.children.size - 1) { + if (index < this.children.size - 1) { to.append("\n") } } } when (content) { is ContentBlockSampleCode -> - appendSampleBlockCode(content.language, ::appendBlockCodeContent) + appendSampleBlockCode(content.language, content.importsBlock::appendBlockCodeContent, { content.appendBlockCodeContent() }) is ContentBlockCode -> - appendBlockCode(content.language, ::appendBlockCodeContent) + appendBlockCode(content.language, { content.appendBlockCodeContent() }) } } is ContentHeading -> appendHeader(content.level) { appendContent(content.children) } |
