From 51502a37aaedd97d92ad9f794c6918b18707d35d Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 5 Nov 2019 18:12:45 +0100 Subject: Adding csses --- core/src/main/kotlin/renderers/DefaultRenderer.kt | 3 +++ core/src/main/kotlin/renderers/HtmlRenderer.kt | 8 ++++++++ core/src/main/kotlin/resolvers/DefaultLocationProvider.kt | 14 ++++++++++---- core/src/main/kotlin/resolvers/LocationProvider.kt | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) (limited to 'core/src') 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) = """ | | |${page.name} + | | | |""".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): 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 = mutableListOf()): List = - if (pathNode == null) path - else getPath(pathNode.parent, path + pathNode.pathName() ) + fun getPath(pathNode: PageNode?, path: List = mutableListOf()): List = 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, context: PageNode? = null): String fun resolve(node: PageNode, context: PageNode? = null): String + fun resolveRoot(node: PageNode): String } -- cgit