diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-03-03 23:38:23 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-04 14:28:14 +0100 |
commit | d08591dea709917553c0d6de024820bb29b328fb (patch) | |
tree | 5844f98629d654ffb4fbaa0471484b149b487361 /plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt | |
parent | 156396f7520b3ac45e37068d6b72087008322cbe (diff) | |
download | dokka-d08591dea709917553c0d6de024820bb29b328fb.tar.gz dokka-d08591dea709917553c0d6de024820bb29b328fb.tar.bz2 dokka-d08591dea709917553c0d6de024820bb29b328fb.zip |
Platform dependent hints for renderer
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 960a39fd..33be5dfe 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -22,54 +22,68 @@ abstract class DefaultRenderer<T>( abstract fun T.buildHeader(level: Int, content: T.() -> Unit) abstract fun T.buildLink(address: String, content: T.() -> Unit) - abstract fun T.buildList(node: ContentList, pageContext: ContentPage) + abstract fun T.buildList(node: ContentList, pageContext: ContentPage, platformRestriction: PlatformData? = null) abstract fun T.buildNewLine() abstract fun T.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) - abstract fun T.buildTable(node: ContentTable, pageContext: ContentPage) + abstract fun T.buildTable(node: ContentTable, pageContext: ContentPage, platformRestriction: PlatformData? = null) abstract fun T.buildText(textNode: ContentText) abstract fun T.buildNavigation(page: PageNode) abstract fun buildPage(page: ContentPage, content: (T, ContentPage) -> Unit): String abstract fun buildError(node: ContentNode) - open fun T.buildGroup(node: ContentGroup, pageContext: ContentPage) = wrapGroup(node, pageContext) { - node.children.forEach { it.build(this, pageContext) } - } + open fun T.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) = + buildContentNode(content.inner, pageContext) + + open fun T.buildGroup(node: ContentGroup, pageContext: ContentPage, platformRestriction: PlatformData? = null) = + wrapGroup(node, pageContext) { node.children.forEach { it.build(this, pageContext, platformRestriction) } } open fun T.wrapGroup(node: ContentGroup, pageContext: ContentPage, childrenCallback: T.() -> Unit) = childrenCallback() - open fun T.buildLinkText(nodes: List<ContentNode>, pageContext: ContentPage) { - nodes.forEach { it.build(this, pageContext) } + open fun T.buildLinkText( + nodes: List<ContentNode>, + pageContext: ContentPage, + platformRestriction: PlatformData? = null + ) { + nodes.forEach { it.build(this, pageContext, platformRestriction) } } open fun T.buildCode(code: List<ContentNode>, language: String, pageContext: ContentPage) { code.forEach { it.build(this, pageContext) } } - open fun T.buildHeader(node: ContentHeader, pageContext: ContentPage) { - buildHeader(node.level) { node.children.forEach { it.build(this, pageContext) } } + open fun T.buildHeader(node: ContentHeader, pageContext: ContentPage, platformRestriction: PlatformData? = null) { + buildHeader(node.level) { node.children.forEach { it.build(this, pageContext, platformRestriction) } } } - open fun ContentNode.build(builder: T, pageContext: ContentPage) = - builder.buildContentNode(this, pageContext) - - open fun T.buildContentNode(node: ContentNode, pageContext: ContentPage) { - when (node) { - is ContentText -> buildText(node) - is ContentHeader -> buildHeader(node, pageContext) - is ContentCode -> buildCode(node.children, node.language, pageContext) - is ContentDRILink -> buildLink( - locationProvider.resolve(node.address, node.platforms.toList(), pageContext) - ) { - buildLinkText(node.children, pageContext) + open fun ContentNode.build(builder: T, pageContext: ContentPage, platformRestriction: PlatformData? = null) = + builder.buildContentNode(this, pageContext, platformRestriction) + + open fun T.buildContentNode( + node: ContentNode, + pageContext: ContentPage, + platformRestriction: PlatformData? = null + ) { + if (platformRestriction == null || platformRestriction in node.platforms) { + when (node) { + is ContentText -> buildText(node) + is ContentHeader -> buildHeader(node, pageContext, platformRestriction) + is ContentCode -> buildCode(node.children, node.language, pageContext) + is ContentDRILink -> + buildLink(locationProvider.resolve(node.address, node.platforms.toList(), pageContext)) { + buildLinkText(node.children, pageContext, platformRestriction) + } + is ContentResolvedLink -> buildLink(node.address) { + buildLinkText(node.children, pageContext, platformRestriction) + } + is ContentEmbeddedResource -> buildResource(node, pageContext) + is ContentList -> buildList(node, pageContext, platformRestriction) + is ContentTable -> buildTable(node, pageContext, platformRestriction) + is ContentGroup -> buildGroup(node, pageContext, platformRestriction) + is PlatformHintedContent -> buildPlatformDependent(node, pageContext) + else -> buildError(node) } - is ContentResolvedLink -> buildLink(node.address) { buildLinkText(node.children, pageContext) } - is ContentEmbeddedResource -> buildResource(node, pageContext) - is ContentList -> buildList(node, pageContext) - is ContentTable -> buildTable(node, pageContext) - is ContentGroup -> buildGroup(node, pageContext) - else -> buildError(node) } } |