diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-10-07 19:36:49 +0200 |
---|---|---|
committer | Błażej Kardyś <bkardys@virtuslab.com> | 2020-11-27 03:15:02 +0100 |
commit | d41965ca3cb180bc82bd5dd6fa747d2b83381b31 (patch) | |
tree | 5660f17f21fdf5871c8239f4d96c4521545292d1 /plugins/base/src/main/kotlin/renderers/html/command/consumers | |
parent | dc179bf9a649d925e7e64dbcaf52a2187416a1d5 (diff) | |
download | dokka-d41965ca3cb180bc82bd5dd6fa747d2b83381b31.tar.gz dokka-d41965ca3cb180bc82bd5dd6fa747d2b83381b31.tar.bz2 dokka-d41965ca3cb180bc82bd5dd6fa747d2b83381b31.zip |
Implement immediate temaplates resolution
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html/command/consumers')
3 files changed, 83 insertions, 0 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/command/consumers/ImmediateResolutionTagConsumer.kt b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ImmediateResolutionTagConsumer.kt new file mode 100644 index 00000000..68f6dc81 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ImmediateResolutionTagConsumer.kt @@ -0,0 +1,31 @@ +package org.jetbrains.dokka.base.renderers.html.command.consumers + +import kotlinx.html.TagConsumer +import kotlinx.html.visit +import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.renderers.html.TemplateBlock +import org.jetbrains.dokka.base.renderers.html.templateCommand +import org.jetbrains.dokka.base.renderers.html.templateCommandFor +import org.jetbrains.dokka.base.templating.Command +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.query + +class ImmediateResolutionTagConsumer<out R>( + private val downstream: TagConsumer<R>, + private val context: DokkaContext +): TagConsumer<R> by downstream { + fun processCommand(command: Command, block: TemplateBlock) { + context.plugin<DokkaBase>().query { immediateHtmlCommandConsumer } + .find { it.canProcess(command) } + ?.processCommand(command, block, this) + ?: run { templateCommandFor(command, downstream).visit(block) } + } + + fun processCommandAndFinalize(command: Command, block: TemplateBlock): R = + context.plugin<DokkaBase>().query { immediateHtmlCommandConsumer } + .find { it.canProcess(command) } + ?.processCommandAndFinalize(command, block, this) + ?: downstream.templateCommand(command, block) +} + diff --git a/plugins/base/src/main/kotlin/renderers/html/command/consumers/PathToRootConsumer.kt b/plugins/base/src/main/kotlin/renderers/html/command/consumers/PathToRootConsumer.kt new file mode 100644 index 00000000..b4649af6 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/html/command/consumers/PathToRootConsumer.kt @@ -0,0 +1,22 @@ +package org.jetbrains.dokka.base.renderers.html.command.consumers + +import org.jetbrains.dokka.base.renderers.html.TemplateBlock +import org.jetbrains.dokka.base.renderers.html.buildAsInnerHtml +import org.jetbrains.dokka.base.templating.Command +import org.jetbrains.dokka.base.templating.ImmediateHtmlCommandConsumer +import org.jetbrains.dokka.base.templating.PathToRootSubstitutionCommand + +object PathToRootConsumer: ImmediateHtmlCommandConsumer { + override fun canProcess(command: Command) = command is PathToRootSubstitutionCommand + + override fun <R> processCommand(command: Command, block: TemplateBlock, tagConsumer: ImmediateResolutionTagConsumer<R>) { + command as PathToRootSubstitutionCommand + tagConsumer.onTagContentUnsafe { +block.buildAsInnerHtml().replace(command.pattern, command.default) } + } + + override fun <R> processCommandAndFinalize(command: Command, block: TemplateBlock, tagConsumer: ImmediateResolutionTagConsumer<R>): R { + processCommand(command, block, tagConsumer) + return tagConsumer.finalize() + } + +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/html/command/consumers/ResolveLinkConsumer.kt b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ResolveLinkConsumer.kt new file mode 100644 index 00000000..1c42c3d5 --- /dev/null +++ b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ResolveLinkConsumer.kt @@ -0,0 +1,30 @@ +package org.jetbrains.dokka.base.renderers.html.command.consumers + +import kotlinx.html.SPAN +import kotlinx.html.span +import kotlinx.html.unsafe +import kotlinx.html.visit +import org.jetbrains.dokka.base.renderers.html.TemplateBlock +import org.jetbrains.dokka.base.renderers.html.buildAsInnerHtml +import org.jetbrains.dokka.base.templating.Command +import org.jetbrains.dokka.base.templating.ImmediateHtmlCommandConsumer +import org.jetbrains.dokka.base.templating.ResolveLinkCommand +import org.jetbrains.dokka.utilities.htmlEscape + +object ResolveLinkConsumer: ImmediateHtmlCommandConsumer { + override fun canProcess(command: Command) = command is ResolveLinkCommand + + override fun <R> processCommand(command: Command, block: TemplateBlock, tagConsumer: ImmediateResolutionTagConsumer<R>) { + command as ResolveLinkCommand + SPAN(mapOf("data-unresolved-link" to command.dri.toString().htmlEscape()), tagConsumer).visit { + unsafe { block.buildAsInnerHtml() } + } + } + + override fun <R> processCommandAndFinalize(command: Command, block: TemplateBlock, tagConsumer: ImmediateResolutionTagConsumer<R>): R { + command as ResolveLinkCommand + return tagConsumer.span { + attributes["data-unresolved-link"] = command.dri.toString().htmlEscape() + } + } +}
\ No newline at end of file |