diff options
author | vmishenev <vad-mishenev@yandex.ru> | 2021-09-01 00:03:13 +0300 |
---|---|---|
committer | vmishenev <vad-mishenev@yandex.ru> | 2021-09-20 19:01:44 +0300 |
commit | fc5496fb8bb888c3a50717260dc05d8fe2d54306 (patch) | |
tree | 2b61c01babe696065c4b8bafad61cce7479561ad /plugins/base/src/main/kotlin | |
parent | 8efe04e127e3bf0aef395b31f3f3d9f49a0afe26 (diff) | |
download | dokka-fc5496fb8bb888c3a50717260dc05d8fe2d54306.tar.gz dokka-fc5496fb8bb888c3a50717260dc05d8fe2d54306.tar.bz2 dokka-fc5496fb8bb888c3a50717260dc05d8fe2d54306.zip |
Improve versioning plugin (#2104)
- support for single module projects
- version navigator is on all pages
- dropdown arrow for version navigator
Diffstat (limited to 'plugins/base/src/main/kotlin')
6 files changed, 43 insertions, 8 deletions
diff --git a/plugins/base/src/main/kotlin/DokkaBase.kt b/plugins/base/src/main/kotlin/DokkaBase.kt index 7e88d08f..fc138461 100644 --- a/plugins/base/src/main/kotlin/DokkaBase.kt +++ b/plugins/base/src/main/kotlin/DokkaBase.kt @@ -28,6 +28,7 @@ import org.jetbrains.dokka.base.translators.descriptors.DefaultDescriptorToDocum import org.jetbrains.dokka.base.translators.documentables.DefaultDocumentableToPageTranslator import org.jetbrains.dokka.base.translators.psi.DefaultPsiToDocumentableTranslator import org.jetbrains.dokka.base.generation.SingleModuleGeneration +import org.jetbrains.dokka.base.renderers.html.command.consumers.ReplaceVersionsConsumer import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer import org.jetbrains.dokka.transformers.pages.PageTransformer @@ -242,7 +243,9 @@ class DokkaBase : DokkaPlugin() { val resolveLinkConsumer by extending { immediateHtmlCommandConsumer with ResolveLinkConsumer } - + val replaceVersionConsumer by extending { + immediateHtmlCommandConsumer providing ::ReplaceVersionsConsumer + } val pathToRootConsumer by extending { immediateHtmlCommandConsumer with PathToRootConsumer } diff --git a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt index e0deef17..5cdeeb40 100644 --- a/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt +++ b/plugins/base/src/main/kotlin/generation/SingleModuleGeneration.kt @@ -46,6 +46,9 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { report("Rendering") render(transformedPages) + report("Running post-actions") + runPostActions() + reportAfterRendering() } @@ -76,6 +79,10 @@ class SingleModuleGeneration(private val context: DokkaContext) : Generation { context.single(CoreExtensions.renderer).render(transformedPages) } + fun runPostActions() { + context[CoreExtensions.postActions].forEach { it() } + } + fun validityCheck(context: DokkaContext) { val (preGenerationCheckResult, checkMessages) = context[CoreExtensions.preGenerationCheck].fold( Pair(true, emptyList<String>()) diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 5eaf9fc7..2a21337f 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -12,6 +12,7 @@ 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.dokka.renderers.PostAction import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.transformers.pages.PageTransformer diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 951f0973..9a88de86 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -13,10 +13,7 @@ import org.jetbrains.dokka.base.renderers.isImage import org.jetbrains.dokka.base.renderers.pageId import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.base.resolvers.local.DokkaBaseLocationProvider -import org.jetbrains.dokka.base.templating.InsertTemplateExtra -import org.jetbrains.dokka.base.templating.PathToRootSubstitutionCommand -import org.jetbrains.dokka.base.templating.ProjectNameSubstitutionCommand -import org.jetbrains.dokka.base.templating.ResolveLinkCommand +import org.jetbrains.dokka.base.templating.* import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.properties.PropertyContainer @@ -757,6 +754,7 @@ open class HtmlRenderer( get() = URI(this).isAbsolute open fun buildHtml(page: PageNode, resources: List<String>, content: FlowContent.() -> Unit): String { + val path = locationProvider.resolve(page) val pathToRoot = locationProvider.pathToRoot(page) return createHTML().prepareForTemplates().html { head { @@ -821,9 +819,7 @@ open class HtmlRenderer( div("library-name") { clickableLogo(page, pathToRoot) } - context.configuration.moduleVersion?.let { moduleVersion -> - div { text(moduleVersion) } - } + div { templateCommand(ReplaceVersionsCommand(path.orEmpty())) } div("pull-right d-flex") { filterButtons(page) button { diff --git a/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt new file mode 100644 index 00000000..ea8cde0f --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt @@ -0,0 +1,25 @@ +package org.jetbrains.dokka.base.renderers.html.command.consumers + +import org.jetbrains.dokka.base.renderers.html.TemplateBlock +import org.jetbrains.dokka.base.templating.Command +import org.jetbrains.dokka.base.templating.ImmediateHtmlCommandConsumer +import org.jetbrains.dokka.base.templating.ReplaceVersionsCommand +import org.jetbrains.dokka.plugability.DokkaContext + +class ReplaceVersionsConsumer(private val context: DokkaContext) : ImmediateHtmlCommandConsumer { + override fun canProcess(command: Command) = command is ReplaceVersionsCommand + + override fun <R> processCommand( + command: Command, + block: TemplateBlock, + tagConsumer: ImmediateResolutionTagConsumer<R> + ) { + command as ReplaceVersionsCommand + tagConsumer.onTagContentUnsafe { +context.configuration.moduleVersion.orEmpty() } + } + + override fun <R> processCommandAndFinalize(command: Command, block: TemplateBlock, tagConsumer: ImmediateResolutionTagConsumer<R>): R { + PathToRootConsumer.processCommand(command, block, tagConsumer) + return tagConsumer.finalize() + } +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt b/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt new file mode 100644 index 00000000..89f267b3 --- /dev/null +++ b/plugins/base/src/main/kotlin/templating/ReplaceVersionsCommand.kt @@ -0,0 +1,3 @@ +package org.jetbrains.dokka.base.templating + +data class ReplaceVersionsCommand(val location: String = ""): Command
\ No newline at end of file |