aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/Formats
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/Formats')
-rw-r--r--core/src/main/kotlin/Formats/ExtraOutlineServices.kt20
-rw-r--r--core/src/main/kotlin/Formats/FormatDescriptor.kt1
-rw-r--r--core/src/main/kotlin/Formats/HtmlFormatService.kt6
-rw-r--r--core/src/main/kotlin/Formats/OutlineService.kt4
-rw-r--r--core/src/main/kotlin/Formats/StandardFormats.kt4
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt18
-rw-r--r--core/src/main/kotlin/Formats/YamlOutlineService.kt4
7 files changed, 44 insertions, 13 deletions
diff --git a/core/src/main/kotlin/Formats/ExtraOutlineServices.kt b/core/src/main/kotlin/Formats/ExtraOutlineServices.kt
new file mode 100644
index 000000000..e4eeac01a
--- /dev/null
+++ b/core/src/main/kotlin/Formats/ExtraOutlineServices.kt
@@ -0,0 +1,20 @@
+package org.jetbrains.dokka
+
+import java.io.File
+
+/**
+ * Outline service that is responsible for generating a single outline format.
+ *
+ * TODO: port existing implementations of ExtraOutlineService to OutlineService, and remove this.
+ */
+interface ExtraOutlineService {
+ fun getFileName(): String
+ fun getFile(location: Location): File
+ fun format(node: DocumentationNode): String
+}
+
+/**
+ * Holder of all of the extra outline services needed for a StandardFormat, in addition to the main
+ * [OutlineFormatService].
+ */
+abstract class ExtraOutlineServices(vararg val services: ExtraOutlineService)
diff --git a/core/src/main/kotlin/Formats/FormatDescriptor.kt b/core/src/main/kotlin/Formats/FormatDescriptor.kt
index fc925f409..e422aa14a 100644
--- a/core/src/main/kotlin/Formats/FormatDescriptor.kt
+++ b/core/src/main/kotlin/Formats/FormatDescriptor.kt
@@ -12,4 +12,5 @@ interface FormatDescriptor {
val javaDocumentationBuilderClass: KClass<out JavaDocumentationBuilder>
val sampleProcessingService: KClass<out SampleProcessingService>
val packageListServiceClass: KClass<out PackageListService>?
+ val extraOutlineServices: KClass<out ExtraOutlineServices>?
}
diff --git a/core/src/main/kotlin/Formats/HtmlFormatService.kt b/core/src/main/kotlin/Formats/HtmlFormatService.kt
index b66724348..ce9acb26c 100644
--- a/core/src/main/kotlin/Formats/HtmlFormatService.kt
+++ b/core/src/main/kotlin/Formats/HtmlFormatService.kt
@@ -105,6 +105,8 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
callback("/dokka/styles/style.css", "style.css")
}
+ override fun getOutlineFileName(): String = "index"
+
override fun createOutputBuilder(to: StringBuilder, location: Location) =
HtmlOutputBuilder(to, location, locationService, languageService, extension, impliedPlatforms, templateService)
@@ -114,7 +116,7 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
templateService.appendFooter(to)
}
- override fun getOutlineFileName(location: Location): File {
+ override fun getOutlineFile(location: Location): File {
return File("${location.path}-outline.html")
}
@@ -133,7 +135,7 @@ open class HtmlFormatService @Inject constructor(@Named("folders") locationServi
}
}
-private fun LocationService.calcPathToRoot(location: Location): Path {
+fun LocationService.calcPathToRoot(location: Location): Path {
val path = Paths.get(location.path)
return path.parent?.relativize(Paths.get(root.path + '/')) ?: path
}
diff --git a/core/src/main/kotlin/Formats/OutlineService.kt b/core/src/main/kotlin/Formats/OutlineService.kt
index 3c31ba57f..42151ffbb 100644
--- a/core/src/main/kotlin/Formats/OutlineService.kt
+++ b/core/src/main/kotlin/Formats/OutlineService.kt
@@ -6,8 +6,8 @@ import java.io.File
* Service for building the outline of the package contents.
*/
interface OutlineFormatService {
- fun getOutlineFileName(location: Location): File
-
+ fun getOutlineFile(location: Location): File
+ fun getOutlineFileName(): String
fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder)
fun appendOutlineLevel(to: StringBuilder, body: () -> Unit)
diff --git a/core/src/main/kotlin/Formats/StandardFormats.kt b/core/src/main/kotlin/Formats/StandardFormats.kt
index fad65ff1f..cc96b22a9 100644
--- a/core/src/main/kotlin/Formats/StandardFormats.kt
+++ b/core/src/main/kotlin/Formats/StandardFormats.kt
@@ -10,10 +10,11 @@ abstract class KotlinFormatDescriptorBase : FormatDescriptor {
override val packageDocumentationBuilderClass = KotlinPackageDocumentationBuilder::class
override val javaDocumentationBuilderClass = KotlinJavaDocumentationBuilder::class
- override val generatorServiceClass = FileGenerator::class
+ override val generatorServiceClass: KClass<out Generator> = FileGenerator::class
override val outlineServiceClass: KClass<out OutlineFormatService>? = null
override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class
override val packageListServiceClass: KClass<out PackageListService>? = DefaultPackageListService::class
+ override val extraOutlineServices: KClass<out ExtraOutlineServices>? = null
}
class HtmlFormatDescriptor : KotlinFormatDescriptorBase() {
@@ -29,6 +30,7 @@ class HtmlAsJavaFormatDescriptor : FormatDescriptor {
override val javaDocumentationBuilderClass = JavaPsiDocumentationBuilder::class
override val sampleProcessingService: KClass<out SampleProcessingService> = DefaultSampleProcessingService::class
override val packageListServiceClass: KClass<out PackageListService>? = DefaultPackageListService::class
+ override val extraOutlineServices: KClass<out ExtraOutlineServices>? = null
}
class KotlinWebsiteFormatDescriptor : KotlinFormatDescriptorBase() {
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index a8b000b7b..63f51f958 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -286,7 +286,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
singleNode.appendPlatforms()
appendContent(singleNode.content)
} else {
- val breakdownByName = nodes.groupBy { node -> node.name }
+ val breakdownByName = nodes.groupBy { node -> getNameForHeader(node) }
for ((name, items) in breakdownByName) {
if (!noHeader)
appendHeader { appendText(name) }
@@ -295,7 +295,11 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- private fun appendDocumentation(overloads: Iterable<DocumentationNode>, isSingleNode: Boolean) {
+ open fun getNameForHeader(node: DocumentationNode): String {
+ return node.name
+ }
+
+ fun appendDocumentation(overloads: Iterable<DocumentationNode>, isSingleNode: Boolean) {
val breakdownBySummary = overloads.groupByTo(LinkedHashMap()) { node -> node.content }
if (breakdownBySummary.size == 1) {
@@ -311,7 +315,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- private fun formatOverloadGroup(items: List<DocumentationNode>, isSingleNode: Boolean = false) {
+ fun formatOverloadGroup(items: List<DocumentationNode>, isSingleNode: Boolean = false) {
for ((index, item) in items.withIndex()) {
if (index > 0) appendLine()
val rendered = languageService.render(item)
@@ -377,7 +381,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- private fun DocumentationNode.appendPlatforms() {
+ fun DocumentationNode.appendPlatforms() {
val platforms = if (isModuleOrPackage())
platformsToShow.toSet() + platformsOfItems(members)
else
@@ -437,7 +441,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- inner class GroupNodePageBuilder(val node: DocumentationNode) : PageBuilder(listOf(node)) {
+ open inner class GroupNodePageBuilder(val node: DocumentationNode) : PageBuilder(listOf(node)) {
override fun build() {
val breakdownByLocation = node.path.filterNot { it.name.isEmpty() }.map { link(node, it) }
@@ -467,7 +471,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- inner class SingleNodePageBuilder(val node: DocumentationNode, noHeader: Boolean = false)
+ open inner class SingleNodePageBuilder(val node: DocumentationNode, noHeader: Boolean = false)
: PageBuilder(listOf(node), noHeader) {
override fun build() {
@@ -612,7 +616,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
- inner class AllTypesNodeBuilder(val node: DocumentationNode)
+ open inner class AllTypesNodeBuilder(val node: DocumentationNode)
: PageBuilder(listOf(node)) {
override fun build() {
diff --git a/core/src/main/kotlin/Formats/YamlOutlineService.kt b/core/src/main/kotlin/Formats/YamlOutlineService.kt
index 7968824cd..39a5b9b3a 100644
--- a/core/src/main/kotlin/Formats/YamlOutlineService.kt
+++ b/core/src/main/kotlin/Formats/YamlOutlineService.kt
@@ -5,7 +5,7 @@ import java.io.File
class YamlOutlineService @Inject constructor(val locationService: LocationService,
val languageService: LanguageService) : OutlineFormatService {
- override fun getOutlineFileName(location: Location): File = File("${location.path}.yml")
+ override fun getOutlineFile(location: Location): File = File("${location.path}.yml")
var outlineLevel = 0
override fun appendOutlineHeader(location: Location, node: DocumentationNode, to: StringBuilder) {
@@ -21,4 +21,6 @@ class YamlOutlineService @Inject constructor(val locationService: LocationServic
body()
outlineLevel--
}
+
+ override fun getOutlineFileName(): String = "index"
}