Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make current breadcrumb element not clickable and of default font color #2588

Merged
merged 2 commits into from Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Expand Up @@ -635,8 +635,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")
}