diff options
Diffstat (limited to 'plugins/base')
23 files changed, 196 insertions, 38 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index e8614507..5a86780b 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -1,10 +1,8 @@ package org.jetbrains.dokka.base import org.jetbrains.dokka.CoreExtensions -import org.jetbrains.dokka.base.renderers.FileWriter -import org.jetbrains.dokka.base.renderers.OutputWriter +import org.jetbrains.dokka.base.renderers.* import org.jetbrains.dokka.base.renderers.html.* -import org.jetbrains.dokka.base.renderers.html.HtmlRenderer import org.jetbrains.dokka.base.signatures.KotlinSignatureProvider import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.resolvers.external.* @@ -154,4 +152,14 @@ class DokkaBase : DokkaPlugin() { val styleAndScriptsAppender by extending { htmlPreprocessors with StyleAndScriptsAppender order { after(rootCreator) } } + + val packageListCreator by extending { + htmlPreprocessors providing { + PackageListCreator( + it, + "html", + "html" + ) + } order { after(rootCreator) } + } }
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 0ff0511a..26c75dbf 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -114,31 +114,12 @@ abstract class DefaultRenderer<T>( root.children.forEach { renderPages(it) } } - // reimplement this as preprocessor - open fun renderPackageList(root: ContentPage) = - getPackageNamesAndPlatforms(root) - .keys - .joinToString("\n") - .also { outputWriter.write("${root.name}/package-list", it, "") } - - open fun getPackageNamesAndPlatforms(root: PageNode): Map<String, List<PlatformData>> = - root.children - .map(::getPackageNamesAndPlatforms) - .fold(emptyMap<String, List<PlatformData>>()) { e, acc -> acc + e } + - if (root is PackagePageNode) { - mapOf(root.name to root.platforms()) - } else { - emptyMap() - } - override fun render(root: RootPageNode) { val newRoot = preprocessors.fold(root) { acc, t -> t(acc) } locationProvider = context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(newRoot) - root.children<ModulePageNode>().forEach { renderPackageList(it) } - renderPages(newRoot) } } diff --git a/plugins/base/src/main/kotlin/renderers/PackageListService.kt b/plugins/base/src/main/kotlin/renderers/PackageListService.kt new file mode 100644 index 00000000..d4333200 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/PackageListService.kt @@ -0,0 +1,51 @@ +package org.jetbrains.dokka.base.renderers + +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.links.parent +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + +class PackageListService(val context: DokkaContext) { + + fun formatPackageList(module: RootPageNode, format: String, linkExtension: String): String { + + val packages = mutableSetOf<String>() + val nonStandardLocations = mutableMapOf<String, String>() + + val locationProvider = + context.plugin<DokkaBase>().querySingle { locationProviderFactory }.getLocationProvider(module) + + fun visit(node: PageNode, parentDris: Set<DRI>) { + + if (node is PackagePageNode) { + packages.add(node.name) + } + + val contentPage = node.safeAs<ContentPage>() + contentPage?.dri?.forEach { + if (parentDris.isNotEmpty() && it.parent !in parentDris) { + nonStandardLocations[it.toString()] = locationProvider.resolve(node) + } + } + + node.children.forEach { visit(it, contentPage?.dri ?: setOf()) } + } + + visit(module, setOf()) + + return buildString { + appendln("\$dokka.format:${format}") + appendln("\$dokka.linkExtension:${linkExtension}") + nonStandardLocations.map { (signature, location) -> "\$dokka.location:$signature\u001f$location" } + .sorted().joinTo(this, separator = "\n", postfix = "\n") + + packages.sorted().joinTo(this, separator = "\n", postfix = "\n") + } + + } + +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt index a72c77ea..9fed74e2 100644 --- a/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt +++ b/plugins/base/src/main/kotlin/renderers/html/htmlPreprocessors.kt @@ -8,10 +8,6 @@ import org.jetbrains.dokka.base.renderers.platforms import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.transformers.pages.PageTransformer -object RootCreator : PageTransformer { - override fun invoke(input: RootPageNode) = - RendererSpecificRootPage("", listOf(input), RenderingStrategy.DoNothing) -} object SearchPageInstaller : PageTransformer { override fun invoke(input: RootPageNode) = input.modified(children = input.children + searchPage) @@ -37,19 +33,22 @@ object SearchPageInstaller : PageTransformer { object NavigationPageInstaller : PageTransformer { override fun invoke(input: RootPageNode) = input.modified( children = input.children + NavigationPage( - input.children.filterIsInstance<ContentPage>().single().let(::visit) + input.children.filterIsInstance<ContentPage>().single() + .let(NavigationPageInstaller::visit) ) ) - private fun visit(page: ContentPage): NavigationNode = NavigationNode( - page.name, - page.dri.first(), - page.platforms(), - if (page !is ClasslikePageNode) - page.children.filterIsInstance<ContentPage>().map { visit(it) } - else - emptyList() - ) + private fun visit(page: ContentPage): NavigationNode = + NavigationNode( + page.name, + page.dri.first(), + page.platforms(), + if (page !is ClasslikePageNode) + page.children.filterIsInstance<ContentPage>() + .map { visit(it) } + else + emptyList() + ) } object ResourceInstaller : PageTransformer { @@ -69,4 +68,4 @@ object StyleAndScriptsAppender : PageTransformer { ) ) } -} +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/preprocessors.kt b/plugins/base/src/main/kotlin/renderers/preprocessors.kt new file mode 100644 index 00000000..bf2a9eb4 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/preprocessors.kt @@ -0,0 +1,27 @@ +package org.jetbrains.dokka.base.renderers + +import org.jetbrains.dokka.pages.* +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.transformers.pages.PageTransformer + +object RootCreator : PageTransformer { + override fun invoke(input: RootPageNode) = + RendererSpecificRootPage("", listOf(input), RenderingStrategy.DoNothing) +} + + +class PackageListCreator(val context: DokkaContext, val format: String, val linkExtension: String) : PageTransformer { + override fun invoke(input: RootPageNode) = + input.modified(children = input.children.map { + it.takeUnless { it is ModulePageNode } + ?: it.modified(children = it.children + packageList(input)) // TODO packageList should take module as an input + }) + + + private fun packageList(pageNode: RootPageNode) = + RendererSpecificResourcePage( + "${pageNode.name}/package-list", + emptyList(), + RenderingStrategy.Write(PackageListService(context).formatPackageList(pageNode, format, linkExtension)) + ) +} diff --git a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt index 5f8d1dc4..b9809ac1 100644 --- a/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/RenderingOnlyTestBase.kt @@ -2,7 +2,7 @@ package renderers import org.jetbrains.dokka.DokkaConfigurationImpl import org.jetbrains.dokka.base.DokkaBase -import org.jetbrains.dokka.base.renderers.html.RootCreator +import org.jetbrains.dokka.base.renderers.RootCreator import org.jetbrains.dokka.base.resolvers.external.DokkaExternalLocationProviderFactory import org.jetbrains.dokka.base.resolvers.external.JavadocExternalLocationProviderFactory import org.jetbrains.dokka.base.resolvers.local.DefaultLocationProviderFactory diff --git a/plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/package-list b/plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/package-list new file mode 100644 index 00000000..caf6273a --- /dev/null +++ b/plugins/base/src/test/resources/expect/annotatedFunction/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#//root/<jvm root>/f.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/package-list b/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/package-list new file mode 100644 index 00000000..d2e42c86 --- /dev/null +++ b/plugins/base/src/test/resources/expect/annotatedFunctionWithAnnotationParameters/out/html/root/package-list @@ -0,0 +1,8 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#//root/<jvm root>/f.html +$dokka.location:/Fancy/equals/#kotlin.Any?//root/<jvm root>/-fancy/equals.html +$dokka.location:/Fancy/hashCode/#//root/<jvm root>/-fancy/hash-code.html +$dokka.location:/Fancy/toString/#//root/<jvm root>/-fancy/to-string.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/function/out/html/root/package-list b/plugins/base/src/test/resources/expect/function/out/html/root/package-list new file mode 100644 index 00000000..3a7c6807 --- /dev/null +++ b/plugins/base/src/test/resources/expect/function/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://fn/#//root/<jvm root>/fn.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/package-list b/plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/package-list new file mode 100644 index 00000000..0b48e7e0 --- /dev/null +++ b/plugins/base/src/test/resources/expect/functionWithAnnotatedParam/out/html/root/package-list @@ -0,0 +1,8 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://function/#kotlin.Function0[kotlin.Unit]//root/<jvm root>/function.html +$dokka.location:/Fancy/equals/#kotlin.Any?//root/<jvm root>/-fancy/equals.html +$dokka.location:/Fancy/hashCode/#//root/<jvm root>/-fancy/hash-code.html +$dokka.location:/Fancy/toString/#//root/<jvm root>/-fancy/to-string.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/package-list b/plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/package-list new file mode 100644 index 00000000..c8e4e8e1 --- /dev/null +++ b/plugins/base/src/test/resources/expect/functionWithDefaultParameter/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#kotlin.String//root/<jvm root>/f.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/package-list b/plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/package-list new file mode 100644 index 00000000..7de7dd3b --- /dev/null +++ b/plugins/base/src/test/resources/expect/functionWithNoinlineParam/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://function/#kotlin.Function0[kotlin.Unit]//root/<jvm root>/function.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/package-list b/plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/package-list new file mode 100644 index 00000000..caf6273a --- /dev/null +++ b/plugins/base/src/test/resources/expect/functionWithNotDocumentedAnnotation/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#//root/<jvm root>/f.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/functionWithParams/out/html/root/package-list b/plugins/base/src/test/resources/expect/functionWithParams/out/html/root/package-list new file mode 100644 index 00000000..8b5d43ee --- /dev/null +++ b/plugins/base/src/test/resources/expect/functionWithParams/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://function/#kotlin.Int//root/<jvm root>/function.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/package-list b/plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/package-list new file mode 100644 index 00000000..13dc2923 --- /dev/null +++ b/plugins/base/src/test/resources/expect/functionWithReceiver/out/html/root/package-list @@ -0,0 +1,6 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://fn/kotlin.String#//root/<jvm root>/fn.html +$dokka.location://fn/kotlin.String#kotlin.Int//root/<jvm root>/fn.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/genericFunction/out/html/root/package-list b/plugins/base/src/test/resources/expect/genericFunction/out/html/root/package-list new file mode 100644 index 00000000..30905d0f --- /dev/null +++ b/plugins/base/src/test/resources/expect/genericFunction/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://generic/#//root/<jvm root>/generic.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/package-list b/plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/package-list new file mode 100644 index 00000000..30905d0f --- /dev/null +++ b/plugins/base/src/test/resources/expect/genericFunctionWithConstraints/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://generic/#//root/<jvm root>/generic.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/inlineFunction/out/html/root/package-list b/plugins/base/src/test/resources/expect/inlineFunction/out/html/root/package-list new file mode 100644 index 00000000..60993388 --- /dev/null +++ b/plugins/base/src/test/resources/expect/inlineFunction/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#kotlin.Function0[kotlin.String]//root/<jvm root>/f.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/package-list b/plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/package-list new file mode 100644 index 00000000..60993388 --- /dev/null +++ b/plugins/base/src/test/resources/expect/inlineSuspendFunction/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#kotlin.Function0[kotlin.String]//root/<jvm root>/f.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/signatureTest/out/html/root/package-list b/plugins/base/src/test/resources/expect/signatureTest/out/html/root/package-list new file mode 100644 index 00000000..3c53d355 --- /dev/null +++ b/plugins/base/src/test/resources/expect/signatureTest/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html + +signatureTest + diff --git a/plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/package-list b/plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/package-list new file mode 100644 index 00000000..8810ec13 --- /dev/null +++ b/plugins/base/src/test/resources/expect/sinceKotlin/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://availableSince1.1/#//root/<jvm root>/available-since1.1.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/suspendFunction/out/html/root/package-list b/plugins/base/src/test/resources/expect/suspendFunction/out/html/root/package-list new file mode 100644 index 00000000..caf6273a --- /dev/null +++ b/plugins/base/src/test/resources/expect/suspendFunction/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#//root/<jvm root>/f.html +<jvm root> + diff --git a/plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/package-list b/plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/package-list new file mode 100644 index 00000000..60993388 --- /dev/null +++ b/plugins/base/src/test/resources/expect/suspendInlineFunction/out/html/root/package-list @@ -0,0 +1,5 @@ +$dokka.format:html +$dokka.linkExtension:html +$dokka.location://f/#kotlin.Function0[kotlin.String]//root/<jvm root>/f.html +<jvm root> + |