aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Locations
diff options
context:
space:
mode:
authorSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-12-02 00:50:08 +0300
committerSimon Ogorodnik <Simon.Ogorodnik@jetbrains.com>2017-12-02 00:50:08 +0300
commit7acc52ba723eab08fe796fcfd68755e7f0eb6a66 (patch)
tree7760517756051bdaa14bdbb2ab61664ebc3993dc /core/src/main/kotlin/Locations
parent1b722f7c61ea3405b8f33612044b28f0b4087406 (diff)
downloaddokka-7acc52ba723eab08fe796fcfd68755e7f0eb6a66.tar.gz
dokka-7acc52ba723eab08fe796fcfd68755e7f0eb6a66.tar.bz2
dokka-7acc52ba723eab08fe796fcfd68755e7f0eb6a66.zip
WIP: Refactoring, remove LocationService, rework FormatDescriptor
Diffstat (limited to 'core/src/main/kotlin/Locations')
-rw-r--r--core/src/main/kotlin/Locations/FoldersLocationService.kt40
-rw-r--r--core/src/main/kotlin/Locations/LocationService.kt79
-rw-r--r--core/src/main/kotlin/Locations/SingleFolderLocationService.kt30
3 files changed, 79 insertions, 70 deletions
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<String>, hasMembers: Boolean): FileLocation {
- return FileLocation(File(rootFile, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension))
- }
-}
-
-fun relativePathToNode(qualifiedName: List<String>, 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<String>, 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<String>, hasMembers: Boolean): Location
-
- val root: Location
+fun relativePathToNode(qualifiedName: List<String>, 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<String>, 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<String>, 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<String>, 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<String>, 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<String>, 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