From ea1f4cc2987536c3ed3df5899e6cec2df890f1e6 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 19 Feb 2015 19:51:01 +0100 Subject: refactor extension setup; encapsulate extension in LocationService --- src/Formats/HtmlFormatService.kt | 4 +--- src/Formats/KotlinWebsiteFormatService.kt | 2 -- src/Formats/MarkdownFormatService.kt | 5 +---- src/Formats/StructuredFormatService.kt | 12 +++++++----- 4 files changed, 9 insertions(+), 14 deletions(-) (limited to 'src/Formats') diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index 8442c66f..733425d7 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -5,9 +5,7 @@ import java.io.File public open class HtmlFormatService(locationService: LocationService, signatureGenerator: LanguageService, val templateService: HtmlTemplateService = HtmlTemplateService.default()) -: StructuredFormatService(locationService, signatureGenerator), OutlineFormatService { - override val extension: String = "html" - +: StructuredFormatService(locationService, signatureGenerator, "html"), OutlineFormatService { override public fun formatText(text: String): String { return text.htmlEscape() } diff --git a/src/Formats/KotlinWebsiteFormatService.kt b/src/Formats/KotlinWebsiteFormatService.kt index 5e616fad..3ded2d6d 100644 --- a/src/Formats/KotlinWebsiteFormatService.kt +++ b/src/Formats/KotlinWebsiteFormatService.kt @@ -3,8 +3,6 @@ package org.jetbrains.dokka public class KotlinWebsiteFormatService(locationService: LocationService, signatureGenerator: LanguageService) : JekyllFormatService(locationService, signatureGenerator) { - override val extension: String = "md" - override fun appendFrontMatter(nodes: Iterable, to: StringBuilder) { super.appendFrontMatter(nodes, to) to.appendln("layout: api") diff --git a/src/Formats/MarkdownFormatService.kt b/src/Formats/MarkdownFormatService.kt index b855ec9c..281ca21d 100644 --- a/src/Formats/MarkdownFormatService.kt +++ b/src/Formats/MarkdownFormatService.kt @@ -3,10 +3,7 @@ package org.jetbrains.dokka public open class MarkdownFormatService(locationService: LocationService, signatureGenerator: LanguageService) -: StructuredFormatService(locationService, signatureGenerator) { - - override val extension: String = "md" - +: StructuredFormatService(locationService, signatureGenerator, "md") { override public fun formatBreadcrumbs(items: Iterable): String { return items.map { formatLink(it) }.joinToString(" / ") } diff --git a/src/Formats/StructuredFormatService.kt b/src/Formats/StructuredFormatService.kt index 32e22fd7..14eb490a 100644 --- a/src/Formats/StructuredFormatService.kt +++ b/src/Formats/StructuredFormatService.kt @@ -5,8 +5,10 @@ import org.jetbrains.dokka.LanguageService.RenderMode public data class FormatLink(val text: String, val href: String) -public abstract class StructuredFormatService(val locationService: LocationService, - val languageService: LanguageService) : FormatService { +public abstract class StructuredFormatService(locationService: LocationService, + val languageService: LanguageService, + override val extension: String) : FormatService { + val locationService: LocationService = locationService.withExtension(extension) abstract public fun appendBlockCode(to: StringBuilder, line: String) abstract public fun appendBlockCode(to: StringBuilder, lines: Iterable) @@ -54,7 +56,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi is ContentListItem -> append(formatListItem(formatText(location, content.children))) is ContentNodeLink -> { - val linkTo = location.relativePathTo(locationService.location(content.node), extension) + val linkTo = location.relativePathTo(locationService.location(content.node)) val linkText = formatText(location, content.children) append(formatLink(linkText, linkTo)) } @@ -76,7 +78,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi open public fun link(from: DocumentationNode, to: DocumentationNode): FormatLink = link(from, to, extension) open public fun link(from: DocumentationNode, to: DocumentationNode, extension: String): FormatLink { - return FormatLink(to.name, locationService.relativePathToLocation(from, to, extension)) + return FormatLink(to.name, locationService.relativePathToLocation(from, to)) } fun appendDocumentation(location: Location, to: StringBuilder, overloads: Iterable) { @@ -132,7 +134,7 @@ public abstract class StructuredFormatService(val locationService: LocationServi private fun DocumentationNode.appendOverrides(to: StringBuilder) { overrides.forEach { to.append("Overrides ") - val location = locationService.relativePathToLocation(this, it, extension) + val location = locationService.relativePathToLocation(this, it) appendLine(to, formatLink(FormatLink(it.owner!!.name + "." + it.name, location))) } } -- cgit