aboutsummaryrefslogtreecommitdiff
path: root/plugins/base
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base')
-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
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt2
8 files changed, 63 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
diff --git a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
index 397a9c45..d533988d 100644
--- a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
@@ -2,6 +2,7 @@ package renderers.html
import org.jetbrains.dokka.DokkaConfigurationImpl
import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.base.renderers.DefaultTabSortingStrategy
import org.jetbrains.dokka.base.renderers.RootCreator
import org.jetbrains.dokka.base.resolvers.external.DokkaExternalLocationProviderFactory
import org.jetbrains.dokka.base.resolvers.external.JavadocExternalLocationProviderFactory
@@ -23,6 +24,7 @@ abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase<Element>() {
DokkaBase().htmlPreprocessors to { _ -> RootCreator },
DokkaBase().externalLocationProviderFactory to { ::JavadocExternalLocationProviderFactory },
DokkaBase().externalLocationProviderFactory to { ::DokkaExternalLocationProviderFactory },
+ DokkaBase().tabSortingStrategy to { DefaultTabSortingStrategy() },
testConfiguration = DokkaConfigurationImpl(
"", null, false, emptyList(), emptyList(), emptyMap(), emptyList(), false
)