diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-06-30 08:03:38 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-07-01 09:43:03 +0200 |
commit | a16e101fad10d024a84aa36069ec6032fcbaf3e6 (patch) | |
tree | 64e19695dccd67c3e1b1621eeac2ad469e01cb46 /plugins/javadoc/src/main/kotlin | |
parent | 14e71e40dfab5f18ccd56b0c015383c0dfb5df51 (diff) | |
download | dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.gz dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.tar.bz2 dokka-a16e101fad10d024a84aa36069ec6032fcbaf3e6.zip |
Implement `AbstractJavadocTemplateMapTest` API
Diffstat (limited to 'plugins/javadoc/src/main/kotlin')
4 files changed, 33 insertions, 16 deletions
diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index 767e0c68..ebe223e5 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -163,7 +163,7 @@ open class JavadocPageCreator( private val firstSentenceRegex = Regex("^((?:[^.?!]|[.!?](?!\\s))*[.!?])") private inline fun <reified T : TagWrapper> Documentable.findNodeInDocumentation(sourceSetData: DokkaSourceSet?): T? = - documentation[sourceSetData]?.firstChildOfType<T>() + documentation[sourceSetData]?.firstChildOfTypeOrNull<T>() private fun Documentable.descriptionToContentNodes(sourceSet: DokkaSourceSet? = highestJvmSourceSet) = findNodeInDocumentation<Description>(sourceSet)?.let { DocTagToContentConverter.buildContent( diff --git a/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt b/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt index 50a971ea..c9dfdbfc 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt @@ -1,6 +1,7 @@ package javadoc.renderer import javadoc.pages.* +import javadoc.toNormalized import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.links.DRI @@ -9,22 +10,23 @@ import org.jetbrains.dokka.model.ImplementedInterfaces import org.jetbrains.dokka.model.InheritedFunction import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext +import java.nio.file.Paths internal class JavadocContentToTemplateMapTranslator( private val locationProvider: LocationProvider, private val context: DokkaContext, ) { - fun templateMapForPageNode(node: JavadocPageNode, pathToRoot: String): TemplateMap = + fun templateMapForPageNode(node: JavadocPageNode): TemplateMap = mapOf<String, Any?>( "docName" to "docName", // todo docname - "pathToRoot" to pathToRoot, + "pathToRoot" to pathToRoot(node), "contextRoot" to node, "kind" to "main", ) + templateMapForNode(node) - fun templateMapForNode(node: JavadocPageNode): TemplateMap = + private fun templateMapForNode(node: JavadocPageNode): TemplateMap = when (node) { is JavadocModulePageNode -> InnerTranslator(node).templateMapForJavadocContentNode(node.content) is JavadocClasslikePageNode -> InnerTranslator(node).templateMapForClasslikeNode(node) @@ -34,6 +36,21 @@ internal class JavadocContentToTemplateMapTranslator( else -> emptyMap() } + private fun pathToRoot(node: JavadocPageNode): String { + return when(node){ + is JavadocModulePageNode -> "" + else -> run { + val link = locationProvider.resolve(node, skipExtension = true) + val dir = Paths.get(link).parent?.toNormalized().orEmpty() + return dir.split("/").filter { it.isNotEmpty() }.joinToString("/") { ".." }.let { + if (it.isNotEmpty()) "$it/" else it + } + } + } + } + + private fun String.toNormalized() = Paths.get(this).toNormalized() + private inner class InnerTranslator(val contextNode: PageNode) { private val htmlTranslator = JavadocContentToHtmlTranslator(locationProvider, context) diff --git a/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt index a7d18100..f7d75924 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/renderer/KorteJavadocRenderer.kt @@ -4,6 +4,7 @@ import com.soywiz.korte.* import javadoc.location.JavadocLocationProvider import javadoc.pages.* import javadoc.renderer.JavadocContentToHtmlTranslator.Companion.buildLink +import javadoc.toNormalized import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -62,9 +63,8 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: private fun CoroutineScope.renderModulePageNode(node: JavadocModulePageNode) { val link = "." val name = "index" - val pathToRoot = "" - val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node, pathToRoot) + val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node) writeFromTemplate(outputWriter, "$link/$name".toNormalized(), "tabPage.korte", contentMap.toList()) node.children.forEach { renderNode(it, link) } @@ -72,12 +72,7 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: private fun CoroutineScope.renderJavadocPageNode(node: JavadocPageNode) { val link = locationProvider.resolve(node, skipExtension = true) - val dir = Paths.get(link).parent?.let { it.toNormalized() }.orEmpty() - val pathToRoot = dir.split("/").filter { it.isNotEmpty() }.joinToString("/") { ".." }.let { - if (it.isNotEmpty()) "$it/" else it - } - - val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node, pathToRoot) + val contentMap = contentToTemplateMapTranslator.templateMapForPageNode(node) writeFromTemplate(outputWriter, link, templateForNode(node), contentMap.toList()) node.children.forEach { renderNode(it, link.toNormalized()) } } @@ -99,9 +94,6 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: private fun DRI.toLink(context: PageNode? = null) = locationProvider.resolve(this, emptySet(), context) - private fun Path.toNormalized() = this.normalize().toFile().toString() - private fun String.toNormalized() = Paths.get(this).toNormalized() - private suspend fun OutputWriter.writeHtml(path: String, text: String) = write(path, text, ".html") private fun CoroutineScope.writeFromTemplate( writer: OutputWriter, @@ -194,4 +186,4 @@ class KorteJavadocRenderer(private val outputWriter: OutputWriter, val context: ?.joinToString("\n") ?: throw IllegalStateException("Template not found: $basePath/$template") } -}
\ No newline at end of file +} diff --git a/plugins/javadoc/src/main/kotlin/javadoc/utils.kt b/plugins/javadoc/src/main/kotlin/javadoc/utils.kt new file mode 100644 index 00000000..94f7c8b4 --- /dev/null +++ b/plugins/javadoc/src/main/kotlin/javadoc/utils.kt @@ -0,0 +1,8 @@ +package javadoc + +import java.nio.file.Path +import java.nio.file.Paths + +internal fun Path.toNormalized() = this.normalize().toFile().toString() + +internal fun String.toNormalized() = Paths.get(this).toNormalized() |