aboutsummaryrefslogtreecommitdiff
path: root/src/Locations
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-02-19 19:51:01 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-02-19 19:51:01 +0100
commitea1f4cc2987536c3ed3df5899e6cec2df890f1e6 (patch)
treeceb0324a2829523587c750d771fc83d849ae4e13 /src/Locations
parentd9bfa029b0ecf300ae47cf1033db2d5cb323d705 (diff)
downloaddokka-ea1f4cc2987536c3ed3df5899e6cec2df890f1e6.tar.gz
dokka-ea1f4cc2987536c3ed3df5899e6cec2df890f1e6.tar.bz2
dokka-ea1f4cc2987536c3ed3df5899e6cec2df890f1e6.zip
refactor extension setup; encapsulate extension in LocationService
Diffstat (limited to 'src/Locations')
-rw-r--r--src/Locations/FoldersLocationService.kt8
-rw-r--r--src/Locations/LocationService.kt13
-rw-r--r--src/Locations/SingleFolderLocationService.kt9
3 files changed, 18 insertions, 12 deletions
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