From 7acc52ba723eab08fe796fcfd68755e7f0eb6a66 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 00:50:08 +0300 Subject: WIP: Refactoring, remove LocationService, rework FormatDescriptor --- .../kotlin/Locations/FoldersLocationService.kt | 40 ++++------- core/src/main/kotlin/Locations/LocationService.kt | 79 ++++++++++++++-------- .../Locations/SingleFolderLocationService.kt | 30 ++++---- 3 files changed, 79 insertions(+), 70 deletions(-) (limited to 'core/src/main/kotlin/Locations') diff --git a/core/src/main/kotlin/Locations/FoldersLocationService.kt b/core/src/main/kotlin/Locations/FoldersLocationService.kt index 83e1cf6a..ae5301e7 100644 --- a/core/src/main/kotlin/Locations/FoldersLocationService.kt +++ b/core/src/main/kotlin/Locations/FoldersLocationService.kt @@ -3,28 +3,18 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.google.inject.name.Named import java.io.File - -class FoldersLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { - constructor(root: String): this(File(root), "") - - override val root: Location - get() = FileLocation(rootFile) - - override fun withExtension(newExtension: String): FileLocationService { - return if (extension.isEmpty()) FoldersLocationService(rootFile, newExtension) else this - } - - override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { - return FileLocation(File(rootFile, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) - } -} - -fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String { - val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } - return if (!hasMembers) { - // leaf node, use file in owner's folder - parts.joinToString("/") - } else { - parts.joinToString("/") + (if (parts.none()) "" else "/") + "index" - } -} +// +//class FoldersLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { +// constructor(root: String): this(File(root), "") +// +// override val root: Location +// get() = FileLocation(rootFile) +// +// override fun withExtension(newExtension: String): FileLocationService { +// return if (extension.isEmpty()) FoldersLocationService(rootFile, newExtension) else this +// } +// +// override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { +// return FileLocation(File(rootFile, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) +// } +//} diff --git a/core/src/main/kotlin/Locations/LocationService.kt b/core/src/main/kotlin/Locations/LocationService.kt index a51ef8d4..6b7e0511 100644 --- a/core/src/main/kotlin/Locations/LocationService.kt +++ b/core/src/main/kotlin/Locations/LocationService.kt @@ -32,37 +32,51 @@ data class FileLocation(val file: File): Location { } } -/** - * Provides means of retrieving locations for [DocumentationNode](documentation nodes) - * - * `LocationService` determines where documentation for particular node should be generated - * - * * [FoldersLocationService] – represent packages and types as folders, members as files in those folders. - * * [SingleFolderLocationService] – all documentation is generated into single folder using fully qualified names - * for file names. - */ -interface LocationService { - fun withExtension(newExtension: String) = this - fun location(node: DocumentationNode): Location = location(node.path.map { it.name }, node.members.any()) - /** - * Calculates a location corresponding to the specified [qualifiedName]. - * @param hasMembers if true, the node for which the location is calculated has member nodes. - */ - fun location(qualifiedName: List, hasMembers: Boolean): Location - - val root: Location +fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String { + val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } + return if (!hasMembers) { + // leaf node, use file in owner's folder + parts.joinToString("/") + } else { + parts.joinToString("/") + (if (parts.none()) "" else "/") + "index" + } } -interface FileLocationService: LocationService { - override fun withExtension(newExtension: String): FileLocationService = this - - override fun location(node: DocumentationNode): FileLocation = location(node.path.map { it.name }, node.members.any()) - override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation -} +// +///** +// * Provides means of retrieving locations for [DocumentationNode](documentation nodes) +// * +// * `LocationService` determines where documentation for particular node should be generated +// * +// * * [FoldersLocationService] – represent packages and types as folders, members as files in those folders. +// * * [SingleFolderLocationService] – all documentation is generated into single folder using fully qualified names +// * for file names. +// */ +//interface LocationService { +// fun withExtension(newExtension: String) = this +// +// fun location(node: DocumentationNode): Location = location(node.path.map { it.name }, node.members.any()) +// +// /** +// * Calculates a location corresponding to the specified [qualifiedName]. +// * @param hasMembers if true, the node for which the location is calculated has member nodes. +// */ +// fun location(qualifiedName: List, hasMembers: Boolean): Location +// +// val root: Location +//} +// +// +//interface FileLocationService: LocationService { +// override fun withExtension(newExtension: String): FileLocationService = this +// +// override fun location(node: DocumentationNode): FileLocation = location(node.path.map { it.name }, node.members.any()) +// override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation +//} fun identifierToFilename(path: String): String { val escaped = path.replace('<', '-').replace('>', '-') @@ -70,9 +84,14 @@ fun identifierToFilename(path: String): String { return if (lowercase == "index") "--index--" else lowercase } -/** - * Returns relative location between two nodes. Used for relative links in documentation. - */ -fun LocationService.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { +///** +// * Returns relative location between two nodes. Used for relative links in documentation. +// */ +//fun LocationService.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { +// return location(owner).relativePathTo(location(node), null) +//} + + +fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { return location(owner).relativePathTo(location(node), null) -} +} \ No newline at end of file diff --git a/core/src/main/kotlin/Locations/SingleFolderLocationService.kt b/core/src/main/kotlin/Locations/SingleFolderLocationService.kt index 1b4fdc28..25cf6f8e 100644 --- a/core/src/main/kotlin/Locations/SingleFolderLocationService.kt +++ b/core/src/main/kotlin/Locations/SingleFolderLocationService.kt @@ -3,18 +3,18 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.google.inject.name.Named import java.io.File - -class SingleFolderLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { - constructor(root: String): this(File(root), "") - - override fun withExtension(newExtension: String): FileLocationService = - SingleFolderLocationService(rootFile, newExtension) - - override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { - val filename = qualifiedName.map { identifierToFilename(it) }.joinToString("-") - return FileLocation(File(rootFile, filename).appendExtension(extension)) - } - - override val root: Location - get() = FileLocation(rootFile) -} \ No newline at end of file +// +//class SingleFolderLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { +// constructor(root: String): this(File(root), "") +// +// override fun withExtension(newExtension: String): FileLocationService = +// SingleFolderLocationService(rootFile, newExtension) +// +// override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { +// val filename = qualifiedName.map { identifierToFilename(it) }.joinToString("-") +// return FileLocation(File(rootFile, filename).appendExtension(extension)) +// } +// +// override val root: Location +// get() = FileLocation(rootFile) +//} \ No newline at end of file -- cgit From c7523225200a3e24d24fb3b0492d5c377246fc69 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 04:57:45 +0300 Subject: Make possible to calculate path to root --- core/src/main/kotlin/Formats/HtmlFormatService.kt | 9 ++------- core/src/main/kotlin/Formats/HtmlTemplateService.kt | 6 +++--- core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt | 4 ++-- core/src/main/kotlin/Generation/FileGenerator.kt | 2 ++ core/src/main/kotlin/Generation/Generator.kt | 3 +++ core/src/main/kotlin/Locations/LocationService.kt | 6 ++++++ 6 files changed, 18 insertions(+), 12 deletions(-) (limited to 'core/src/main/kotlin/Locations') diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt index 560d8597..0073553c 100644 --- a/core/src/main/kotlin/Formats/HtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt @@ -80,7 +80,7 @@ open class HtmlOutputBuilder(to: StringBuilder, } override fun appendNodes(nodes: Iterable) { - templateService.appendHeader(to, getPageTitle(nodes), locationService.calcPathToRoot(location)) + templateService.appendHeader(to, getPageTitle(nodes), generator.relativeToRoot(location)) super.appendNodes(nodes) templateService.appendFooter(to) } @@ -108,7 +108,7 @@ open class HtmlFormatService @Inject constructor(generator: NodeLocationAwareGen HtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, templateService) override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable) { - templateService.appendHeader(to, "Module Contents", locationService.calcPathToRoot(location)) + templateService.appendHeader(to, "Module Contents", generator.relativeToRoot(location)) super.appendOutline(location, to, nodes) templateService.appendFooter(to) } @@ -132,11 +132,6 @@ open class HtmlFormatService @Inject constructor(generator: NodeLocationAwareGen } } -private fun LocationService.calcPathToRoot(location: Location): Path { - val path = Paths.get(location.path) - return path.parent?.relativize(Paths.get(root.path + '/')) ?: path -} - fun getPageTitle(nodes: Iterable): String? { val breakdownByLocation = nodes.groupBy { node -> formatPageTitle(node) } return breakdownByLocation.keys.singleOrNull() diff --git a/core/src/main/kotlin/Formats/HtmlTemplateService.kt b/core/src/main/kotlin/Formats/HtmlTemplateService.kt index 22832e34..84e01910 100644 --- a/core/src/main/kotlin/Formats/HtmlTemplateService.kt +++ b/core/src/main/kotlin/Formats/HtmlTemplateService.kt @@ -1,9 +1,9 @@ package org.jetbrains.dokka -import java.nio.file.Path +import java.io.File interface HtmlTemplateService { - fun appendHeader(to: StringBuilder, title: String?, basePath: Path) + fun appendHeader(to: StringBuilder, title: String?, basePath: File) fun appendFooter(to: StringBuilder) companion object { @@ -16,7 +16,7 @@ interface HtmlTemplateService { to.appendln("") to.appendln("") } - override fun appendHeader(to: StringBuilder, title: String?, relativePathToRoot: String) { + override fun appendHeader(to: StringBuilder, title: String?, basePath: File) { to.appendln("") to.appendln("") to.appendln("") diff --git a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt index 208756c8..6ced75b5 100644 --- a/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/KotlinWebsiteHtmlFormatService.kt @@ -4,13 +4,13 @@ import com.google.inject.Inject import com.google.inject.name.Named import org.jetbrains.dokka.Utilities.impliedPlatformsName import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty -import java.nio.file.Path +import java.io.File object EmptyHtmlTemplateService : HtmlTemplateService { override fun appendFooter(to: StringBuilder) {} - override fun appendHeader(to: StringBuilder, title: String?, basePath: Path) {} + override fun appendHeader(to: StringBuilder, title: String?, basePath: File) {} } diff --git a/core/src/main/kotlin/Generation/FileGenerator.kt b/core/src/main/kotlin/Generation/FileGenerator.kt index 3193a5bc..9c7c65e6 100644 --- a/core/src/main/kotlin/Generation/FileGenerator.kt +++ b/core/src/main/kotlin/Generation/FileGenerator.kt @@ -14,6 +14,8 @@ class FileGenerator @Inject constructor(@Named("outputDir") val rootFile: File) @set:Inject(optional = true) lateinit var options: DocumentationOptions @set:Inject(optional = true) var packageListService: PackageListService? = null + override val root: File = rootFile + override fun location(node: DocumentationNode): FileLocation { return FileLocation(File(rootFile, relativePathToNode(node.path.map { it.name }, node.members.any())).appendExtension(formatService.extension)) } diff --git a/core/src/main/kotlin/Generation/Generator.kt b/core/src/main/kotlin/Generation/Generator.kt index 003386ef..23286e29 100644 --- a/core/src/main/kotlin/Generation/Generator.kt +++ b/core/src/main/kotlin/Generation/Generator.kt @@ -1,5 +1,7 @@ package org.jetbrains.dokka +import java.io.File + interface Generator { fun buildPages(nodes: Iterable) fun buildOutlines(nodes: Iterable) @@ -23,4 +25,5 @@ fun Generator.buildAll(node: DocumentationNode): Unit = buildAll(listOf(node)) interface NodeLocationAwareGenerator: Generator { fun location(node: DocumentationNode): Location + val root: File } \ No newline at end of file diff --git a/core/src/main/kotlin/Locations/LocationService.kt b/core/src/main/kotlin/Locations/LocationService.kt index 6b7e0511..8ea45dae 100644 --- a/core/src/main/kotlin/Locations/LocationService.kt +++ b/core/src/main/kotlin/Locations/LocationService.kt @@ -94,4 +94,10 @@ fun identifierToFilename(path: String): String { fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { return location(owner).relativePathTo(location(node), null) +} + + +fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { + val file = File(from.path) + return file.relativeTo(root) } \ No newline at end of file -- cgit From d6d5df5bc04be5274446e9f37a3e52672083da36 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Sat, 2 Dec 2017 05:58:30 +0300 Subject: Add actual relativePathToNode function --- core/src/main/kotlin/Generation/FileGenerator.kt | 2 +- core/src/main/kotlin/Locations/LocationService.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'core/src/main/kotlin/Locations') diff --git a/core/src/main/kotlin/Generation/FileGenerator.kt b/core/src/main/kotlin/Generation/FileGenerator.kt index ea34a269..3d25e932 100644 --- a/core/src/main/kotlin/Generation/FileGenerator.kt +++ b/core/src/main/kotlin/Generation/FileGenerator.kt @@ -21,7 +21,7 @@ class FileGenerator @Inject constructor(@Named("outputDir") val rootFile: File) } fun locationWithoutExtension(node: DocumentationNode): FileLocation { - return FileLocation(File(rootFile, relativePathToNode(node.path.map { it.name }, node.members.any()))) + return FileLocation(File(rootFile, relativePathToNode(node))) } override fun buildPages(nodes: Iterable) { diff --git a/core/src/main/kotlin/Locations/LocationService.kt b/core/src/main/kotlin/Locations/LocationService.kt index 8ea45dae..e453baca 100644 --- a/core/src/main/kotlin/Locations/LocationService.kt +++ b/core/src/main/kotlin/Locations/LocationService.kt @@ -44,6 +44,7 @@ fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String } } +fun relativePathToNode(node: DocumentationNode) = relativePathToNode(node.path.map { it.name }, node.members.any()) // -- cgit From 214e16e07d93b3565c433ed67b78796e80f43ec5 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 5 Dec 2017 18:25:08 +0300 Subject: Tidy around --- core/src/main/kotlin/Formats/StandardFormats.kt | 4 - .../kotlin/Locations/FoldersLocationService.kt | 20 ---- core/src/main/kotlin/Locations/Location.kt | 59 ++++++++++++ core/src/main/kotlin/Locations/LocationService.kt | 104 --------------------- .../Locations/SingleFolderLocationService.kt | 20 ---- core/src/main/kotlin/Utilities/DokkaModules.kt | 2 - 6 files changed, 59 insertions(+), 150 deletions(-) delete mode 100644 core/src/main/kotlin/Locations/FoldersLocationService.kt create mode 100644 core/src/main/kotlin/Locations/Location.kt delete mode 100644 core/src/main/kotlin/Locations/LocationService.kt delete mode 100644 core/src/main/kotlin/Locations/SingleFolderLocationService.kt (limited to 'core/src/main/kotlin/Locations') diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt index 71af1991..dd67ac97 100644 --- a/core/src/main/kotlin/Formats/StandardFormats.kt +++ b/core/src/main/kotlin/Formats/StandardFormats.kt @@ -47,10 +47,6 @@ class KotlinWebsiteHtmlFormatDescriptor : KotlinFormatDescriptorBase() { override val sampleProcessingService = KotlinWebsiteSampleProcessingService::class override val outlineServiceClass = YamlOutlineService::class - override fun configureAnalysis(binder: Binder) { - super.configureAnalysis(binder) - } - override fun configureOutput(binder: Binder) = with(binder) { super.configureOutput(binder) bind().toInstance(EmptyHtmlTemplateService) diff --git a/core/src/main/kotlin/Locations/FoldersLocationService.kt b/core/src/main/kotlin/Locations/FoldersLocationService.kt deleted file mode 100644 index ae5301e7..00000000 --- a/core/src/main/kotlin/Locations/FoldersLocationService.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.jetbrains.dokka - -import com.google.inject.Inject -import com.google.inject.name.Named -import java.io.File -// -//class FoldersLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { -// constructor(root: String): this(File(root), "") -// -// override val root: Location -// get() = FileLocation(rootFile) -// -// override fun withExtension(newExtension: String): FileLocationService { -// return if (extension.isEmpty()) FoldersLocationService(rootFile, newExtension) else this -// } -// -// override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { -// return FileLocation(File(rootFile, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) -// } -//} diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt new file mode 100644 index 00000000..17538ff5 --- /dev/null +++ b/core/src/main/kotlin/Locations/Location.kt @@ -0,0 +1,59 @@ +package org.jetbrains.dokka + +import java.io.File + +interface Location { + val path: String get + fun relativePathTo(other: Location, anchor: String? = null): String +} + +/** + * Represents locations in the documentation in the form of [path](File). + * + * $file: [File] for this location + * $path: [String] representing path of this location + */ +data class FileLocation(val file: File): Location { + override val path : String + get() = file.path + + override fun relativePathTo(other: Location, anchor: String?): String { + if (other !is FileLocation) { + throw IllegalArgumentException("$other is not a FileLocation") + } + if (file.path.substringBeforeLast(".") == other.file.path.substringBeforeLast(".") && anchor == null) { + return "./${file.name}" + } + val ownerFolder = file.parentFile!! + val relativePath = ownerFolder.toPath().relativize(other.file.toPath()).toString().replace(File.separatorChar, '/') + return if (anchor == null) relativePath else relativePath + "#" + anchor + } +} + + +fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String { + val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } + return if (!hasMembers) { + // leaf node, use file in owner's folder + parts.joinToString("/") + } else { + parts.joinToString("/") + (if (parts.none()) "" else "/") + "index" + } +} + +fun relativePathToNode(node: DocumentationNode) = relativePathToNode(node.path.map { it.name }, node.members.any()) + +fun identifierToFilename(path: String): String { + val escaped = path.replace('<', '-').replace('>', '-') + val lowercase = escaped.replace("[A-Z]".toRegex()) { matchResult -> "-" + matchResult.value.toLowerCase() } + return if (lowercase == "index") "--index--" else lowercase +} + +fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { + return location(owner).relativePathTo(location(node), null) +} + +fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { + val file = File(from.path) + return file.relativeTo(root) +} \ No newline at end of file diff --git a/core/src/main/kotlin/Locations/LocationService.kt b/core/src/main/kotlin/Locations/LocationService.kt deleted file mode 100644 index e453baca..00000000 --- a/core/src/main/kotlin/Locations/LocationService.kt +++ /dev/null @@ -1,104 +0,0 @@ -package org.jetbrains.dokka - -import java.io.File - -interface Location { - val path: String get - fun relativePathTo(other: Location, anchor: String? = null): String -} - -/** - * Represents locations in the documentation in the form of [path](File). - * - * Locations are provided by [LocationService.location] function. - * - * $file: [File] for this location - * $path: [String] representing path of this location - */ -data class FileLocation(val file: File): Location { - override val path : String - get() = file.path - - override fun relativePathTo(other: Location, anchor: String?): String { - if (other !is FileLocation) { - throw IllegalArgumentException("$other is not a FileLocation") - } - if (file.path.substringBeforeLast(".") == other.file.path.substringBeforeLast(".") && anchor == null) { - return "./${file.name}" - } - val ownerFolder = file.parentFile!! - val relativePath = ownerFolder.toPath().relativize(other.file.toPath()).toString().replace(File.separatorChar, '/') - return if (anchor == null) relativePath else relativePath + "#" + anchor - } -} - - - -fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String { - val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } - return if (!hasMembers) { - // leaf node, use file in owner's folder - parts.joinToString("/") - } else { - parts.joinToString("/") + (if (parts.none()) "" else "/") + "index" - } -} - -fun relativePathToNode(node: DocumentationNode) = relativePathToNode(node.path.map { it.name }, node.members.any()) - - -// -///** -// * Provides means of retrieving locations for [DocumentationNode](documentation nodes) -// * -// * `LocationService` determines where documentation for particular node should be generated -// * -// * * [FoldersLocationService] – represent packages and types as folders, members as files in those folders. -// * * [SingleFolderLocationService] – all documentation is generated into single folder using fully qualified names -// * for file names. -// */ -//interface LocationService { -// fun withExtension(newExtension: String) = this -// -// fun location(node: DocumentationNode): Location = location(node.path.map { it.name }, node.members.any()) -// -// /** -// * Calculates a location corresponding to the specified [qualifiedName]. -// * @param hasMembers if true, the node for which the location is calculated has member nodes. -// */ -// fun location(qualifiedName: List, hasMembers: Boolean): Location -// -// val root: Location -//} -// -// -//interface FileLocationService: LocationService { -// override fun withExtension(newExtension: String): FileLocationService = this -// -// override fun location(node: DocumentationNode): FileLocation = location(node.path.map { it.name }, node.members.any()) -// override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation -//} - -fun identifierToFilename(path: String): String { - val escaped = path.replace('<', '-').replace('>', '-') - val lowercase = escaped.replace("[A-Z]".toRegex()) { matchResult -> "-" + matchResult.value.toLowerCase() } - return if (lowercase == "index") "--index--" else lowercase -} - -///** -// * Returns relative location between two nodes. Used for relative links in documentation. -// */ -//fun LocationService.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { -// return location(owner).relativePathTo(location(node), null) -//} - - -fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, node: DocumentationNode): String { - return location(owner).relativePathTo(location(node), null) -} - - -fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { - val file = File(from.path) - return file.relativeTo(root) -} \ No newline at end of file diff --git a/core/src/main/kotlin/Locations/SingleFolderLocationService.kt b/core/src/main/kotlin/Locations/SingleFolderLocationService.kt deleted file mode 100644 index 25cf6f8e..00000000 --- a/core/src/main/kotlin/Locations/SingleFolderLocationService.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.jetbrains.dokka - -import com.google.inject.Inject -import com.google.inject.name.Named -import java.io.File -// -//class SingleFolderLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { -// constructor(root: String): this(File(root), "") -// -// override fun withExtension(newExtension: String): FileLocationService = -// SingleFolderLocationService(rootFile, newExtension) -// -// override fun location(qualifiedName: List, hasMembers: Boolean): FileLocation { -// val filename = qualifiedName.map { identifierToFilename(it) }.joinToString("-") -// return FileLocation(File(rootFile, filename).appendExtension(extension)) -// } -// -// override val root: Location -// get() = FileLocation(rootFile) -//} \ No newline at end of file diff --git a/core/src/main/kotlin/Utilities/DokkaModules.kt b/core/src/main/kotlin/Utilities/DokkaModules.kt index fcc2f692..6b5e153e 100644 --- a/core/src/main/kotlin/Utilities/DokkaModules.kt +++ b/core/src/main/kotlin/Utilities/DokkaModules.kt @@ -24,8 +24,6 @@ class DokkaAnalysisModule(val environment: AnalysisEnvironment, override fun configure(binder: Binder) { binder.bind().toInstance(logger) - binder.registerCategory("language") - val coreEnvironment = environment.createCoreEnvironment() binder.bind().toInstance(coreEnvironment) -- cgit From dbd4774ffae19ff4d52cd21c7cb3906cdc3e0b5c Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 15 Dec 2017 01:00:32 +0300 Subject: Normalize file path's when using as URI --- core/src/main/kotlin/Formats/HtmlTemplateService.kt | 2 +- core/src/main/kotlin/Locations/Location.kt | 10 ++++++---- core/src/test/kotlin/format/FileGeneratorTestCase.kt | 7 ++----- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'core/src/main/kotlin/Locations') diff --git a/core/src/main/kotlin/Formats/HtmlTemplateService.kt b/core/src/main/kotlin/Formats/HtmlTemplateService.kt index 84e01910..a65a7b18 100644 --- a/core/src/main/kotlin/Formats/HtmlTemplateService.kt +++ b/core/src/main/kotlin/Formats/HtmlTemplateService.kt @@ -24,7 +24,7 @@ interface HtmlTemplateService { to.appendln("$title") } if (css != null) { - val cssPath = basePath.resolve(css) + val cssPath = basePath.resolve(css).toUnixString() to.appendln("") } to.appendln("") diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt index 17538ff5..0e6572d9 100644 --- a/core/src/main/kotlin/Locations/Location.kt +++ b/core/src/main/kotlin/Locations/Location.kt @@ -13,8 +13,8 @@ interface Location { * $file: [File] for this location * $path: [String] representing path of this location */ -data class FileLocation(val file: File): Location { - override val path : String +data class FileLocation(val file: File) : Location { + override val path: String get() = file.path override fun relativePathTo(other: Location, anchor: String?): String { @@ -30,7 +30,6 @@ data class FileLocation(val file: File): Location { } } - fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String { val parts = qualifiedName.map { identifierToFilename(it) }.filterNot { it.isEmpty() } return if (!hasMembers) { @@ -41,6 +40,7 @@ fun relativePathToNode(qualifiedName: List, hasMembers: Boolean): String } } + fun relativePathToNode(node: DocumentationNode) = relativePathToNode(node.path.map { it.name }, node.members.any()) fun identifierToFilename(path: String): String { @@ -56,4 +56,6 @@ fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { val file = File(from.path) return file.relativeTo(root) -} \ No newline at end of file +} + +fun File.toUnixString() = toString().replace(File.separatorChar, '/') diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt index 644d5baa..948426ea 100644 --- a/core/src/test/kotlin/format/FileGeneratorTestCase.kt +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -1,9 +1,6 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.DocumentationNode -import org.jetbrains.dokka.FileGenerator -import org.jetbrains.dokka.FormatService -import org.jetbrains.dokka.relativeToRoot +import org.jetbrains.dokka.* import org.junit.Before import org.junit.Rule import org.junit.rules.TemporaryFolder @@ -30,7 +27,7 @@ abstract class FileGeneratorTestCase { if (sb.isNotBlank() && !sb.endsWith('\n')) { sb.appendln() } - sb.appendln("") + sb.appendln("") } sb.append(loc.file.readText()) } -- cgit From 9865da2e6e6c038ab6c719a6a03bb09184542d20 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 17 May 2018 19:48:44 +0300 Subject: Fix incorrect link to stylesheet in html format --- core/src/main/kotlin/Formats/HtmlFormatService.kt | 5 ++--- core/src/main/kotlin/Generation/FileGenerator.kt | 4 +--- core/src/main/kotlin/Locations/Location.kt | 6 +++--- core/src/test/kotlin/format/FileGeneratorTestCase.kt | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) (limited to 'core/src/main/kotlin/Locations') diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt index 0073553c..0ad946be 100644 --- a/core/src/main/kotlin/Formats/HtmlFormatService.kt +++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt @@ -4,7 +4,6 @@ import com.google.inject.Inject import com.google.inject.name.Named import org.jetbrains.dokka.Utilities.impliedPlatformsName import java.io.File -import java.nio.file.Path open class HtmlOutputBuilder(to: StringBuilder, location: Location, @@ -80,7 +79,7 @@ open class HtmlOutputBuilder(to: StringBuilder, } override fun appendNodes(nodes: Iterable) { - templateService.appendHeader(to, getPageTitle(nodes), generator.relativeToRoot(location)) + templateService.appendHeader(to, getPageTitle(nodes), generator.relativePathToRoot(location)) super.appendNodes(nodes) templateService.appendFooter(to) } @@ -108,7 +107,7 @@ open class HtmlFormatService @Inject constructor(generator: NodeLocationAwareGen HtmlOutputBuilder(to, location, generator, languageService, extension, impliedPlatforms, templateService) override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable) { - templateService.appendHeader(to, "Module Contents", generator.relativeToRoot(location)) + templateService.appendHeader(to, "Module Contents", generator.relativePathToRoot(location)) super.appendOutline(location, to, nodes) templateService.appendFooter(to) } diff --git a/core/src/main/kotlin/Generation/FileGenerator.kt b/core/src/main/kotlin/Generation/FileGenerator.kt index bc08e180..b7c6cf63 100644 --- a/core/src/main/kotlin/Generation/FileGenerator.kt +++ b/core/src/main/kotlin/Generation/FileGenerator.kt @@ -8,15 +8,13 @@ import java.io.FileOutputStream import java.io.IOException import java.io.OutputStreamWriter -class FileGenerator @Inject constructor(@Named("outputDir") val rootFile: File) : NodeLocationAwareGenerator { +class FileGenerator @Inject constructor(@Named("outputDir") override val root: File) : NodeLocationAwareGenerator { @set:Inject(optional = true) var outlineService: OutlineFormatService? = null @set:Inject(optional = true) lateinit var formatService: FormatService @set:Inject(optional = true) lateinit var options: DocumentationOptions @set:Inject(optional = true) var packageListService: PackageListService? = null - override val root: File = rootFile - override fun location(node: DocumentationNode): FileLocation { return FileLocation(fileForNode(node, formatService.linkExtension)) } diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt index 0e6572d9..4cb0ac39 100644 --- a/core/src/main/kotlin/Locations/Location.kt +++ b/core/src/main/kotlin/Locations/Location.kt @@ -53,9 +53,9 @@ fun NodeLocationAwareGenerator.relativePathToLocation(owner: DocumentationNode, return location(owner).relativePathTo(location(node), null) } -fun NodeLocationAwareGenerator.relativeToRoot(from: Location): File { - val file = File(from.path) - return file.relativeTo(root) +fun NodeLocationAwareGenerator.relativePathToRoot(from: Location): File { + val file = File(from.path).parentFile + return root.relativeTo(file) } fun File.toUnixString() = toString().replace(File.separatorChar, '/') diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt index 948426ea..ef9e815d 100644 --- a/core/src/test/kotlin/format/FileGeneratorTestCase.kt +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -27,7 +27,7 @@ abstract class FileGeneratorTestCase { if (sb.isNotBlank() && !sb.endsWith('\n')) { sb.appendln() } - sb.appendln("") + sb.appendln("") } sb.append(loc.file.readText()) } -- cgit