diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 4 | ||||
-rw-r--r-- | src/Formats/KotlinWebsiteFormatService.kt | 2 | ||||
-rw-r--r-- | src/Formats/MarkdownFormatService.kt | 5 | ||||
-rw-r--r-- | src/Formats/StructuredFormatService.kt | 12 | ||||
-rw-r--r-- | src/Locations/FoldersLocationService.kt | 8 | ||||
-rw-r--r-- | src/Locations/LocationService.kt | 13 | ||||
-rw-r--r-- | src/Locations/SingleFolderLocationService.kt | 9 | ||||
-rw-r--r-- | src/Utilities/Path.kt | 2 |
8 files changed, 28 insertions, 27 deletions
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<DocumentationNode>, 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<FormatLink>): 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<String>) @@ -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<DocumentationNode>) { @@ -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))) } } diff --git a/src/Locations/FoldersLocationService.kt b/src/Locations/FoldersLocationService.kt index 6f3954c4..4f56475c 100644 --- a/src/Locations/FoldersLocationService.kt +++ b/src/Locations/FoldersLocationService.kt @@ -2,10 +2,12 @@ package org.jetbrains.dokka import java.io.File -public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root)) -public class FoldersLocationService(val root: File) : FileLocationService { +public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root), "") +public class FoldersLocationService(val root: File, val extension: String) : FileLocationService { + override fun withExtension(newExtension: String): LocationService = FoldersLocationService(root, newExtension) + override fun location(node: DocumentationNode): FileLocation { - return FileLocation(File(root, relativePathToNode(node))) + return FileLocation(File(root, relativePathToNode(node)).appendExtension(extension)) } } diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index d364c511..96cd0c51 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -4,7 +4,7 @@ import java.io.File public trait Location { val path: String get - fun relativePathTo(other: Location, extension: String): String + fun relativePathTo(other: Location): String } /** @@ -19,13 +19,12 @@ public data class FileLocation(val file: File): Location { override val path : String get() = file.path - override fun relativePathTo(other: Location, extension: String): String { + override fun relativePathTo(other: Location): String { if (other !is FileLocation) { throw IllegalArgumentException("$other is not a FileLocation") } val ownerFolder = file.getParentFile()!! - val memberPath = other.file.appendExtension(extension) - return ownerFolder.getRelativePath(memberPath).path + return ownerFolder.getRelativePath(other.file).path } } @@ -39,6 +38,8 @@ public data class FileLocation(val file: File): Location { * for file names. */ public trait LocationService { + fun withExtension(newExtension: String) = this + /** * Calculates location for particular node in output structure */ @@ -60,6 +61,6 @@ public fun identifierToFilename(path: String): String { /** * Returns relative location between two nodes. Used for relative links in documentation. */ -fun LocationService.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode, extension: String): String { - return location(owner).relativePathTo(location(node), extension) +fun LocationService.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { + return location(owner).relativePathTo(location(node)) } diff --git a/src/Locations/SingleFolderLocationService.kt b/src/Locations/SingleFolderLocationService.kt index aefab450..e136a6b2 100644 --- a/src/Locations/SingleFolderLocationService.kt +++ b/src/Locations/SingleFolderLocationService.kt @@ -2,10 +2,13 @@ package org.jetbrains.dokka import java.io.File -public fun SingleFolderLocationService(root: String): SingleFolderLocationService = SingleFolderLocationService(File(root)) -public class SingleFolderLocationService(val root: File) : FileLocationService { +public fun SingleFolderLocationService(root: String): SingleFolderLocationService = SingleFolderLocationService(File(root), "") +public class SingleFolderLocationService(val root: File, val extension: String) : FileLocationService { + override fun withExtension(newExtension: String): LocationService = + SingleFolderLocationService(root, newExtension) + override fun location(node: DocumentationNode): FileLocation { val filename = node.path.map { identifierToFilename(it.name) }.joinToString("-") - return FileLocation(File(root, filename)) + return FileLocation(File(root, filename).appendExtension(extension)) } }
\ No newline at end of file diff --git a/src/Utilities/Path.kt b/src/Utilities/Path.kt index 63240e98..24420ec7 100644 --- a/src/Utilities/Path.kt +++ b/src/Utilities/Path.kt @@ -18,4 +18,4 @@ fun File.getRelativePath(name: File): File { } } -fun File.appendExtension(extension: String) = File(getPath() + "." + extension) +fun File.appendExtension(extension: String) = if (extension.isEmpty()) this else File(getPath() + "." + extension) |