aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/renderers/DefaultRenderer.kt3
-rw-r--r--core/src/main/kotlin/renderers/HtmlRenderer.kt8
-rw-r--r--core/src/main/kotlin/resolvers/DefaultLocationProvider.kt14
-rw-r--r--core/src/main/kotlin/resolvers/LocationProvider.kt1
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
}