aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main
diff options
context:
space:
mode:
authorFilip Zybała <fzybala@virtuslab.com>2020-07-08 10:11:53 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-07-13 15:13:01 +0200
commit46bfb60f356a861097149f64bf414e732807c522 (patch)
tree05ddd63773f481e58c717ffe59d0c553722b9957 /plugins/base/src/main
parent6377d964819f937bd4a7633488d69edc327542d8 (diff)
downloaddokka-46bfb60f356a861097149f64bf414e732807c522.tar.gz
dokka-46bfb60f356a861097149f64bf414e732807c522.tar.bz2
dokka-46bfb60f356a861097149f64bf414e732807c522.zip
Implemented extension point for tab sorting strategy
Diffstat (limited to 'plugins/base/src/main')
-rw-r--r--plugins/base/src/main/kotlin/DokkaBase.kt6
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt29
-rw-r--r--plugins/base/src/main/kotlin/renderers/TabSortingStrategy.kt7
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt14
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt2
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt8
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt4
7 files changed, 61 insertions, 9 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt
index bcd2c93e..6586f2dc 100644
--- a/plugins/base/src/main/kotlin/DokkaBase.kt
+++ b/plugins/base/src/main/kotlin/DokkaBase.kt
@@ -41,6 +41,7 @@ class DokkaBase : DokkaPlugin() {
val outputWriter by extensionPoint<OutputWriter>()
val htmlPreprocessors by extensionPoint<PageTransformer>()
val kotlinAnalysis by extensionPoint<KotlinAnalysis>()
+ val tabSortingStrategy by extensionPoint<TabSortingStrategy>()
val descriptorToDocumentableTranslator by extending {
@@ -134,10 +135,15 @@ class DokkaBase : DokkaPlugin() {
}
}
+ val defaultTabSortingStrategy by extending {
+ tabSortingStrategy with DefaultTabSortingStrategy()
+ }
+
val htmlRenderer by extending {
CoreExtensions.renderer providing ::HtmlRenderer
}
+
val defaultKotlinAnalysis by extending {
kotlinAnalysis providing { ctx -> KotlinAnalysis(ctx) }
}
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt b/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt
new file mode 100644
index 00000000..b40f9afe
--- /dev/null
+++ b/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt
@@ -0,0 +1,29 @@
+package org.jetbrains.dokka.base.renderers
+
+import org.jetbrains.dokka.pages.ContentKind
+import org.jetbrains.dokka.pages.ContentNode
+import org.jetbrains.dokka.pages.Kind
+import org.jetbrains.dokka.utilities.DokkaLogger
+
+class DefaultTabSortingStrategy : TabSortingStrategy {
+ override fun <T: ContentNode> sort(tabs: Collection<T>): List<T> {
+ val tabMap: Map<Kind, MutableList<T>> = mapOf(
+ ContentKind.Classlikes to mutableListOf(),
+ ContentKind.Constructors to mutableListOf(),
+ ContentKind.Functions to mutableListOf(),
+ ContentKind.Properties to mutableListOf(),
+ ContentKind.Extensions to mutableListOf(),
+ ContentKind.Parameters to mutableListOf(),
+ ContentKind.Inheritors to mutableListOf(),
+ ContentKind.Source to mutableListOf(),
+ ContentKind.Sample to mutableListOf(),
+ ContentKind.Comment to mutableListOf()
+ )
+ val unrecognized: MutableList<T> = mutableListOf()
+ tabs.forEach {
+ tabMap[it.dci.kind]?.add(it) ?: unrecognized.add(it)
+ }
+ return tabMap.values.flatten() + unrecognized
+ }
+
+} \ No newline at end of file
diff --git a/plugins/base/src/main/kotlin/renderers/TabSortingStrategy.kt b/plugins/base/src/main/kotlin/renderers/TabSortingStrategy.kt
new file mode 100644
index 00000000..dcf49ca9
--- /dev/null
+++ b/plugins/base/src/main/kotlin/renderers/TabSortingStrategy.kt
@@ -0,0 +1,7 @@
+package org.jetbrains.dokka.base.renderers
+
+import org.jetbrains.dokka.pages.ContentNode
+
+interface TabSortingStrategy {
+ fun <T: ContentNode> sort(tabs: Collection<T>) : List<T>
+} \ 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 595dc8d2..50af53f0 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -9,12 +9,14 @@ import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import org.jetbrains.dokka.Platform
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.renderers.DefaultRenderer
+import org.jetbrains.dokka.base.renderers.TabSortingStrategy
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.query
+import org.jetbrains.dokka.plugability.querySingle
import java.io.File
import java.net.URI
@@ -26,11 +28,19 @@ open class HtmlRenderer(
sourceSet to context.configuration.sourceSets.filter { sourceSet.dependentSourceSets.contains(it.sourceSetID) }
}.toMap()
-
private val pageList = mutableMapOf<String, Pair<String, String>>()
override val preprocessors = context.plugin<DokkaBase>().query { htmlPreprocessors }
+ private val tabSortingStrategy = context.plugin<DokkaBase>().querySingle { tabSortingStrategy }
+
+ private fun <T: ContentNode> sortTabs(strategy: TabSortingStrategy, tabs: Collection<T>) : List<T> {
+ val sorted = strategy.sort(tabs)
+ if(sorted.size != tabs.size)
+ context.logger.warn("Tab sorting strategy has changed number of tabs from ${tabs.size} to ${sorted.size}")
+ return sorted;
+ }
+
override fun FlowContent.wrapGroup(
node: ContentGroup,
pageContext: ContentPage,
@@ -44,7 +54,7 @@ open class HtmlRenderer(
val firstLevel = node.children.filterIsInstance<ContentHeader>().flatMap { it.children }
.filterIsInstance<ContentText>()
- val renderable = firstLevel.union(secondLevel)
+ val renderable = firstLevel.union(secondLevel).let { sortTabs(tabSortingStrategy, it) }
div(classes = "tabs-section") {
attributes["tabs-section"] = "tabs-section"
diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
index 9a11c126..f0e62f11 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
@@ -57,7 +57,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent
node.dri.first(),
node.documentable!!.sourceSets.toSet()
) {
- header(2, "Sources")
+ header(2, "Sources", kind = ContentKind.Source)
+ContentTable(
emptyList(),
sources.map {
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index 40283d82..f8dbde60 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -315,7 +315,7 @@ open class DefaultPageCreator(
fun DocumentableContentBuilder.contentForParams() {
if (tags.isNotEmptyForTag<Param>()) {
- header(2, "Parameters")
+ header(2, "Parameters", kind = ContentKind.Parameters)
group(
extra = mainExtra + SimpleAttr.header("Parameters"),
styles = setOf(ContentStyle.WithExtraAttributes)
@@ -356,7 +356,7 @@ open class DefaultPageCreator(
fun DocumentableContentBuilder.contentForSeeAlso() {
if (tags.isNotEmptyForTag<See>()) {
- header(2, "See also")
+ header(2, "See also", kind = ContentKind.Comment)
group(
extra = mainExtra + SimpleAttr.header("See also"),
styles = setOf(ContentStyle.WithExtraAttributes)
@@ -393,7 +393,7 @@ open class DefaultPageCreator(
fun DocumentableContentBuilder.contentForSamples() {
val samples = tags.withTypeNamed<Sample>()
if (samples.isNotEmpty()) {
- header(2, "Samples")
+ header(2, "Samples", kind = ContentKind.Sample)
group(
extra = mainExtra + SimpleAttr.header("Samples"),
styles = emptySet()
@@ -476,7 +476,7 @@ open class DefaultPageCreator(
extra: PropertyContainer<ContentNode> = mainExtra
) {
if (collection.any()) {
- header(2, name)
+ header(2, name, kind = kind)
table(kind, extra = extra, styles = emptySet()) {
collection
.groupBy { it.name }
diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
index 94aa2c5a..b7927076 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt
@@ -114,7 +114,7 @@ open class PageContentBuilder(
styles,
extra + SimpleAttr("anchor", text.replace("\\s".toRegex(), "").toLowerCase())
) {
- text(text)
+ text(text, kind = kind)
block()
}
)
@@ -172,7 +172,7 @@ open class PageContentBuilder(
operation: DocumentableContentBuilder.(T) -> Unit
) {
if (renderWhenEmpty || elements.any()) {
- header(level, name) { }
+ header(level, name, kind = kind) { }
contents += ContentTable(
headers ?: defaultHeaders,
elements