From 0a18e1c31f6a8dcec4b3e95f8795a53dd5df9fcc Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Sun, 3 Nov 2019 23:53:44 +0100 Subject: [WIP] intergraph transformer --- core/src/main/kotlin/renderers/DefaultRenderer.kt | 30 ++++++++++++----------- core/src/main/kotlin/renderers/HtmlRenderer.kt | 19 +++++++------- 2 files changed, 25 insertions(+), 24 deletions(-) (limited to 'core/src/main/kotlin/renderers') diff --git a/core/src/main/kotlin/renderers/DefaultRenderer.kt b/core/src/main/kotlin/renderers/DefaultRenderer.kt index 7dab7c5c..5c6b3751 100644 --- a/core/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/core/src/main/kotlin/renderers/DefaultRenderer.kt @@ -3,7 +3,7 @@ package org.jetbrains.dokka.renderers import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.resolvers.LocationProvider -abstract class DefaultRenderer(val outputDir: String, val fileWriter: FileWriter, val locationProvider: LocationProvider): Renderer { +abstract class DefaultRenderer(val fileWriter: FileWriter, val locationProvider: LocationProvider): Renderer { protected abstract fun buildHeader(level: Int, text: String): String protected abstract fun buildNewLine(): String @@ -11,29 +11,31 @@ abstract class DefaultRenderer(val outputDir: String, val fileWriter: FileWriter protected abstract fun buildCode(code: String): String protected abstract fun buildNavigation(): String // TODO protected open fun buildText(text: String): String = text - protected open fun buildGroup(children: List): String = children.joinToString { it.build() } - protected open fun buildComment(parts: List): String = parts.joinToString { it.build() } - protected open fun buildSymbol(parts: List): String = parts.joinToString { it.build() } - protected open fun buildBlock(name: String, content: List) = buildHeader(2, name) + content.joinToString("\n") { it.build() } + protected open fun buildHeader(level: Int, content: List, pageContext: PageNode): String = buildHeader(level, content.joinToString { it.build(pageContext) }) + protected open fun buildGroup(children: List, pageContext: PageNode): String = children.joinToString { it.build(pageContext) } + protected open fun buildComment(parts: List, pageContext: PageNode): String = parts.joinToString { it.build(pageContext) } + protected open fun buildSymbol(parts: List, pageContext: PageNode): String = parts.joinToString { it.build(pageContext) } + protected open fun buildBlock(name: String, content: List, pageContext: PageNode) = buildHeader(3, name) + content.joinToString("\n") { it.build(pageContext) } - protected open fun ContentNode.build(): String = buildContentNode(this) + protected open fun ContentNode.build(pageContext: PageNode): String = buildContentNode(this, pageContext) - protected open fun buildContentNode(node: ContentNode) = + protected open fun buildContentNode(node: ContentNode, pageContext: PageNode) = when(node) { is ContentText -> buildText(node.text) - is ContentComment -> buildComment(node.parts) - is ContentSymbol -> buildSymbol(node.parts) + is ContentComment -> buildComment(node.parts, pageContext) + is ContentSymbol -> buildSymbol(node.parts, pageContext) is ContentCode -> buildCode(node.code) - is ContentBlock -> buildBlock(node.name, node.children) - is ContentLink -> buildLink(node.text, locationProvider.resolve(node.address, node.platforms)) - is ContentGroup -> buildGroup(node.children) + is ContentBlock -> buildBlock(node.name, node.children, pageContext) + is ContentLink -> buildLink(node.text, locationProvider.resolve(node.address, node.platforms, pageContext)) + is ContentGroup -> buildGroup(node.children, pageContext) + is ContentHeader -> buildHeader(node.level, node.items, pageContext) else -> "" } protected open fun buildPageContent(page: PageNode): String = - buildHeader(1, page.name) + page.content.joinToString("\n") { it.build() } + /*buildHeader(1, page.name) + */ page.content.joinToString("\n") { it.build(page) } - protected open fun renderPage(page: PageNode) = fileWriter.write(locationProvider.resolve(page), buildPageContent(page)) + protected open fun renderPage(page: PageNode) = fileWriter.write(locationProvider.resolve(page), buildPageContent(page), "") protected open fun renderPages(root: PageNode) { renderPage(root) diff --git a/core/src/main/kotlin/renderers/HtmlRenderer.kt b/core/src/main/kotlin/renderers/HtmlRenderer.kt index 3a6e1576..b6d56fdc 100644 --- a/core/src/main/kotlin/renderers/HtmlRenderer.kt +++ b/core/src/main/kotlin/renderers/HtmlRenderer.kt @@ -5,11 +5,11 @@ import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.resolvers.LocationProvider -open class HtmlRenderer(outputDir: String, fileWriter: FileWriter, locationProvider: LocationProvider): DefaultRenderer(outputDir, fileWriter, locationProvider) { +open class HtmlRenderer(fileWriter: FileWriter, locationProvider: LocationProvider): DefaultRenderer(fileWriter, locationProvider) { - override fun buildComment(parts: List): String = "

${super.buildComment(parts)}

" + override fun buildComment(parts: List, pageContext: PageNode): String = "

${super.buildComment(parts, pageContext)}

" - override fun buildSymbol(parts: List): String = "${super.buildSymbol(parts)}" + override fun buildSymbol(parts: List, pageContext: PageNode): String = "${super.buildSymbol(parts, pageContext)}" override fun buildHeader(level: Int, text: String): String = "$text\n" @@ -21,17 +21,16 @@ open class HtmlRenderer(outputDir: String, fileWriter: FileWriter, locationProvi override fun buildNavigation(): String = "" // TODO implement - override fun buildGroup(children: List): String = "\n" + - "" + children.find { it is ContentLink }?.build() + "\n" + - "" + children.filterNot { it is ContentLink }.joinToString("\n") { it.build() } + "\n" + - "\n" + override fun buildGroup(children: List, pageContext: PageNode): String = + children.find { it is ContentLink }?.build(pageContext) + "\n" + + "" + children.filterNot { it is ContentLink }.joinToString("\n") { it.build(pageContext) } - override fun buildBlock(name: String, content: List): String = - buildHeader(2, name) + "\n" + content.joinToString("\n") { it.build() } + "
" + override fun buildBlock(name: String, content: List, pageContext: PageNode): String = + buildHeader(3, name) + "\n\n\n\n\n\n
\n" + content.joinToString("
") { it.build(pageContext) } + "
" override fun renderPage(page: PageNode) { val pageText = buildStartHtml(page) + buildPageContent(page) + buildEndHtml() - fileWriter.write(locationProvider.resolve(page), pageText) + fileWriter.write(locationProvider.resolve(page), pageText, "") } protected open fun buildStartHtml(page: PageNode) = """ -- cgit