aboutsummaryrefslogtreecommitdiff
path: root/dokka-subprojects/plugin-versioning/src/main/kotlin/org/jetbrains/dokka/versioning/VersioningPlugin.kt
blob: 2e1fde8dcadcb71d2534f63dc0440aa5b8402c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

package org.jetbrains.dokka.versioning

import org.jetbrains.dokka.CoreExtensions.postActions
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.templating.ImmediateHtmlCommandConsumer
import org.jetbrains.dokka.plugability.*
import org.jetbrains.dokka.renderers.PostAction
import org.jetbrains.dokka.templates.CommandHandler
import org.jetbrains.dokka.templates.TemplatingPlugin
import org.jetbrains.dokka.transformers.pages.PageTransformer

public class VersioningPlugin : DokkaPlugin() {

    public val versioningStorage: ExtensionPoint<VersioningStorage> by extensionPoint()
    public val versionsNavigationCreator: ExtensionPoint<VersionsNavigationCreator> by extensionPoint()
    public val versionsOrdering: ExtensionPoint<VersionsOrdering> by extensionPoint()

    private val dokkaBase by lazy { plugin<DokkaBase>() }
    private val templatingPlugin by lazy { plugin<TemplatingPlugin>() }

    public val defaultVersioningStorage: Extension<VersioningStorage, *, *> by extending {
        versioningStorage providing ::DefaultVersioningStorage
    }

    public val defaultVersioningNavigationCreator: Extension<VersionsNavigationCreator, *, *> by extending {
        versionsNavigationCreator providing ::HtmlVersionsNavigationCreator
    }

    public val replaceVersionCommandHandler: Extension<CommandHandler, *, *> by extending {
        templatingPlugin.directiveBasedCommandHandlers providing ::ReplaceVersionCommandHandler override templatingPlugin.replaceVersionCommandHandler
    }

    public val resolveLinkConsumer: Extension<ImmediateHtmlCommandConsumer, *, *> by extending {
        dokkaBase.immediateHtmlCommandConsumer providing ::ReplaceVersionCommandConsumer override dokkaBase.replaceVersionConsumer
    }

    public val cssStyleInstaller: Extension<PageTransformer, *, *> by extending {
        dokkaBase.htmlPreprocessors providing ::MultiModuleStylesInstaller order {
            after(dokkaBase.assetsInstaller)
            before(dokkaBase.customResourceInstaller)
        }
    }

    public val notFoundPageInstaller: Extension<PageTransformer, *, *> by extending {
        dokkaBase.htmlPreprocessors providing ::NotFoundPageInstaller order {
            after(dokkaBase.assetsInstaller)
            before(dokkaBase.customResourceInstaller)
        } applyIf { !delayTemplateSubstitution }
    }

    public val versionsDefaultOrdering: Extension<VersionsOrdering, *, *> by extending {
        versionsOrdering providing { ctx ->
            configuration<VersioningPlugin, VersioningConfiguration>(ctx)?.versionsOrdering?.let {
                ByConfigurationVersionOrdering(ctx)
            } ?: SemVerVersionOrdering()
        }
    }

    public val previousDocumentationCopyPostAction: Extension<PostAction, *, *> by extending {
        postActions providing ::DefaultPreviousDocumentationCopyPostAction applyIf { !delayTemplateSubstitution }
    }

    @OptIn(DokkaPluginApiPreview::class)
    override fun pluginApiPreviewAcknowledgement(): PluginApiPreviewAcknowledgement =
        PluginApiPreviewAcknowledgement
}