From 77c8777b7f66bddd374d68decd507547d356d602 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Sun, 31 May 2020 21:02:46 +0200 Subject: Improve CSS, pages navigation tree and create anchors on page --- .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 258 +++++++++++----- .../kotlin/renderers/html/htmlPreprocessors.kt | 20 +- .../kotlin/signatures/KotlinSignatureProvider.kt | 2 +- .../documentables/DefaultPageCreator.kt | 67 ++--- .../documentables/PageContentBuilder.kt | 14 +- .../src/main/resources/dokka/scripts/clipboard.js | 52 ++++ .../resources/dokka/scripts/navigationLoader.js | 11 + .../base/src/main/resources/dokka/styles/style.css | 330 ++++++++++++++++++--- 8 files changed, 607 insertions(+), 147 deletions(-) create mode 100644 plugins/base/src/main/resources/dokka/scripts/clipboard.js (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 7ebcf00e..67fa2d91 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -22,7 +22,7 @@ open class HtmlRenderer( private val sourceSetDependencyMap = with(context.sourceSetCache) { allSourceSets.map { sourceSet -> - sourceSet to allSourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetName ) } + sourceSet to allSourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetName) } }.toMap() } @@ -38,22 +38,24 @@ open class HtmlRenderer( val additionalClasses = node.style.joinToString(" ") { it.toString().toLowerCase() } return when { node.hasStyle(ContentStyle.TabbedContent) -> div(additionalClasses) { - val secondLevel = node.children.filterIsInstance().flatMap { it.children }.filterIsInstance().flatMap { it.children }.filterIsInstance() - val firstLevel = node.children.filterIsInstance().flatMap { it.children }.filterIsInstance() + val secondLevel = node.children.filterIsInstance().flatMap { it.children } + .filterIsInstance().flatMap { it.children }.filterIsInstance() + val firstLevel = node.children.filterIsInstance().flatMap { it.children } + .filterIsInstance() val renderable = firstLevel.union(secondLevel) - div(classes = "tabs-section"){ + div(classes = "tabs-section") { attributes["tabs-section"] = "tabs-section" renderable.forEachIndexed { index, node -> - button(classes = "section-tab"){ - if(index == 0 ) attributes["data-active"] = "" + button(classes = "section-tab") { + if (index == 0) attributes["data-active"] = "" attributes["data-togglable"] = node.text text(node.text) } } } - div(classes = "tabs-section-body"){ + div(classes = "tabs-section-body") { childrenCallback() } } @@ -61,7 +63,10 @@ open class HtmlRenderer( node.extra.extraHtmlAttributes().forEach { attributes[it.extraKey] = it.extraValue } childrenCallback() } - node.dci.kind == ContentKind.Symbol -> div("symbol $additionalClasses") { childrenCallback() } + node.dci.kind in setOf(ContentKind.Symbol, ContentKind.Sample) -> div("symbol $additionalClasses") { + childrenCallback() + if (node.hasStyle(TextStyle.Monospace)) copyButton() + } node.dci.kind == ContentKind.BriefComment -> div("brief $additionalClasses") { childrenCallback() } node.dci.kind == ContentKind.Cover -> div("cover $additionalClasses") { filterButtons(node) @@ -80,7 +85,7 @@ open class HtmlRenderer( button(classes = "platform-tag platform-selector") { attributes["data-active"] = "" attributes["data-filter"] = it.sourceSetName - when(it.platform.key){ + when (it.platform.key) { "common" -> classes = classes + "common-like" "native" -> classes = classes + "native-like" "jvm" -> classes = classes + "jvm-like" @@ -92,40 +97,57 @@ open class HtmlRenderer( } } + private fun FlowContent.copyButton() = span(classes = "top-right-position") { + span("copy-icon") { + unsafe { + raw( + """ + + """.trimIndent() + ) + } + } + copiedPopup("Content copied to clipboard", "popup-to-left") + } + + private fun FlowContent.copiedPopup(notificationContent: String, additionalClasses: String = "") = + div("copy-popup-wrapper $additionalClasses") { + unsafe { + raw( + """ + + + + """.trimIndent() + ) + } + span { + text(notificationContent) + } + } + override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) = - buildPlatformDependent(content.sourceSets.map { it to setOf(content.inner) }.toMap(), pageContext, content.extra) + buildPlatformDependent( + content.sourceSets.map { it to setOf(content.inner) }.toMap(), + pageContext, + content.extra, + content.style + ) private fun FlowContent.buildPlatformDependent( nodes: Map>, pageContext: ContentPage, - extra: PropertyContainer = PropertyContainer.empty() + extra: PropertyContainer = PropertyContainer.empty(), + styles: Set