aboutsummaryrefslogtreecommitdiff
path: root/src/Model/Content.kt
diff options
context:
space:
mode:
authorDmitry Jemerov <yole@jetbrains.com>2015-01-30 17:59:15 +0100
committerDmitry Jemerov <yole@jetbrains.com>2015-01-30 17:59:15 +0100
commitbfd9ffd13ed6b6916790f5f0de5f9523db71b22e (patch)
tree214ae0ff76e8b35841947b639ce3c2022ad72fec /src/Model/Content.kt
parentb55b258574a01a02f906f5f12646ecacfc640e20 (diff)
downloaddokka-bfd9ffd13ed6b6916790f5f0de5f9523db71b22e.tar.gz
dokka-bfd9ffd13ed6b6916790f5f0de5f9523db71b22e.tar.bz2
dokka-bfd9ffd13ed6b6916790f5f0de5f9523db71b22e.zip
load sections from KDoc PSI, not through Markdown extensions
Diffstat (limited to 'src/Model/Content.kt')
-rw-r--r--src/Model/Content.kt71
1 files changed, 27 insertions, 44 deletions
diff --git a/src/Model/Content.kt b/src/Model/Content.kt
index 8491fd88..2fae317d 100644
--- a/src/Model/Content.kt
+++ b/src/Model/Content.kt
@@ -1,7 +1,5 @@
package org.jetbrains.dokka
-import kotlin.properties.Delegates
-
public abstract class ContentNode {
val children = arrayListOf<ContentNode>()
@@ -34,7 +32,7 @@ public class ContentNodeLink(val node : DocumentationNode) : ContentBlock()
public class ContentExternalLink(val href : String) : ContentBlock()
public class ContentList() : ContentBlock()
public class ContentListItem() : ContentBlock()
-public class ContentSection(public val label: String) : ContentBlock()
+public class ContentSection(public val label: String, public val subjectName: String?) : ContentBlock()
fun content(body: ContentNode.() -> Unit): ContentNode {
val block = ContentBlock()
@@ -54,53 +52,38 @@ fun ContentNode.link(to: DocumentationNode, body: ContentNode.() -> Unit) {
}
public class Content() : ContentNode() {
- public val sections: Map<String, ContentSection> by Delegates.lazy {
- val map = linkedMapOf<String, ContentSection>()
- for (child in children) {
- if (child is ContentSection)
- map.put(child.label, child)
- }
-
- if ("\$summary" !in map && "\$description" !in map) {
- // no explicit summary and description, convert anonymous section
- val anonymous = map[""]
- if (anonymous != null) {
- map.remove("")
- val summary = ContentSection("\$summary")
- val description = ContentSection("\$description")
-
- val summaryNodes = anonymous.children.take(1)
- val descriptionNodes = anonymous.children.drop(1)
-
- if (summaryNodes.any()) {
- summary.children.addAll(summaryNodes)
- map.put("\$summary", summary)
- }
-
- if (descriptionNodes.any()) {
- description.children.addAll(descriptionNodes)
- map.put("\$description", description)
- }
- }
- }
- map
+ private val sectionList = arrayListOf<ContentSection>()
+ public val sections: List<ContentSection>
+ get() = sectionList
+
+ fun addSection(name: String?, subjectName: String?): ContentSection {
+ val section = ContentSection(name ?: "", subjectName)
+ sectionList.add(section)
+ return section
}
- public val summary: ContentNode get() {
- return sections["\$summary"] ?: ContentNode.empty
+ fun findSectionByName(name: String): ContentSection? =
+ sections.firstOrNull { it.label == name }
+
+ fun getSectionsWithSubjects(): Map<String, List<ContentSection>> =
+ sections.filter { it.subjectName != null }.groupBy { it.label }
+
+ public val summary: ContentNode get() = children.firstOrNull() ?: ContentEmpty
+
+ public val description: ContentNode get() {
+ val descriptionNodes = children.drop(1)
+ if (descriptionNodes.isEmpty()) {
+ return ContentEmpty
+ }
+ val result = ContentSection("\$description", null)
+ result.children.addAll(descriptionNodes)
+ return result
}
- public val description: ContentNode get() = sections["\$description"] ?: ContentNode.empty
override fun equals(other: Any?): Boolean {
if (other !is Content)
return false
- if (sections.size != other.sections.size)
- return false
- for (keys in sections.keySet())
- if (sections[keys] != other.sections[keys])
- return false
-
- return true
+ return sections == other.sections && children == other.children
}
override fun hashCode(): Int {
@@ -110,7 +93,7 @@ public class Content() : ContentNode() {
override fun toString(): String {
if (sections.isEmpty())
return "<empty>"
- return sections.values().joinToString()
+ return sections.joinToString()
}
val isEmpty: Boolean