diff options
author | Dmitry Jemerov <intelliyole@gmail.com> | 2015-12-03 12:13:17 +0100 |
---|---|---|
committer | Dmitry Jemerov <intelliyole@gmail.com> | 2015-12-03 12:13:17 +0100 |
commit | 797cb4732c53bf1e3b2091add8cf731fc436607f (patch) | |
tree | 5470caa451bdea99c371793bcc5411e179d1df71 /src | |
parent | 610ca01d0e2d6443f19b4218b26863cdacce07f1 (diff) | |
parent | 90cf2ebccd12073a55ff6f187e5a378a2e96e23b (diff) | |
download | dokka-797cb4732c53bf1e3b2091add8cf731fc436607f.tar.gz dokka-797cb4732c53bf1e3b2091add8cf731fc436607f.tar.bz2 dokka-797cb4732c53bf1e3b2091add8cf731fc436607f.zip |
Merge pull request #38 from mikehearn/style-css
Enable browsing of the output HTML with CSS
Diffstat (limited to 'src')
-rw-r--r-- | src/Formats/HtmlFormatService.kt | 7 | ||||
-rw-r--r-- | src/Formats/HtmlTemplateService.kt | 9 | ||||
-rw-r--r-- | src/Generation/FileGenerator.kt | 6 | ||||
-rw-r--r-- | src/Generation/Generator.kt | 2 | ||||
-rw-r--r-- | src/Locations/FoldersLocationService.kt | 8 | ||||
-rw-r--r-- | src/Locations/LocationService.kt | 4 | ||||
-rw-r--r-- | src/Locations/SingleFolderLocationService.kt | 9 | ||||
-rw-r--r-- | src/Utilities/DokkaModule.kt | 2 | ||||
-rw-r--r-- | src/Utilities/Path.kt | 14 | ||||
-rw-r--r-- | src/main.kt | 4 |
10 files changed, 36 insertions, 29 deletions
diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index e810ef7f..2c461905 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -3,6 +3,7 @@ package org.jetbrains.dokka import com.google.inject.Inject import com.google.inject.name.Named import java.io.File +import java.nio.file.Paths public open class HtmlFormatService @Inject constructor(@Named("folders") locationService: LocationService, signatureGenerator: LanguageService, @@ -113,17 +114,19 @@ public open class HtmlFormatService @Inject constructor(@Named("folders") locati override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { - templateService.appendHeader(to, getPageTitle(nodes)) + templateService.appendHeader(to, getPageTitle(nodes), calcPathToRoot(location)) super.appendNodes(location, to, nodes) templateService.appendFooter(to) } override fun appendOutline(location: Location, to: StringBuilder, nodes: Iterable<DocumentationNode>) { - templateService.appendHeader(to, "Module Contents") + templateService.appendHeader(to, "Module Contents", calcPathToRoot(location)) super.appendOutline(location, to, nodes) templateService.appendFooter(to) } + private fun calcPathToRoot(location: Location) = Paths.get(location.path).parent.relativize(Paths.get(locationService.root.path + '/')) + override fun getOutlineFileName(location: Location): File { return File("${location.path}-outline.html") } diff --git a/src/Formats/HtmlTemplateService.kt b/src/Formats/HtmlTemplateService.kt index b9900757..ae42a31b 100644 --- a/src/Formats/HtmlTemplateService.kt +++ b/src/Formats/HtmlTemplateService.kt @@ -1,7 +1,9 @@ package org.jetbrains.dokka +import java.nio.file.Path + public interface HtmlTemplateService { - fun appendHeader(to: StringBuilder, title: String?) + fun appendHeader(to: StringBuilder, title: String?, basePath: Path) fun appendFooter(to: StringBuilder) companion object { @@ -11,14 +13,15 @@ public interface HtmlTemplateService { to.appendln("</BODY>") to.appendln("</HTML>") } - override fun appendHeader(to: StringBuilder, title: String?) { + override fun appendHeader(to: StringBuilder, title: String?, basePath: Path) { to.appendln("<HTML>") to.appendln("<HEAD>") if (title != null) { to.appendln("<title>$title</title>") } if (css != null) { - to.appendln("<link rel=\"stylesheet\" href=\"$css\">") + val cssPath = basePath.resolve(css) + to.appendln("<link rel=\"stylesheet\" href=\"$cssPath\">") } to.appendln("</HEAD>") to.appendln("<BODY>") diff --git a/src/Generation/FileGenerator.kt b/src/Generation/FileGenerator.kt index 810038fa..a762bae3 100644 --- a/src/Generation/FileGenerator.kt +++ b/src/Generation/FileGenerator.kt @@ -42,6 +42,12 @@ public class FileGenerator @Inject constructor(val locationService: FileLocation } } } + + override fun buildSupportFiles() { + FileOutputStream(locationService.location(listOf("style.css"), false).file).use { + javaClass.getResourceAsStream("/dokka/styles/style.css").copyTo(it) + } + } } private fun File.mkdirsOrFail() { diff --git a/src/Generation/Generator.kt b/src/Generation/Generator.kt index d7db1c52..ac10a6a5 100644 --- a/src/Generation/Generator.kt +++ b/src/Generation/Generator.kt @@ -3,11 +3,13 @@ package org.jetbrains.dokka public interface Generator { fun buildPages(nodes: Iterable<DocumentationNode>) fun buildOutlines(nodes: Iterable<DocumentationNode>) + fun buildSupportFiles() } fun Generator.buildAll(nodes: Iterable<DocumentationNode>) { buildPages(nodes) buildOutlines(nodes) + buildSupportFiles() } fun Generator.buildPage(node: DocumentationNode): Unit = buildPages(listOf(node)) diff --git a/src/Locations/FoldersLocationService.kt b/src/Locations/FoldersLocationService.kt index 8a0cf6be..89b34ed1 100644 --- a/src/Locations/FoldersLocationService.kt +++ b/src/Locations/FoldersLocationService.kt @@ -5,14 +5,16 @@ import com.google.inject.name.Named import java.io.File public fun FoldersLocationService(root: String): FoldersLocationService = FoldersLocationService(File(root), "") -public class FoldersLocationService @Inject constructor(@Named("outputDir") val root: File, val extension: String) : FileLocationService { +public class FoldersLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { + override val root: Location + get() = FileLocation(rootFile) override fun withExtension(newExtension: String): FileLocationService { - return if (extension.isEmpty()) FoldersLocationService(root, newExtension) else this + return if (extension.isEmpty()) FoldersLocationService(rootFile, newExtension) else this } override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation { - return FileLocation(File(root, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) + return FileLocation(File(rootFile, relativePathToNode(qualifiedName, hasMembers)).appendExtension(extension)) } } diff --git a/src/Locations/LocationService.kt b/src/Locations/LocationService.kt index 4f587361..80bc0236 100644 --- a/src/Locations/LocationService.kt +++ b/src/Locations/LocationService.kt @@ -27,7 +27,7 @@ public data class FileLocation(val file: File): Location { return "." } val ownerFolder = file.parentFile!! - val relativePath = ownerFolder.getRelativePath(other.file).path + val relativePath = ownerFolder.toPath().relativize(other.file.toPath()).toString() return if (anchor == null) relativePath else relativePath + "#" + anchor } } @@ -51,6 +51,8 @@ public interface LocationService { * @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 } diff --git a/src/Locations/SingleFolderLocationService.kt b/src/Locations/SingleFolderLocationService.kt index 049636c0..e313ac28 100644 --- a/src/Locations/SingleFolderLocationService.kt +++ b/src/Locations/SingleFolderLocationService.kt @@ -5,12 +5,15 @@ import com.google.inject.name.Named import java.io.File public fun SingleFolderLocationService(root: String): SingleFolderLocationService = SingleFolderLocationService(File(root), "") -public class SingleFolderLocationService @Inject constructor(@Named("outputDir") val root: File, val extension: String) : FileLocationService { +public class SingleFolderLocationService @Inject constructor(@Named("outputDir") val rootFile: File, val extension: String) : FileLocationService { override fun withExtension(newExtension: String): FileLocationService = - SingleFolderLocationService(root, newExtension) + SingleFolderLocationService(rootFile, newExtension) override fun location(qualifiedName: List<String>, hasMembers: Boolean): FileLocation { val filename = qualifiedName.map { identifierToFilename(it) }.joinToString("-") - return FileLocation(File(root, filename).appendExtension(extension)) + return FileLocation(File(rootFile, filename).appendExtension(extension)) } + + override val root: Location + get() = FileLocation(rootFile) }
\ No newline at end of file diff --git a/src/Utilities/DokkaModule.kt b/src/Utilities/DokkaModule.kt index 3b2d26f1..1eb82313 100644 --- a/src/Utilities/DokkaModule.kt +++ b/src/Utilities/DokkaModule.kt @@ -26,7 +26,7 @@ class DokkaModule(val environment: AnalysisEnvironment, binder.bind(LanguageService::class.java).to(KotlinLanguageService::class.java) binder.bind(HtmlTemplateService::class.java).toProvider(object : Provider<HtmlTemplateService> { - override fun get(): HtmlTemplateService = HtmlTemplateService.default("/dokka/styles/style.css") + override fun get(): HtmlTemplateService = HtmlTemplateService.default("style.css") }) binder.registerCategory<LanguageService>("language") diff --git a/src/Utilities/Path.kt b/src/Utilities/Path.kt index 36277d9f..05838499 100644 --- a/src/Utilities/Path.kt +++ b/src/Utilities/Path.kt @@ -1,19 +1,5 @@ package org.jetbrains.dokka import java.io.File -import java.io.IOException - -fun File.getRelativePath(name: File): File { - val parent = parentFile ?: throw IOException("No common directory") - - val basePath = canonicalPath + File.separator; - val targetPath = name.canonicalPath; - - if (targetPath.startsWith(basePath)) { - return File(targetPath.substring(basePath.length)) - } else { - return File(".." + File.separator + parent.getRelativePath(name)) - } -} fun File.appendExtension(extension: String) = if (extension.isEmpty()) this else File(path + "." + extension) diff --git a/src/main.kt b/src/main.kt index ef694981..5a7514c4 100644 --- a/src/main.kt +++ b/src/main.kt @@ -93,7 +93,7 @@ public fun main(args: Array<String>) { samples, includes, arguments.moduleName, - arguments.outputDir, + arguments.outputDir.let { if (it.endsWith('/')) it else it + '/' }, arguments.outputFormat, sourceLinks, arguments.nodeprecated) @@ -148,7 +148,7 @@ class DokkaGenerator(val logger: DokkaLogger, val environment = createAnalysisEnvironment() logger.info("Module: $moduleName") - logger.info("Output: ${File(outputDir).absolutePath}") + logger.info("Output: ${File(outputDir)}") logger.info("Sources: ${environment.sources.joinToString()}") logger.info("Classpath: ${environment.classpath.joinToString()}") |