aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/renderers
diff options
context:
space:
mode:
authorKamil Doległo <kamilok1965@interia.pl>2019-11-03 23:53:44 +0100
committerKamil Doległo <kamilok1965@interia.pl>2019-11-04 00:07:31 +0100
commit0a18e1c31f6a8dcec4b3e95f8795a53dd5df9fcc (patch)
tree047e40a7d3c195423ad3239e05feaf0bbdcacd10 /core/src/main/kotlin/renderers
parent41b9edd65e58735e69f29369942ef953baadeb3b (diff)
downloaddokka-0a18e1c31f6a8dcec4b3e95f8795a53dd5df9fcc.tar.gz
dokka-0a18e1c31f6a8dcec4b3e95f8795a53dd5df9fcc.tar.bz2
dokka-0a18e1c31f6a8dcec4b3e95f8795a53dd5df9fcc.zip
[WIP] intergraph transformer
Diffstat (limited to 'core/src/main/kotlin/renderers')
-rw-r--r--core/src/main/kotlin/renderers/DefaultRenderer.kt30
-rw-r--r--core/src/main/kotlin/renderers/HtmlRenderer.kt19
2 files changed, 25 insertions, 24 deletions
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<ContentNode>): String = children.joinToString { it.build() }
- protected open fun buildComment(parts: List<ContentNode>): String = parts.joinToString { it.build() }
- protected open fun buildSymbol(parts: List<ContentNode>): String = parts.joinToString { it.build() }
- protected open fun buildBlock(name: String, content: List<ContentNode>) = buildHeader(2, name) + content.joinToString("\n") { it.build() }
+ protected open fun buildHeader(level: Int, content: List<ContentNode>, pageContext: PageNode): String = buildHeader(level, content.joinToString { it.build(pageContext) })
+ protected open fun buildGroup(children: List<ContentNode>, pageContext: PageNode): String = children.joinToString { it.build(pageContext) }
+ protected open fun buildComment(parts: List<ContentNode>, pageContext: PageNode): String = parts.joinToString { it.build(pageContext) }
+ protected open fun buildSymbol(parts: List<ContentNode>, pageContext: PageNode): String = parts.joinToString { it.build(pageContext) }
+ protected open fun buildBlock(name: String, content: List<ContentNode>, 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<ContentNode>): String = "<p>${super.buildComment(parts)}</p>"
+ override fun buildComment(parts: List<ContentNode>, pageContext: PageNode): String = "<p>${super.buildComment(parts, pageContext)}</p>"
- override fun buildSymbol(parts: List<ContentNode>): String = "<code>${super.buildSymbol(parts)}</code>"
+ override fun buildSymbol(parts: List<ContentNode>, pageContext: PageNode): String = "<code>${super.buildSymbol(parts, pageContext)}</code>"
override fun buildHeader(level: Int, text: String): String = "<h$level>$text</h$level>\n"
@@ -21,17 +21,16 @@ open class HtmlRenderer(outputDir: String, fileWriter: FileWriter, locationProvi
override fun buildNavigation(): String = "" // TODO implement
- override fun buildGroup(children: List<ContentNode>): String = "<tr>\n" +
- "<td>" + children.find { it is ContentLink }?.build() + "</td>\n" +
- "<td>" + children.filterNot { it is ContentLink }.joinToString("\n") { it.build() } + "</td>\n" +
- "</tr>\n"
+ override fun buildGroup(children: List<ContentNode>, pageContext: PageNode): String =
+ children.find { it is ContentLink }?.build(pageContext) + "</td>\n" +
+ "<td>" + children.filterNot { it is ContentLink }.joinToString("\n") { it.build(pageContext) }
- override fun buildBlock(name: String, content: List<ContentNode>): String =
- buildHeader(2, name) + "<table>\n" + content.joinToString("\n") { it.build() } + "</table>"
+ override fun buildBlock(name: String, content: List<ContentNode>, pageContext: PageNode): String =
+ buildHeader(3, name) + "<table>\n<tr>\n<td>\n" + content.joinToString("</td>\n</tr>\n<tr>\n<td>") { it.build(pageContext) } + "</td></tr>\n</table>"
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) = """<!DOCTYPE html>