diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2019-10-29 11:46:04 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@interia.pl> | 2019-10-29 15:49:53 +0100 |
commit | 14a290009098b777521b1dedb551047fb66ba73b (patch) | |
tree | ae68219051b080ff8888308d5521aaeea7431fb4 /core/src/main/kotlin/renderers/HtmlRenderer.kt | |
parent | 5f358199788fefb78f5db7791e718480793a77fc (diff) | |
download | dokka-14a290009098b777521b1dedb551047fb66ba73b.tar.gz dokka-14a290009098b777521b1dedb551047fb66ba73b.tar.bz2 dokka-14a290009098b777521b1dedb551047fb66ba73b.zip |
[WIP] new model
Diffstat (limited to 'core/src/main/kotlin/renderers/HtmlRenderer.kt')
-rw-r--r-- | core/src/main/kotlin/renderers/HtmlRenderer.kt | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/src/main/kotlin/renderers/HtmlRenderer.kt b/core/src/main/kotlin/renderers/HtmlRenderer.kt new file mode 100644 index 00000000..3a6e1576 --- /dev/null +++ b/core/src/main/kotlin/renderers/HtmlRenderer.kt @@ -0,0 +1,51 @@ +package org.jetbrains.dokka.renderers + +import org.jetbrains.dokka.pages.ContentLink +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) { + + override fun buildComment(parts: List<ContentNode>): String = "<p>${super.buildComment(parts)}</p>" + + override fun buildSymbol(parts: List<ContentNode>): String = "<code>${super.buildSymbol(parts)}</code>" + + override fun buildHeader(level: Int, text: String): String = "<h$level>$text</h$level>\n" + + override fun buildNewLine(): String = "<br/>" + + override fun buildLink(text: String, address: String): String = "<a href=\"$address\">$text</a>" + + override fun buildCode(code: String): String = "<code>$code</code>" + + 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 buildBlock(name: String, content: List<ContentNode>): String = + buildHeader(2, name) + "<table>\n" + content.joinToString("\n") { it.build() } + "</table>" + + override fun renderPage(page: PageNode) { + val pageText = buildStartHtml(page) + buildPageContent(page) + buildEndHtml() + fileWriter.write(locationProvider.resolve(page), pageText) + } + + protected open fun buildStartHtml(page: PageNode) = """<!DOCTYPE html> + |<html> + |<head> + |<title>${page.name}</title> + |</head> + |<body> + |""".trimMargin() + + protected open fun buildEndHtml() = + """ + | + |</body> + |</html> + """.trimMargin() +}
\ No newline at end of file |