Skip to content

Commit

Permalink
Rename handleCommandto handleCommandAsTag
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Feb 21, 2022
1 parent 7d279f8 commit 3ca49ad
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions plugins/all-modules-page/api/all-modules-page.api
Expand Up @@ -84,5 +84,6 @@ public final class org/jetbrains/dokka/allModulesPage/ResolveLinkCommandHandler
public fun finish (Ljava/io/File;)V
public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsComment (Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsTag (Lorg/jetbrains/dokka/base/templating/Command;Lorg/jsoup/nodes/Element;Ljava/io/File;Ljava/io/File;)V
}

Expand Up @@ -16,29 +16,29 @@ class ResolveLinkCommandHandler(context: DokkaContext) : CommandHandler {
private val externalModuleLinkResolver =
context.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver }

override fun handleCommand(element: Element, command: Command, input: File, output: File) {
override fun handleCommandAsTag(command: Command, body: Element, input: File, output: File) {
command as ResolveLinkCommand
val link = externalModuleLinkResolver.resolve(command.dri, output)
if (link == null) {
val children = element.childNodes().toList()
val children = body.childNodes().toList()
val attributes = Attributes().apply {
put("data-unresolved-link", command.dri.toString())
}
val el = Element(Tag.valueOf("span"), "", attributes).apply {
children.forEach { ch -> appendChild(ch) }
}
element.replaceWith(el)
body.replaceWith(el)
return
}

val attributes = Attributes().apply {
put("href", link)
}
val children = element.childNodes().toList()
val children = body.childNodes().toList()
val el = Element(Tag.valueOf("a"), "", attributes).apply {
children.forEach { ch -> appendChild(ch) }
}
element.replaceWith(el)
body.replaceWith(el)
}

override fun canHandle(command: Command): Boolean = command is ResolveLinkCommand
Expand Down
5 changes: 5 additions & 0 deletions plugins/templating/api/templating.api
Expand Up @@ -29,17 +29,20 @@ public final class org/jetbrains/dokka/templates/AddToNavigationCommandHandler :
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 fun handleCommandAsComment (Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsTag (Lorg/jetbrains/dokka/base/templating/Command;Lorg/jsoup/nodes/Element;Ljava/io/File;Ljava/io/File;)V
}

public abstract interface class org/jetbrains/dokka/templates/CommandHandler {
public abstract fun canHandle (Lorg/jetbrains/dokka/base/templating/Command;)Z
public abstract fun finish (Ljava/io/File;)V
public abstract fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
public abstract fun handleCommandAsComment (Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public abstract fun handleCommandAsTag (Lorg/jetbrains/dokka/base/templating/Command;Lorg/jsoup/nodes/Element;Ljava/io/File;Ljava/io/File;)V
}

public final class org/jetbrains/dokka/templates/CommandHandler$DefaultImpls {
public static fun finish (Lorg/jetbrains/dokka/templates/CommandHandler;Ljava/io/File;)V
public static fun handleCommand (Lorg/jetbrains/dokka/templates/CommandHandler;Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
public static fun handleCommandAsComment (Lorg/jetbrains/dokka/templates/CommandHandler;Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
}

Expand Down Expand Up @@ -87,6 +90,7 @@ public final class org/jetbrains/dokka/templates/SubstitutionCommandHandler : or
public fun finish (Ljava/io/File;)V
public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsComment (Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsTag (Lorg/jetbrains/dokka/base/templating/Command;Lorg/jsoup/nodes/Element;Ljava/io/File;Ljava/io/File;)V
}

public abstract interface class org/jetbrains/dokka/templates/Substitutor {
Expand Down Expand Up @@ -168,6 +172,7 @@ public final class templates/ReplaceVersionCommandHandler : org/jetbrains/dokka/
public fun finish (Ljava/io/File;)V
public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsComment (Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsTag (Lorg/jetbrains/dokka/base/templating/Command;Lorg/jsoup/nodes/Element;Ljava/io/File;Ljava/io/File;)V
}

public final class templates/SourcesetDependencyProcessingStrategy : org/jetbrains/dokka/templates/TemplateProcessingStrategy {
Expand Down
Expand Up @@ -13,12 +13,12 @@ import java.util.concurrent.ConcurrentHashMap
class AddToNavigationCommandHandler(val context: DokkaContext) : CommandHandler {
private val navigationFragments = ConcurrentHashMap<String, Element>()

override fun handleCommand(element: Element, command: Command, input: File, output: File) {
override fun handleCommandAsTag(command: Command, body: Element, input: File, output: File) {
command as AddToNavigationCommand
context.configuration.modules.find { it.name == command.moduleName }
?.relativePathToOutputDirectory
?.relativeToOrSelf(context.configuration.outputDir)
?.let { key -> navigationFragments[key.toString()] = element }
?.let { key -> navigationFragments[key.toString()] = body }
}

override fun canHandle(command: Command) = command is AddToNavigationCommand
Expand Down
Expand Up @@ -7,7 +7,10 @@ import java.io.File


interface CommandHandler {
fun handleCommand(element: Element, command: Command, input: File, output: File)
@Deprecated("This was renamed to handleCommandAsTag", ReplaceWith("handleCommandAsTag(command, element, input, output)"))
fun handleCommand(element: Element, command: Command, input: File, output: File) =
handleCommandAsTag(command, element, input, output)
fun handleCommandAsTag(command: Command, body: Element, input: File, output: File)
fun handleCommandAsComment(command: Command, body: List<Node>, input: File, output: File) { }
fun canHandle(command: Command): Boolean
fun finish(output: File) {}
Expand Down
Expand Up @@ -42,7 +42,7 @@ class DirectiveBasedHtmlTemplateProcessingStrategy(private val context: DokkaCon
} else false

fun handleCommandAsTag(element: Element, command: Command, input: File, output: File) {
traverseHandlers(command) { handleCommand(element, command, input, output) }
traverseHandlers(command) { handleCommandAsTag(command, element, input, output) }
}

fun handleCommandAsComment(command: Command, body: List<Node>, input: File, output: File) {
Expand Down
Expand Up @@ -12,10 +12,10 @@ class ReplaceVersionCommandHandler(private val context: DokkaContext) : CommandH

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()
override fun handleCommandAsTag(command: Command, body: Element, input: File, output: File) {
val position = body.elementSiblingIndex()
val parent = body.parent()
body.remove()
context.configuration.moduleVersion?.takeIf { it.isNotEmpty() }
?.let { parent.insertChildren(position, TextNode(it)) }
}
Expand Down
Expand Up @@ -13,14 +13,14 @@ import java.io.File

class SubstitutionCommandHandler(context: DokkaContext) : CommandHandler {

override fun handleCommand(element: Element, command: Command, input: File, output: File) {
override fun handleCommandAsTag(command: Command, body: Element, input: File, output: File) {
command as SubstitutionCommand
val childrenCopy = element.children().toList()
val childrenCopy = body.children().toList()
substitute(childrenCopy, TemplatingContext(input, output, childrenCopy, command))

val position = element.elementSiblingIndex()
val parent = element.parent()
element.remove()
val position = body.elementSiblingIndex()
val parent = body.parent()
body.remove()

parent?.insertChildren(position, childrenCopy)
}
Expand Down
Expand Up @@ -7,6 +7,7 @@ import templates.ProjectNameSubstitutor
import templates.ReplaceVersionCommandHandler
import templates.SourcesetDependencyProcessingStrategy

@Suppress("unused")
class TemplatingPlugin : DokkaPlugin() {

val submoduleTemplateProcessor by extensionPoint<SubmoduleTemplateProcessor>()
Expand Down
1 change: 1 addition & 0 deletions plugins/versioning/api/versioning.api
Expand Up @@ -60,6 +60,7 @@ public final class org/jetbrains/dokka/versioning/ReplaceVersionCommandHandler :
public final fun getVersionsNavigationCreator ()Lorg/jetbrains/dokka/versioning/VersionsNavigationCreator;
public fun handleCommand (Lorg/jsoup/nodes/Element;Lorg/jetbrains/dokka/base/templating/Command;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsComment (Lorg/jetbrains/dokka/base/templating/Command;Ljava/util/List;Ljava/io/File;Ljava/io/File;)V
public fun handleCommandAsTag (Lorg/jetbrains/dokka/base/templating/Command;Lorg/jsoup/nodes/Element;Ljava/io/File;Ljava/io/File;)V
}

public final class org/jetbrains/dokka/versioning/SemVerVersionOrdering : org/jetbrains/dokka/versioning/VersionsOrdering {
Expand Down
Expand Up @@ -18,7 +18,7 @@ class ReplaceVersionCommandHandler(context: DokkaContext) : CommandHandler {

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

override fun handleCommand(element: Element, command: Command, input: File, output: File) {
override fun handleCommandAsTag(command: Command, element: Element, input: File, output: File) {
element.empty()
element.append(versionsNavigationCreator(output))
}
Expand Down

0 comments on commit 3ca49ad

Please sign in to comment.