Skip to content

Commit

Permalink
Make current breadcrumb element not clickable and of default font col…
Browse files Browse the repository at this point in the history
…or (#2588)
  • Loading branch information
IgnatBeresnev committed Jul 27, 2022
1 parent f4d2bf4 commit 26dde5b
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 2 deletions.
14 changes: 12 additions & 2 deletions plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Expand Up @@ -634,8 +634,18 @@ open class HtmlRenderer(
}

private fun FlowContent.buildNavigationElement(node: PageNode, page: PageNode) =
if (node.isNavigable) buildLink(node, page)
else text(node.name)
if (node.isNavigable) {
val isCurrentPage = (node == page)
if (isCurrentPage) {
span(classes = "current") {
text(node.name)
}
} else {
buildLink(node, page)
}
} else {
text(node.name)
}

private fun FlowContent.buildLink(to: PageNode, from: PageNode) =
locationProvider.resolve(to, from)?.let { path ->
Expand Down
4 changes: 4 additions & 0 deletions plugins/base/src/main/resources/dokka/styles/style.css
Expand Up @@ -150,6 +150,10 @@ html ::-webkit-scrollbar-thumb {
margin: auto 2px;
}

.breadcrumbs .current {
color: var(--default-font-color);
}

.tabs-section > .section-tab:first-child,
.platform-hinted > .platform-bookmarks-row > .platform-bookmark:first-child {
margin-left: 0;
Expand Down
84 changes: 84 additions & 0 deletions plugins/base/src/test/kotlin/renderers/html/BreadcrumbsTest.kt
@@ -0,0 +1,84 @@
package renderers.html

import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jsoup.nodes.Element
import org.junit.jupiter.api.Test
import signatures.renderedContent
import utils.*

class BreadcrumbsTest : BaseAbstractTest() {

private val configuration = dokkaConfiguration {
sourceSets {
sourceSet {
sourceRoots = listOf("src/")
}
}
}

@Test
fun `should add breadcrumbs with current element`() {
val writerPlugin = TestOutputWriterPlugin()
testInline(
"""
|/src/main/kotlin/basic/TestClass.kt
|package testpackage
|
|class TestClass {
| fun foo() {}
|}
""".trimMargin(),
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/testpackage/-test-class/foo.html").selectBreadcrumbs().match(
link("root"),
delimiter(),
link("testpackage"),
delimiter(),
link("TestClass"),
delimiter(),
current("foo"),
ignoreSpanWithTokenStyle = true
)
}
}
}

@Test
fun `should mark only one element as current even if more elements have the same name`() {
val writerPlugin = TestOutputWriterPlugin()
testInline(
"""
|/src/main/kotlin/basic/TestClass.kt
|package testpackage
|
|class testname {
| val testname: String = ""
|}
""".trimMargin(),
configuration,
pluginOverrides = listOf(writerPlugin)
) {
renderingStage = { _, _ ->
writerPlugin.writer.renderedContent("root/testpackage/testname/testname.html").selectBreadcrumbs().match(
link("root"),
delimiter(),
link("testpackage"),
delimiter(),
link("testname"),
delimiter(),
current("testname"),
ignoreSpanWithTokenStyle = true
)
}
}
}

private fun Element.selectBreadcrumbs() = this.select("div.breadcrumbs").single()

private fun link(text: String): Tag = A(text)
private fun delimiter(): Tag = Span().withClasses("delimiter")
private fun current(text: String): Tag = Span(text).withClasses("current")
}

0 comments on commit 26dde5b

Please sign in to comment.