Skip to content

Commit

Permalink
Improve versioning plugin
Browse files Browse the repository at this point in the history
- support for single module projects
- version navigator is on all pages
- dropdown arrow for version navigator
  • Loading branch information
vmishenev committed Aug 31, 2021
1 parent 721e024 commit 48bafab
Show file tree
Hide file tree
Showing 21 changed files with 297 additions and 119 deletions.
3 changes: 0 additions & 3 deletions docs/src/doc/docs/user_guide/versioning/versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ Above configuration should be placed under the `pluginsConfiguration` block spec
Configuration object is named `org.jetbrains.dokka.versioning.VersioningConfiguration`.


!!! note
In the current release versioning is available only for the multimodule. Supporting single module is scheduled for next release

### Directory structure required

If you pass previous versions using `olderVersionsDir`, a particular directory structure is required:
Expand Down
1 change: 0 additions & 1 deletion plugins/all-modules-page/api/all-modules-page.api
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public final class org/jetbrains/dokka/allModulesPage/AllModulesPageGeneration :
public final fun finishProcessingSubmodules ()V
public fun generate (Lorg/jetbrains/dokka/Timer;)V
public fun getGenerationName ()Ljava/lang/String;
public final fun handlePreviousDocs ()V
public final fun processMultiModule (Lorg/jetbrains/dokka/pages/RootPageNode;)V
public final fun processSubmodules ()Lorg/jetbrains/dokka/allModulesPage/AllModulesPageGeneration$DefaultAllModulesContext;
public final fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.templates.TemplatingPlugin
import org.jetbrains.dokka.templates.TemplatingResult
import org.jetbrains.dokka.transformers.pages.CreationContext
import org.jetbrains.dokka.versioning.VersioningPlugin

class AllModulesPageGeneration(private val context: DokkaContext) : Generation {

private val allModulesPagePlugin by lazy { context.plugin<AllModulesPagePlugin>() }
private val templatingPlugin by lazy { context.plugin<TemplatingPlugin>() }
private val versioningPlugin by lazy { context.plugin<VersioningPlugin>() }

override fun Timer.generate() {
report("Processing submodules")
Expand All @@ -26,9 +24,6 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation {
report("Creating all modules page")
val pages = createAllModulesPage(generationContext)

report("Copy previous documentation")
handlePreviousDocs()

report("Transforming pages")
val transformedPages = transformAllModulesPage(pages)

Expand All @@ -44,8 +39,6 @@ class AllModulesPageGeneration(private val context: DokkaContext) : Generation {

override val generationName = "index page for project"

fun handlePreviousDocs() = versioningPlugin.querySingle { versioningHandler }.invoke()

fun createAllModulesPage(allModulesContext: DefaultAllModulesContext) =
allModulesPagePlugin.querySingle { allModulesPageCreator }.invoke(allModulesContext)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class MultimoduleLocationProvider(private val root: RootPageNode, dokkaCont
?.let(externalModuleLinkResolver::resolveLinkToModuleIndex)

override fun resolve(node: PageNode, context: PageNode?, skipExtension: Boolean) =
if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index"
if (node is ContentPage && MultimodulePageCreator.MULTIMODULE_ROOT_DRI in node.dri) pathToRoot(root) + "index${if(skipExtension)"" else ".html"}"
else defaultLocationProvider.resolve(node, context, skipExtension)

override fun pathToRoot(from: PageNode): String = defaultLocationProvider.pathToRoot(from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ import org.jetbrains.dokka.model.doc.P
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.configuration
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageCreator
import org.jetbrains.dokka.utilities.DokkaLogger
import org.jetbrains.dokka.versioning.ReplaceVersionsCommand
import org.jetbrains.dokka.versioning.VersioningConfiguration
import org.jetbrains.dokka.versioning.VersioningPlugin
import java.io.File

class MultimodulePageCreator(
Expand All @@ -46,11 +42,6 @@ class MultimodulePageCreator(
kind = ContentKind.Cover,
sourceSets = sourceSetData
) {
/* The line below checks if there is a provided configuration for versioning.
If not, we are skipping the template for inserting versions navigation */
configuration<VersioningPlugin, VersioningConfiguration>(context)?.let {
group(extra = PropertyContainer.withAll(InsertTemplateExtra(ReplaceVersionsCommand))) { }
}
getMultiModuleDocumentation(context.configuration.includes).takeIf { it.isNotEmpty() }?.let { nodes ->
group(kind = ContentKind.Cover) {
nodes.forEach { node ->
Expand Down
7 changes: 7 additions & 0 deletions plugins/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class org/jetbrains/dokka/base/DokkaBase : org/jetbrains/dokka/plug
public final fun getPageMerger ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getPageMergerStrategy ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getPathToRootConsumer ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getPostActions ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getPreMergeDocumentableTransformer ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getPsiToDocumentableTranslator ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getResolveLinkConsumer ()Lorg/jetbrains/dokka/plugability/Extension;
Expand Down Expand Up @@ -243,6 +244,7 @@ public abstract class org/jetbrains/dokka/base/renderers/DefaultRenderer : org/j
protected final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
protected final fun getLocationProvider ()Lorg/jetbrains/dokka/base/resolvers/local/LocationProvider;
protected final fun getOutputWriter ()Lorg/jetbrains/dokka/base/renderers/OutputWriter;
protected fun getPostActions ()Ljava/lang/Iterable;
protected fun getPreprocessors ()Ljava/lang/Iterable;
protected final fun groupDivergentInstances (Lorg/jetbrains/dokka/pages/ContentDivergentGroup;Lorg/jetbrains/dokka/pages/ContentPage;Lkotlin/jvm/functions/Function3;Lkotlin/jvm/functions/Function3;)Ljava/util/Map;
public fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V
Expand Down Expand Up @@ -297,6 +299,9 @@ public final class org/jetbrains/dokka/base/renderers/PackageListService$Compani
public final fun renderPackageList (Ljava/util/Map;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
}

public abstract interface class org/jetbrains/dokka/base/renderers/PostAction : kotlin/jvm/functions/Function0 {
}

public final class org/jetbrains/dokka/base/renderers/RootCreator : org/jetbrains/dokka/transformers/pages/PageTransformer {
public static final field INSTANCE Lorg/jetbrains/dokka/base/renderers/RootCreator;
public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RendererSpecificRootPage;
Expand Down Expand Up @@ -365,6 +370,8 @@ public class org/jetbrains/dokka/base/renderers/html/HtmlRenderer : org/jetbrain
public synthetic fun buildText (Ljava/lang/Object;Lorg/jetbrains/dokka/pages/ContentText;)V
public fun buildText (Lkotlinx/html/FlowContent;Lorg/jetbrains/dokka/pages/ContentText;)V
public fun clickableLogo (Lkotlinx/html/FlowContent;Lorg/jetbrains/dokka/pages/PageNode;Ljava/lang/String;)V
public synthetic fun getPostActions ()Ljava/lang/Iterable;
protected fun getPostActions ()Ljava/util/List;
public synthetic fun getPreprocessors ()Ljava/lang/Iterable;
protected fun getPreprocessors ()Ljava/util/List;
public fun render (Lorg/jetbrains/dokka/pages/RootPageNode;)V
Expand Down
1 change: 1 addition & 0 deletions plugins/base/src/main/kotlin/DokkaBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DokkaBase : DokkaPlugin() {
val externalLocationProviderFactory by extensionPoint<ExternalLocationProviderFactory>()
val outputWriter by extensionPoint<OutputWriter>()
val htmlPreprocessors by extensionPoint<PageTransformer>()
val postActions by extensionPoint<PostAction>()
val kotlinAnalysis by extensionPoint<KotlinAnalysis>()
val tabSortingStrategy by extensionPoint<TabSortingStrategy>()
val immediateHtmlCommandConsumer by extensionPoint<ImmediateHtmlCommandConsumer>()
Expand Down
3 changes: 3 additions & 0 deletions plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class DefaultRenderer<T>(
private set

protected open val preprocessors: Iterable<PageTransformer> = emptyList()
protected open val postActions: Iterable<PostAction> = emptyList()

abstract fun T.buildHeader(level: Int, node: ContentHeader, content: T.() -> Unit)
abstract fun T.buildLink(address: String, content: T.() -> Unit)
Expand Down Expand Up @@ -209,6 +210,8 @@ abstract class DefaultRenderer<T>(
runBlocking(Dispatchers.Default) {
renderPages(newRoot)
}

postActions.forEach { it() }
}

protected fun ContentDivergentGroup.groupDivergentInstances(
Expand Down
3 changes: 3 additions & 0 deletions plugins/base/src/main/kotlin/renderers/PostAction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.jetbrains.dokka.base.renderers

interface PostAction : () -> Unit
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ open class HtmlRenderer(
private var shouldRenderSourceSetBubbles: Boolean = false

override val preprocessors = context.plugin<DokkaBase>().query { htmlPreprocessors }
override val postActions = context.plugin<DokkaBase>().query { postActions }

private val tabSortingStrategy = context.plugin<DokkaBase>().querySingle { tabSortingStrategy }

Expand Down
70 changes: 55 additions & 15 deletions plugins/versioning/api/versioning.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,22 @@ public final class org/jetbrains/dokka/versioning/ByConfigurationVersionOrdering
}

public final class org/jetbrains/dokka/versioning/DefaultVersioningHandler : org/jetbrains/dokka/versioning/VersioningHandler {
public static final field Companion Lorg/jetbrains/dokka/versioning/DefaultVersioningHandler$Companion;
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun currentVersion ()Ljava/io/File;
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public fun getPreviousVersions ()Ljava/util/Map;
public fun getVersions ()Ljava/util/Map;
public synthetic fun invoke ()Ljava/lang/Object;
public fun invoke ()V
}

public final class org/jetbrains/dokka/versioning/DefaultVersioningHandler$Companion {
}

public final class org/jetbrains/dokka/versioning/HtmlVersionsNavigationCreator : org/jetbrains/dokka/versioning/VersionsNavigationCreator {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public fun invoke ()Ljava/lang/String;
public fun invoke (Ljava/io/File;)Ljava/lang/String;
public fun invoke (Ljava/lang/String;)Ljava/lang/String;
}

public final class org/jetbrains/dokka/versioning/MultiModuleStylesInstaller : org/jetbrains/dokka/transformers/pages/PageTransformer {
public static final field INSTANCE Lorg/jetbrains/dokka/versioning/MultiModuleStylesInstaller;
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode;
}

Expand All @@ -45,33 +40,61 @@ public final class org/jetbrains/dokka/versioning/ReplaceVersionCommandHandler :
}

public final class org/jetbrains/dokka/versioning/ReplaceVersionsCommand : org/jetbrains/dokka/base/templating/Command {
public static final field INSTANCE Lorg/jetbrains/dokka/versioning/ReplaceVersionsCommand;
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun copy (Ljava/lang/String;)Lorg/jetbrains/dokka/versioning/ReplaceVersionsCommand;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/versioning/ReplaceVersionsCommand;Ljava/lang/String;ILjava/lang/Object;)Lorg/jetbrains/dokka/versioning/ReplaceVersionsCommand;
public fun equals (Ljava/lang/Object;)Z
public final fun getLocation ()Ljava/lang/String;
public fun hashCode ()I
public final fun setLocation (Ljava/lang/String;)V
public fun toString ()Ljava/lang/String;
}

public final class org/jetbrains/dokka/versioning/SemVerVersionOrdering : org/jetbrains/dokka/versioning/VersionsOrdering {
public fun <init> ()V
public fun order (Ljava/util/List;)Ljava/util/List;
}

public final class org/jetbrains/dokka/versioning/VersionDirs {
public fun <init> (Ljava/io/File;Ljava/io/File;)V
public final fun component1 ()Ljava/io/File;
public final fun component2 ()Ljava/io/File;
public final fun copy (Ljava/io/File;Ljava/io/File;)Lorg/jetbrains/dokka/versioning/VersionDirs;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/versioning/VersionDirs;Ljava/io/File;Ljava/io/File;ILjava/lang/Object;)Lorg/jetbrains/dokka/versioning/VersionDirs;
public fun equals (Ljava/lang/Object;)Z
public final fun getDst ()Ljava/io/File;
public final fun getSrc ()Ljava/io/File;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class org/jetbrains/dokka/versioning/VersioningConfiguration : org/jetbrains/dokka/plugability/ConfigurableBlock {
public static final field Companion Lorg/jetbrains/dokka/versioning/VersioningConfiguration$Companion;
public static final field OLDER_VERSIONS_DIR Ljava/lang/String;
public static final field VERSIONS_FILE Ljava/lang/String;
public fun <init> ()V
public fun <init> (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;Ljava/lang/Boolean;)V
public synthetic fun <init> (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/io/File;
public final fun component2 ()Ljava/util/List;
public final fun component3 ()Ljava/util/List;
public final fun component4 ()Ljava/lang/String;
public final fun copy (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;)Lorg/jetbrains/dokka/versioning/VersioningConfiguration;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/versioning/VersioningConfiguration;Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;ILjava/lang/Object;)Lorg/jetbrains/dokka/versioning/VersioningConfiguration;
public final fun component5 ()Ljava/lang/Boolean;
public final fun copy (Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;Ljava/lang/Boolean;)Lorg/jetbrains/dokka/versioning/VersioningConfiguration;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/versioning/VersioningConfiguration;Ljava/io/File;Ljava/util/List;Ljava/util/List;Ljava/lang/String;Ljava/lang/Boolean;ILjava/lang/Object;)Lorg/jetbrains/dokka/versioning/VersioningConfiguration;
public fun equals (Ljava/lang/Object;)Z
public final fun getOlderVersions ()Ljava/util/List;
public final fun getOlderVersionsDir ()Ljava/io/File;
public final fun getOnEachPage ()Ljava/lang/Boolean;
public final fun getVersion ()Ljava/lang/String;
public final fun getVersionsOrdering ()Ljava/util/List;
public fun hashCode ()I
public final fun setOlderVersions (Ljava/util/List;)V
public final fun setOlderVersionsDir (Ljava/io/File;)V
public final fun setOnEachPage (Ljava/lang/Boolean;)V
public final fun setVersion (Ljava/lang/String;)V
public final fun setVersionsOrdering (Ljava/util/List;)V
public fun toString ()Ljava/lang/String;
Expand All @@ -80,12 +103,14 @@ public final class org/jetbrains/dokka/versioning/VersioningConfiguration : org/
public final class org/jetbrains/dokka/versioning/VersioningConfiguration$Companion {
public final fun getDefaultOlderVersions ()Ljava/util/List;
public final fun getDefaultOlderVersionsDir ()Ljava/io/File;
public final fun getDefaultOnEachPage ()Z
public final fun getDefaultVersion ()Ljava/lang/Void;
public final fun getDefaultVersionsOrdering ()Ljava/util/List;
}

public abstract interface class org/jetbrains/dokka/versioning/VersioningHandler : kotlin/jvm/functions/Function0 {
public abstract interface class org/jetbrains/dokka/versioning/VersioningHandler {
public abstract fun currentVersion ()Ljava/io/File;
public abstract fun getPreviousVersions ()Ljava/util/Map;
public abstract fun getVersions ()Ljava/util/Map;
}

Expand All @@ -94,6 +119,8 @@ public final class org/jetbrains/dokka/versioning/VersioningPlugin : org/jetbrai
public final fun getCssStyleInstaller ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getDefaultVersioningHandler ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getDefaultVersioningNavigationCreator ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getDefaultVersionsNavigationAdder ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getPreviousDocumentationCopier ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getReplaceVersionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getResolveLinkConsumer ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getVersioningHandler ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
Expand All @@ -103,11 +130,24 @@ public final class org/jetbrains/dokka/versioning/VersioningPlugin : org/jetbrai
}

public abstract interface class org/jetbrains/dokka/versioning/VersionsNavigationCreator {
public abstract fun invoke ()Ljava/lang/String;
public abstract fun invoke (Ljava/io/File;)Ljava/lang/String;
public abstract fun invoke (Ljava/lang/String;)Ljava/lang/String;
}

public abstract interface class org/jetbrains/dokka/versioning/VersionsOrdering {
public abstract fun order (Ljava/util/List;)Ljava/util/List;
}

public final class versioning/DefaultPreviousDocumentationCopier : org/jetbrains/dokka/base/renderers/PostAction {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public synthetic fun invoke ()Ljava/lang/Object;
public fun invoke ()V
}

public final class versioning/VersionsNavigationAdder : org/jetbrains/dokka/transformers/pages/PageTransformer {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode;
}

Loading

0 comments on commit 48bafab

Please sign in to comment.