Skip to content

Commit

Permalink
Make versioning navigator for WebHelp
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Sep 1, 2021
1 parent 9fee85f commit 372ba3d
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 114 deletions.
2 changes: 0 additions & 2 deletions docs/src/doc/docs/user_guide/versioning/versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Versioning plugin aims to provide users with ability to create a versioned documentation.
Therefore, users of the documentation can view different versions of the documentation by going to the main page and change versions.

Versioning plugin is applied by default but not enabled in Dokka so there is no need to apply it manually.

Versioning can be configured using:

* version - a string value representing a version that should be displayed in the dropdown.
Expand Down
1 change: 0 additions & 1 deletion plugins/all-modules-page/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ registerDokkaArtifactPublication("dokkaAllModulesPage") {
dependencies {
implementation(project(":plugins:base"))
implementation(project(":plugins:templating"))
implementation(project(":plugins:versioning"))
testImplementation(project(":plugins:base"))
testImplementation(project(":plugins:base:base-test-utils"))
testImplementation(project(":plugins:gfm"))
Expand Down
23 changes: 23 additions & 0 deletions plugins/base/api/base.api
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public final class org/jetbrains/dokka/base/DokkaBase : org/jetbrains/dokka/plug
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 getReplaceVersionConsumer ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getResolveLinkConsumer ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getRootCreator ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getSameMethodNameMerger ()Lorg/jetbrains/dokka/plugability/Extension;
Expand Down Expand Up @@ -541,6 +542,14 @@ public final class org/jetbrains/dokka/base/renderers/html/command/consumers/Pat
public fun processCommandAndFinalize (Lorg/jetbrains/dokka/base/templating/Command;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/dokka/base/renderers/html/command/consumers/ImmediateResolutionTagConsumer;)Ljava/lang/Object;
}

public final class org/jetbrains/dokka/base/renderers/html/command/consumers/ReplaceVersionsConsumer : org/jetbrains/dokka/base/templating/ImmediateHtmlCommandConsumer {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun canProcess (Lorg/jetbrains/dokka/base/templating/Command;)Z
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public fun processCommand (Lorg/jetbrains/dokka/base/templating/Command;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/dokka/base/renderers/html/command/consumers/ImmediateResolutionTagConsumer;)V
public fun processCommandAndFinalize (Lorg/jetbrains/dokka/base/templating/Command;Lkotlin/jvm/functions/Function1;Lorg/jetbrains/dokka/base/renderers/html/command/consumers/ImmediateResolutionTagConsumer;)Ljava/lang/Object;
}

public final class org/jetbrains/dokka/base/renderers/html/command/consumers/ResolveLinkConsumer : org/jetbrains/dokka/base/templating/ImmediateHtmlCommandConsumer {
public static final field INSTANCE Lorg/jetbrains/dokka/base/renderers/html/command/consumers/ResolveLinkConsumer;
public fun canProcess (Lorg/jetbrains/dokka/base/templating/Command;)Z
Expand Down Expand Up @@ -962,6 +971,20 @@ public final class org/jetbrains/dokka/base/templating/ProjectNameSubstitutionCo
public fun toString ()Ljava/lang/String;
}

public final class org/jetbrains/dokka/base/templating/ReplaceVersionsCommand : org/jetbrains/dokka/base/templating/Command {
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/base/templating/ReplaceVersionsCommand;
public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/templating/ReplaceVersionsCommand;Ljava/lang/String;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/templating/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/base/templating/ResolveLinkCommand : org/jetbrains/dokka/base/templating/Command {
public fun <init> (Lorg/jetbrains/dokka/links/DRI;)V
public final fun getDri ()Lorg/jetbrains/dokka/links/DRI;
Expand Down
5 changes: 4 additions & 1 deletion plugins/base/src/main/kotlin/DokkaBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -243,7 +244,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
}
Expand Down
10 changes: 3 additions & 7 deletions plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -753,6 +750,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 {
Expand Down Expand Up @@ -817,9 +815,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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(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()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.jetbrains.dokka.base.templating

data class ReplaceVersionsCommand(var location: String = ""): Command
9 changes: 9 additions & 0 deletions plugins/templating/api/templating.api
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public final class org/jetbrains/dokka/templates/TemplatingPlugin : org/jetbrain
public final fun getPagesSearchTemplateStrategy ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getPathToRootSubstitutor ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getProjectNameSubstitutor ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getReplaceVersionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getSourcesetDependencyProcessingStrategy ()Lorg/jetbrains/dokka/plugability/Extension;
public final fun getSubmoduleTemplateProcessor ()Lorg/jetbrains/dokka/plugability/ExtensionPoint;
public final fun getSubstitutionCommandHandler ()Lorg/jetbrains/dokka/plugability/Extension;
Expand All @@ -156,6 +157,14 @@ public final class templates/ProjectNameSubstitutor : org/jetbrains/dokka/templa
public fun trySubstitute (Lorg/jetbrains/dokka/templates/TemplatingContext;Lkotlin/text/MatchResult;)Ljava/lang/String;
}

public final class templates/ReplaceVersionCommandHandler : org/jetbrains/dokka/templates/CommandHandler {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun canHandle (Lorg/jetbrains/dokka/base/templating/Command;)Z
public fun finish (Ljava/io/File;)V
public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext;
public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
}

public final class templates/SourcesetDependencyProcessingStrategy : org/jetbrains/dokka/templates/TemplateProcessingStrategy {
public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V
public fun finish (Ljava/io/File;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package templates

import org.jetbrains.dokka.base.templating.Command
import org.jetbrains.dokka.base.templating.ReplaceVersionsCommand
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.templates.CommandHandler
import org.jsoup.nodes.Element
import org.jsoup.nodes.TextNode
import java.io.File

class ReplaceVersionCommandHandler(val context: DokkaContext) : CommandHandler {

override fun canHandle(command: Command): Boolean = command is ReplaceVersionsCommand

override fun handleCommand(element: Element, command: Command, input: File, output: File) {
val position = element.elementSiblingIndex()
val parent = element.parent()
element.remove()

parent.insertChildren(position, TextNode(context.configuration.moduleVersion.orEmpty()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.dokka.allModulesPage.templates.PackageListProcessingStrateg
import org.jetbrains.dokka.allModulesPage.templates.PagesSearchTemplateStrategy
import org.jetbrains.dokka.plugability.DokkaPlugin
import templates.ProjectNameSubstitutor
import templates.ReplaceVersionCommandHandler
import templates.SourcesetDependencyProcessingStrategy

class TemplatingPlugin : DokkaPlugin() {
Expand Down Expand Up @@ -65,4 +66,7 @@ class TemplatingPlugin : DokkaPlugin() {
val substitutionCommandHandler by extending {
directiveBasedCommandHandlers providing ::SubstitutionCommandHandler
}
val replaceVersionCommandHandler by extending {
directiveBasedCommandHandlers providing ::ReplaceVersionCommandHandler
}
}
21 changes: 0 additions & 21 deletions plugins/versioning/api/versioning.api
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ public final class org/jetbrains/dokka/versioning/ReplaceVersionCommandHandler :
public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
}

public final class org/jetbrains/dokka/versioning/ReplaceVersionsCommand : org/jetbrains/dokka/base/templating/Command {
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;
Expand Down Expand Up @@ -119,7 +105,6 @@ 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;
Expand All @@ -145,9 +130,3 @@ public final class versioning/DefaultPreviousDocumentationCopier : org/jetbrains
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;
}

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DefaultPreviousDocumentationCopier(val context: DokkaContext) : PostAction
versionRootContent.listFiles()?.forEach {
processRecursively(it, target)
}
} else if(versionRootContent.extension == "html") processingStrategies.first {
} else if (versionRootContent.extension == "html") processingStrategies.first {
it.process(versionRootContent, targetParent.resolve(versionRootContent.name), null)
} else {
versionRootContent.copyTo(targetParent.resolve(versionRootContent.name), overwrite = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.jetbrains.dokka.base.renderers.html.command.consumers.ImmediateResolu
import org.jetbrains.dokka.base.renderers.html.templateCommandFor
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
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package org.jetbrains.dokka.versioning


import org.jetbrains.dokka.base.templating.Command
import org.jetbrains.dokka.base.templating.ReplaceVersionsCommand
import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.templates.CommandHandler
import org.jsoup.nodes.Element
import java.io.File

data class ReplaceVersionsCommand(var location: String = ""): Command

class ReplaceVersionCommandHandler(context: DokkaContext) : CommandHandler {

val versionsNavigationCreator by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.jetbrains.dokka.plugability.DokkaPlugin
import org.jetbrains.dokka.plugability.configuration
import org.jetbrains.dokka.templates.TemplatingPlugin
import versioning.DefaultPreviousDocumentationCopier
import versioning.VersionsNavigationAdder

class VersioningPlugin : DokkaPlugin() {

Expand All @@ -23,10 +22,10 @@ class VersioningPlugin : DokkaPlugin() {
versionsNavigationCreator providing ::HtmlVersionsNavigationCreator
}
val replaceVersionCommandHandler by extending {
templatingPlugin.directiveBasedCommandHandlers providing ::ReplaceVersionCommandHandler
templatingPlugin.directiveBasedCommandHandlers providing ::ReplaceVersionCommandHandler override templatingPlugin.replaceVersionCommandHandler
}
val resolveLinkConsumer by extending {
dokkaBase.immediateHtmlCommandConsumer providing ::ReplaceVersionCommandConsumer
dokkaBase.immediateHtmlCommandConsumer providing ::ReplaceVersionCommandConsumer override dokkaBase.replaceVersionConsumer
}
val cssStyleInstaller by extending {
dokkaBase.htmlPreprocessors providing ::MultiModuleStylesInstaller order {
Expand All @@ -44,9 +43,4 @@ class VersioningPlugin : DokkaPlugin() {
val previousDocumentationCopier by extending {
dokkaBase.postActions providing ::DefaultPreviousDocumentationCopier applyIf { !delayTemplateSubstitution }
}
val defaultVersionsNavigationAdder by extending {
dokkaBase.htmlPreprocessors providing ::VersionsNavigationAdder order {
after(dokkaBase.assetsInstaller)
}
}
}

This file was deleted.

Loading

0 comments on commit 372ba3d

Please sign in to comment.