aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers
diff options
context:
space:
mode:
authorMarcin Aman <marcin.aman@gmail.com>2021-08-04 17:02:31 +0200
committerMarcin Aman <marcin.aman@gmail.com>2021-08-12 13:21:40 +0200
commit0fe8352ab057dfbbf690a723b2ccfc15b9977f4a (patch)
tree7017e7169950f907206832c862dce5e711e3cae8 /plugins/base/src/main/kotlin/renderers
parent42c0320e0c5f2d79a5438558bb87d4668aa4c3cc (diff)
downloaddokka-0fe8352ab057dfbbf690a723b2ccfc15b9977f4a.tar.gz
dokka-0fe8352ab057dfbbf690a723b2ccfc15b9977f4a.tar.bz2
dokka-0fe8352ab057dfbbf690a723b2ccfc15b9977f4a.zip
Webhelp-like frontend
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt66
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt39
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt1
4 files changed, 63 insertions, 47 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index d63e8da6..77086695 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -15,6 +15,7 @@ import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint
import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider
import org.jetbrains.dokka.base.templating.InsertTemplateExtra
import org.jetbrains.dokka.base.templating.PathToRootSubstitutionCommand
+import org.jetbrains.dokka.base.templating.ProjectNameSubstitutionCommand
import org.jetbrains.dokka.base.templating.ResolveLinkCommand
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.DisplaySourceSet
@@ -603,22 +604,13 @@ open class HtmlRenderer(
override fun FlowContent.buildNavigation(page: PageNode) =
- div("navigation-wrapper") {
- id = "navigation-wrapper"
- div(classes = "breadcrumbs") {
- val path = locationProvider.ancestors(page).filterNot { it is RendererSpecificPage }.asReversed()
- if (path.isNotEmpty()) {
- buildNavigationElement(path.first(), page)
- path.drop(1).forEach { node ->
- text("/")
- buildNavigationElement(node, page)
- }
- }
- }
- div("pull-right d-flex") {
- filterButtons(page)
- div {
- id = "searchBar"
+ div(classes = "breadcrumbs") {
+ val path = locationProvider.ancestors(page).filterNot { it is RendererSpecificPage }.asReversed()
+ if (path.size > 1) {
+ buildNavigationElement(path.first(), page)
+ path.drop(1).forEach { node ->
+ text("/")
+ buildNavigationElement(node, page)
}
}
}
@@ -685,7 +677,8 @@ open class HtmlRenderer(
pageContext: ContentPage
) {
div("sample-container") {
- code(code.style.joinToString(" ") { it.toString().toLowerCase() }) {
+ val stylesWithBlock = code.style + TextStyle.Block
+ code(stylesWithBlock.joinToString(" ") { it.toString().toLowerCase() }) {
attributes["theme"] = "idea"
pre {
code.children.forEach { buildContentNode(it, pageContext) }
@@ -716,7 +709,7 @@ open class HtmlRenderer(
}
unappliedStyles.isNotEmpty() -> {
val styleToApply = unappliedStyles.first()
- applyStyle(styleToApply){
+ applyStyle(styleToApply) {
buildText(textNode, unappliedStyles - styleToApply)
}
}
@@ -726,8 +719,8 @@ open class HtmlRenderer(
}
}
- private inline fun FlowContent.applyStyle(styleToApply: Style, crossinline body: FlowContent.() -> Unit){
- when(styleToApply){
+ private inline fun FlowContent.applyStyle(styleToApply: Style, crossinline body: FlowContent.() -> Unit) {
+ when (styleToApply) {
TextStyle.Bold -> b { body() }
TextStyle.Italic -> i { body() }
TextStyle.Strikethrough -> strike { body() }
@@ -803,14 +796,25 @@ open class HtmlRenderer(
}
}
body {
+ div("navigation-wrapper") {
+ id = "navigation-wrapper"
+ div("library-name") {
+ clickableLogo(page, pathToRoot)
+ }
+ context.configuration.moduleVersion?.let { moduleVersion ->
+ div { text(moduleVersion) }
+ }
+ div("pull-right d-flex") {
+ filterButtons(page)
+ div {
+ id = "searchBar"
+ }
+ }
+ }
div {
id = "container"
div {
id = "leftColumn"
- clickableLogo(page, pathToRoot)
- div {
- id = "paneSearch"
- }
div {
id = "sideMenu"
}
@@ -857,15 +861,17 @@ open class HtmlRenderer(
templateCommand(PathToRootSubstitutionCommand(pattern = "###", default = pathToRoot)) {
a {
href = "###index.html"
- div {
- id = "logo"
+ templateCommand(ProjectNameSubstitutionCommand(pattern = "@@@", default = context.configuration.moduleName)) {
+ span {
+ text("@@@")
+ }
}
}
}
- } else a {
- href = pathToRoot + "index.html"
- div {
- id = "logo"
+ } else {
+ a {
+ href = pathToRoot + "index.html"
+ text(context.configuration.moduleName)
}
}
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
index e2953d46..e0b20f01 100644
--- a/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/NavigationPage.kt
@@ -40,13 +40,13 @@ class NavigationPage(val root: NavigationNode, val moduleName: String, val conte
id = navId
attributes["pageId"] = "${moduleName}::${node.pageId}"
div("overview") {
- buildLink(node.dri, node.sourceSets.toList()) { buildBreakableText(node.name) }
if (node.children.isNotEmpty()) {
- span("navButton pull-right") {
+ span("navButton") {
onClick = """document.getElementById("$navId").classList.toggle("hidden");"""
span("navButtonContent")
}
}
+ buildLink(node.dri, node.sourceSets.toList()) { buildBreakableText(node.name) }
}
node.children.withIndex().forEach { (n, p) -> visit(p, "$navId-$n", renderer) }
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
index b9eab293..19079241 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlFormatingUtils.kt
@@ -3,7 +3,7 @@ package org.jetbrains.dokka.base.renderers.html
import kotlinx.html.FlowContent
import kotlinx.html.span
-fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String) {
+fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String, hasLastElement: Boolean = false) {
if (name.contains(" ")) {
val withOutSpaces = name.split(" ")
withOutSpaces.dropLast(1).forEach {
@@ -13,7 +13,7 @@ fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String) {
buildBreakableText(withOutSpaces.last())
} else {
val content = name.replace(Regex("(?!^)([A-Z])"), " $1").split(" ")
- joinToHtml(content) {
+ joinToHtml(content, hasLastElement) {
it
}
}
@@ -22,32 +22,41 @@ fun FlowContent.buildTextBreakableAfterCapitalLetters(name: String) {
fun FlowContent.buildBreakableDotSeparatedHtml(name: String) {
val phrases = name.split(".")
phrases.forEachIndexed { i, e ->
+ val elementWithOptionalDot =
+ if (i != phrases.lastIndex) {
+ "$e."
+ } else {
+ e
+ }
+
if (e.length > 10) {
- buildBreakableText(e)
+ buildTextBreakableAfterCapitalLetters(elementWithOptionalDot, hasLastElement = i == phrases.lastIndex)
} else {
- val elementWithOptionalDot =
- if (i != phrases.lastIndex) {
- "$e."
- } else {
- e
- }
- buildBreakableHtmlElement(elementWithOptionalDot)
+ buildBreakableHtmlElement(elementWithOptionalDot, i == phrases.lastIndex)
}
}
}
-private fun FlowContent.joinToHtml(elements: List<String>, onEach: (String) -> String) {
+private fun FlowContent.joinToHtml(elements: List<String>, hasLastElement: Boolean = true, onEach: (String) -> String) {
elements.dropLast(1).forEach {
buildBreakableHtmlElement(onEach(it))
}
- span {
- buildBreakableHtmlElement(elements.last(), last = true)
+ elements.last().takeIf { it.isNotBlank() }?.let {
+ if (hasLastElement) {
+ span {
+ buildBreakableHtmlElement(it, last = true)
+ }
+ } else {
+ buildBreakableHtmlElement(it, last = false)
+ }
}
}
private fun FlowContent.buildBreakableHtmlElement(element: String, last: Boolean = false) {
- span {
- +element
+ element.takeIf { it.isNotBlank() }?.let {
+ span {
+ +it
+ }
}
if (!last) {
wbr { }
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index b6099e21..70f1c1d6 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -153,6 +153,7 @@ class StylesInstaller(private val dokkaContext: DokkaContext) : PageTransformer
object AssetsInstaller : PageTransformer {
private val imagesPages = listOf(
"images/arrow_down.svg",
+ "images/arrow_down_white.svg",
"images/docs_logo.svg",
"images/logo-icon.svg",
"images/go-to-top-icon.svg",