diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/CoreExtensions.kt | 8 | ||||
-rw-r--r-- | core/src/main/kotlin/DokkaGenerator.kt | 7 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/PageNodes.kt | 82 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/DokkaContext.kt | 3 | ||||
-rw-r--r-- | core/src/main/kotlin/renderers/HtmlRenderer.kt | 8 | ||||
-rw-r--r-- | core/src/main/kotlin/transformers/PageNodeTransformer.kt | 8 |
6 files changed, 99 insertions, 17 deletions
diff --git a/core/src/main/kotlin/CoreExtensions.kt b/core/src/main/kotlin/CoreExtensions.kt new file mode 100644 index 00000000..32559d52 --- /dev/null +++ b/core/src/main/kotlin/CoreExtensions.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka + +import org.jetbrains.dokka.plugability.ExtensionPoint +import org.jetbrains.dokka.transformers.PageNodeTransformer + +object CoreExtensions { + val pageTransformer = ExtensionPoint<PageNodeTransformer>(this::class.qualifiedName!!, "pageTransformer") +}
\ No newline at end of file diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index f02f1e87..129549b9 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -62,11 +62,10 @@ class DokkaGenerator( } }.let { val markdownConverter = MarkdownToContentConverter(logger) -// it.forEach { it.genericPretty().also(::nierzigoj) } DefaultDocumentationToPageTransformer(markdownConverter, logger).transform(DocumentationNodesMerger(it)) - } - .also { -// it.genericPretty().also(::nierzigoj) + }.let { + context[CoreExtensions.pageTransformer].fold(it) { pn, t -> t.action.invoke(pn, context) } + }.also { HtmlRenderer( FileWriter(configuration.outputDir, ""), DefaultLocationProvider(it, configuration, ".${configuration.format}") diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt index 0d6072f7..810cd776 100644 --- a/core/src/main/kotlin/pages/PageNodes.kt +++ b/core/src/main/kotlin/pages/PageNodes.kt @@ -10,10 +10,18 @@ interface PageNode { val parent: PageNode? val dri: DRI val documentationNode: DocumentationNode<*>? + val embeddedResources: List<String> val children: List<PageNode> + + fun modified( + name: String = this.name, + content: ContentNode = this.content, + embeddedResources: List<String> = this.embeddedResources, + children: List<PageNode> = this.children + ): PageNode } -abstract class BasicPageNode(children: List<PageNode>): PageNode { +abstract class BasicPageNode(children: List<PageNode>) : PageNode { private lateinit var _parent: PageNode override val parent: PageNode? by lazy { _parent } @@ -22,8 +30,7 @@ abstract class BasicPageNode(children: List<PageNode>): PageNode { override fun equals(other: Any?): Boolean = if (other is PageNode) { dri == other.dri && name == other.name - } - else false + } else false override fun hashCode(): Int = (name + dri).hashCode() @@ -31,17 +38,26 @@ abstract class BasicPageNode(children: List<PageNode>): PageNode { init { children.forEach { if (it is BasicPageNode) it._parent = this } } - } class ModulePageNode( override val name: String, override val content: ContentNode, override val documentationNode: DocumentationNode<*>?, - children: List<PageNode> -): BasicPageNode(children) { + children: List<PageNode>, + override val embeddedResources: List<String> = listOf() +) : BasicPageNode(children) { override val parent: Nothing? = null override val dri: DRI = DRI.topLevel + + override fun modified( + name: String, + content: ContentNode, + embeddedResources: List<String>, + children: List<PageNode> + ): ModulePageNode = + if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this + else ModulePageNode(name, content, documentationNode, children, embeddedResources) } class PackagePageNode( @@ -49,30 +65,70 @@ class PackagePageNode( override val content: ContentNode, override val dri: DRI, override val documentationNode: DocumentationNode<*>?, - children: List<PageNode> -): BasicPageNode(children) + children: List<PageNode>, + override val embeddedResources: List<String> = listOf() +) : BasicPageNode(children) { + + override fun modified( + name: String, + content: ContentNode, + embeddedResources: List<String>, + children: List<PageNode> + ): PackagePageNode = + if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this + else PackagePageNode(name, content, dri, documentationNode, children, embeddedResources) +} class ClassPageNode( override val name: String, override val content: ContentNode, override val dri: DRI, override val documentationNode: DocumentationNode<*>?, - children: List<PageNode> -): BasicPageNode(children) + children: List<PageNode>, + override val embeddedResources: List<String> = listOf() +) : BasicPageNode(children) { + + override fun modified( + name: String, + content: ContentNode, + embeddedResources: List<String>, + children: List<PageNode> + ): ClassPageNode = + if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this + else ClassPageNode(name, content, dri, documentationNode, children, embeddedResources) +} class MemberPageNode( override val name: String, override val content: ContentNode, override val dri: DRI, override val documentationNode: DocumentationNode<*>?, - children: List<PageNode> = emptyList() -): BasicPageNode(children) + children: List<PageNode> = emptyList(), + override val embeddedResources: List<String> = listOf() +) : BasicPageNode(children) { + + override fun modified( + name: String, + content: ContentNode, + embeddedResources: List<String>, + children: List<PageNode> + ): MemberPageNode = + if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this + else MemberPageNode(name, content, dri, documentationNode, children, embeddedResources) +} data class PlatformData(val platformType: Platform, val targets: List<String>) { override fun toString() = targets.toString() } -fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) { this } else { this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() } +fun PageNode.dfs(predicate: (PageNode) -> Boolean): PageNode? = if (predicate(this)) { + this +} else { + this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull() +} + +private infix fun <T> List<T>.shallowEq(other: List<T>) = + this === other || (this.size == other.size && (this zip other).all { (a, b) -> a === b }) // Navigation?? diff --git a/core/src/main/kotlin/plugability/DokkaContext.kt b/core/src/main/kotlin/plugability/DokkaContext.kt index d67f34b1..dcd3398e 100644 --- a/core/src/main/kotlin/plugability/DokkaContext.kt +++ b/core/src/main/kotlin/plugability/DokkaContext.kt @@ -11,6 +11,9 @@ class DokkaContext private constructor() { internal val extensions = mutableMapOf<ExtensionPoint<*>, MutableList<Extension<*>>>() + @Suppress("UNCHECKED_CAST") + operator fun <T: Any, E: ExtensionPoint<T>> get(point: E) = extensions[point] as List<Extension<T>> + @PublishedApi internal fun plugin(kclass: KClass<*>) = plugins[kclass] diff --git a/core/src/main/kotlin/renderers/HtmlRenderer.kt b/core/src/main/kotlin/renderers/HtmlRenderer.kt index f750140a..3b778671 100644 --- a/core/src/main/kotlin/renderers/HtmlRenderer.kt +++ b/core/src/main/kotlin/renderers/HtmlRenderer.kt @@ -4,6 +4,9 @@ import org.jetbrains.dokka.htmlEscape import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.resolvers.LocationProvider import java.io.File +import java.net.URL +import java.nio.file.Path +import java.nio.file.Paths open class HtmlRenderer(fileWriter: FileWriter, locationProvider: LocationProvider) : DefaultRenderer(fileWriter, locationProvider) { @@ -69,11 +72,16 @@ open class HtmlRenderer(fileWriter: FileWriter, locationProvider: LocationProvid ) } + protected open fun buildScripts(page: PageNode) = + page.embeddedResources.filter { URL(it).path.substringAfterLast('.') == "js" } + .joinToString(separator = "") { """<script type = "text/javascript" async src = "$it"></script>""" + "\n" } + protected open fun buildStartHtml(page: PageNode) = """<!DOCTYPE html> |<html> |<head> |<title>${page.name}</title> |<link rel="stylesheet" href="${locationProvider.resolveRoot(page)}style.css" /> + |${buildScripts(page)} |</head> |<body> |""".trimMargin() diff --git a/core/src/main/kotlin/transformers/PageNodeTransformer.kt b/core/src/main/kotlin/transformers/PageNodeTransformer.kt new file mode 100644 index 00000000..b86e0b34 --- /dev/null +++ b/core/src/main/kotlin/transformers/PageNodeTransformer.kt @@ -0,0 +1,8 @@ +package org.jetbrains.dokka.transformers + +import org.jetbrains.dokka.pages.ModulePageNode +import org.jetbrains.dokka.plugability.DokkaContext + +interface PageNodeTransformer { + fun invoke(input: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode +}
\ No newline at end of file |