diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-05 18:12:45 +0100 |
---|---|---|
committer | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-05 18:12:59 +0100 |
commit | 51502a37aaedd97d92ad9f794c6918b18707d35d (patch) | |
tree | 6e79ec3c8d13203dce9fbfdc636663792f485e0e /core | |
parent | ab02673643d2a127152e295c78792f6821ee5960 (diff) | |
download | dokka-51502a37aaedd97d92ad9f794c6918b18707d35d.tar.gz dokka-51502a37aaedd97d92ad9f794c6918b18707d35d.tar.bz2 dokka-51502a37aaedd97d92ad9f794c6918b18707d35d.zip |
Adding csses
Diffstat (limited to 'core')
4 files changed, 22 insertions, 4 deletions
diff --git a/core/src/main/kotlin/renderers/DefaultRenderer.kt b/core/src/main/kotlin/renderers/DefaultRenderer.kt index e3b3fbeb..c5c12598 100644 --- a/core/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/core/src/main/kotlin/renderers/DefaultRenderer.kt @@ -43,6 +43,8 @@ abstract class DefaultRenderer(val fileWriter: FileWriter, val locationProvider: root.children.forEach { renderPages(it) } } + protected open fun buildSupportFiles() {} + protected open fun renderPackageList(root: PageNode) = getPackageNamesAndPlatforms(root) .keys @@ -61,6 +63,7 @@ abstract class DefaultRenderer(val fileWriter: FileWriter, val locationProvider: override fun render(root: PageNode) { renderPackageList(root) + buildSupportFiles() renderPages(root) } } diff --git a/core/src/main/kotlin/renderers/HtmlRenderer.kt b/core/src/main/kotlin/renderers/HtmlRenderer.kt index 9b76f719..ce0e6b73 100644 --- a/core/src/main/kotlin/renderers/HtmlRenderer.kt +++ b/core/src/main/kotlin/renderers/HtmlRenderer.kt @@ -5,6 +5,8 @@ import org.jetbrains.dokka.pages.ContentLink import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.resolvers.LocationProvider +import java.io.File +import java.io.InputStreamReader open class HtmlRenderer(fileWriter: FileWriter, locationProvider: LocationProvider): DefaultRenderer(fileWriter, locationProvider) { @@ -36,10 +38,16 @@ open class HtmlRenderer(fileWriter: FileWriter, locationProvider: LocationProvid fileWriter.write(locationProvider.resolve(page), pageText, "") } + override fun buildSupportFiles() { + fileWriter.write("style.css", + InputStreamReader(javaClass.getResourceAsStream("/dokka/styles/style.css")).readText()) + } + protected open fun buildStartHtml(page: PageNode) = """<!DOCTYPE html> |<html> |<head> |<title>${page.name}</title> + |<link rel="stylesheet" href="${locationProvider.resolveRoot(page)}style.css" /> |</head> |<body> |""".trimMargin() diff --git a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt index c5243233..f8faa45b 100644 --- a/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt +++ b/core/src/main/kotlin/resolvers/DefaultLocationProvider.kt @@ -17,6 +17,9 @@ open class DefaultLocationProvider(private val pageGraphRoot: PageNode, val conf .flatMap { it.externalDocumentationLinks }.map { it.packageListUrl }.distinct() ) + override fun resolveRoot(node: PageNode): String = "../${pathTo(pageGraphRoot, node).removeSuffix( + PAGE_WITH_CHILDREN_SUFFIX)}" + protected open fun findInPageGraph(dri: DRI, platforms: List<PlatformData>): PageNode? = pageGraphRoot.dfs { it.dri == dri } protected open fun pathTo(node: PageNode, context: PageNode?): String { @@ -25,12 +28,15 @@ open class DefaultLocationProvider(private val pageGraphRoot: PageNode, val conf if (this is PackagePageNode) name else identifierToFilename(name) - fun getPath(pathNode: PageNode?, path: List<String> = mutableListOf()): List<String> = - if (pathNode == null) path - else getPath(pathNode.parent, path + pathNode.pathName() ) + fun getPath(pathNode: PageNode?, path: List<String> = mutableListOf()): List<String> = when(pathNode) { + null -> path + pageGraphRoot -> path + "root" + else -> getPath(pathNode.parent, path + pathNode.pathName()) + } + val contextNode = if (context?.children?.isEmpty() == true) context.parent else context val nodePath = getPath(node).reversed() - val contextPath = getPath(context).reversed() + val contextPath = getPath(contextNode).reversed() val commonPathElements = nodePath.zip(contextPath).takeWhile { (a, b) -> a == b }.size diff --git a/core/src/main/kotlin/resolvers/LocationProvider.kt b/core/src/main/kotlin/resolvers/LocationProvider.kt index e55c712d..9f02d347 100644 --- a/core/src/main/kotlin/resolvers/LocationProvider.kt +++ b/core/src/main/kotlin/resolvers/LocationProvider.kt @@ -7,4 +7,5 @@ import org.jetbrains.dokka.pages.PlatformData interface LocationProvider { fun resolve(dri: DRI, platforms: List<PlatformData>, context: PageNode? = null): String fun resolve(node: PageNode, context: PageNode? = null): String + fun resolveRoot(node: PageNode): String } |