aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorFilip Zybała <fzybala@virtuslab.com>2020-05-21 09:51:54 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-05-28 16:07:46 +0200
commit0f1c461d20336444bc667713954ea2879cc0a396 (patch)
treed1adc3fa2b4178f78147bde1fa0e06875d4b1930 /plugins/base/src/main/kotlin
parent5f9299b074355e3f636da6eb6e1f9283f06ab8c7 (diff)
downloaddokka-0f1c461d20336444bc667713954ea2879cc0a396.tar.gz
dokka-0f1c461d20336444bc667713954ea2879cc0a396.tar.bz2
dokka-0f1c461d20336444bc667713954ea2879cc0a396.zip
Added filtering to HTML pages
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt6
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt39
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt26
3 files changed, 70 insertions, 1 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index a6052a9e..382b8f86 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -174,4 +174,10 @@ class DokkaBase : DokkaPlugin() {
)
} order { after(rootCreator) }
}
+
+ val sourcesetDependencyAppender by extending {
+ htmlPreprocessors providing ::SourcesetDependencyAppender order { after(rootCreator)}
+ }
+
+
} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 52f7024a..b089c71a 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -63,13 +63,35 @@ open class HtmlRenderer(
}
node.dci.kind == ContentKind.Symbol -> div("symbol $additionalClasses") { childrenCallback() }
node.dci.kind == ContentKind.BriefComment -> div("brief $additionalClasses") { childrenCallback() }
- node.dci.kind == ContentKind.Cover -> div("cover $additionalClasses") { childrenCallback() }
+ node.dci.kind == ContentKind.Cover -> div("cover $additionalClasses") {
+ filterButtons(node)
+ childrenCallback()
+ }
node.hasStyle(TextStyle.Paragraph) -> p(additionalClasses) { childrenCallback() }
node.hasStyle(TextStyle.Block) -> div(additionalClasses) { childrenCallback() }
else -> childrenCallback()
}
}
+ private fun FlowContent.filterButtons(group: ContentGroup) {
+ div(classes = "filter-section") {
+ id = "filter-section"
+ group.sourceSets.forEach {
+ button(classes = "platform-tag platform-selector") {
+ attributes["data-active"] = ""
+ attributes["data-filter"] = it.sourceSetName
+ when(it.platform.key){
+ "common" -> classes = classes + "common-like"
+ "native" -> classes = classes + "native-like"
+ "jvm" -> classes = classes + "jvm-like"
+ "js" -> classes = classes + "js-like"
+ }
+ text(it.sourceSetName)
+ }
+ }
+ }
+ }
+
override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) =
buildPlatformDependent(content.sourceSets.map { it to setOf(content.inner) }.toMap(), pageContext, content.extra)
@@ -108,6 +130,8 @@ open class HtmlRenderer(
attributes["data-toggle-list"] = "data-toggle-list"
contents.forEachIndexed { index, pair ->
button(classes = "platform-bookmark") {
+ attributes["data-filterable-current"] = pair.first.sourceSetName
+ attributes["data-filterable-set"] = pair.first.sourceSetName
if (index == 0) attributes["data-active"] = ""
attributes["data-toggle"] = pair.first.sourceSetName
when(
@@ -160,8 +184,15 @@ open class HtmlRenderer(
consumer.onTagContentUnsafe {
+createHTML().div("divergent-group"){
+ attributes["data-filterable-current"] = groupedDivergent.keys.joinToString(" ") {
+ it.sourceSetName
+ }
+ attributes["data-filterable-set"] = groupedDivergent.keys.joinToString(" ") {
+ it.sourceSetName
+ }
consumer.onTagContentUnsafe { +it.key.first }
div("main-subrow") {
+
if (node.implicitlySourceSetHinted) {
buildPlatformDependent(
groupedDivergent.map { (sourceSet, elements) ->
@@ -242,6 +273,12 @@ open class HtmlRenderer(
?.let {
withAnchor(node.dci.dri.first().toString()) {
div(classes = "table-row") {
+ attributes["data-filterable-current"] = node.sourceSets.joinToString(" ") {
+ it.sourceSetName
+ }
+ attributes["data-filterable-set"] = node.sourceSets.joinToString(" ") {
+ it.sourceSetName
+ }
it.filterIsInstance<ContentLink>().takeIf { it.isNotEmpty() }?.let {
div("main-subrow " + node.style.joinToString(" ")) {
it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
index 710407c5..45ef1457 100644
--- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt
@@ -6,6 +6,7 @@ import kotlinx.html.table
import kotlinx.html.tbody
import org.jetbrains.dokka.base.renderers.platforms
import org.jetbrains.dokka.pages.*
+import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.transformers.pages.PageTransformer
@@ -66,8 +67,33 @@ object StyleAndScriptsAppender : PageTransformer {
"styles/style.css",
"scripts/navigationLoader.js",
"scripts/platformContentHandler.js",
+ "scripts/sourceset_dependencies.js",
"styles/jetbrains-mono.css"
)
)
}
+}
+
+class SourcesetDependencyAppender(val context: DokkaContext) : PageTransformer{
+ override fun invoke(input: RootPageNode): RootPageNode {
+ val dependenciesMap = context.configuration.passesConfigurations.map {
+ it.sourceSetName to it.dependentSourceSets
+ }.toMap()
+ fun createDependenciesJson() : String = "sourceset_dependencies = '{${
+ dependenciesMap.entries.joinToString(", ") {
+ "\"${it.key}\": [${it.value.joinToString(","){
+ "\"$it\""
+ }}]"
+ }
+ }}'"
+ val deps = RendererSpecificResourcePage(
+ name = "scripts/sourceset_dependencies.js",
+ children = emptyList(),
+ strategy = RenderingStrategy.Write(createDependenciesJson())
+ )
+
+ return input.modified(
+ children = input.children + deps
+ )
+ }
} \ No newline at end of file