From 4b75751845b6d63a642cac1017ada30f2549bf14 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 16 Jan 2015 13:04:09 +0100 Subject: generate page titles in HTML output --- src/Formats/HtmlFormatService.kt | 19 ++++++++++++++++++- src/Formats/HtmlTemplateService.kt | 7 +++++-- test/data/format/classWithClassObject.html | 1 + test/data/format/deprecated.package.html | 1 + test/data/format/htmlEscaping.html | 1 + test/data/format/overloads.html | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index f76693dc..a50f2c8b 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -115,7 +115,7 @@ public open class HtmlFormatService(locationService: LocationService, override fun appendNodes(location: Location, to: StringBuilder, nodes: Iterable) { - templateService.appendHeader(to) + templateService.appendHeader(to, getPageTitle(nodes)) super.appendNodes(location, to, nodes) templateService.appendFooter(to) } @@ -124,4 +124,21 @@ public open class HtmlFormatService(locationService: LocationService, } override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { } + + fun getPageTitle(nodes: Iterable): String? { + val breakdownByLocation = nodes.groupBy { node -> formatPageTitle(node) } + return breakdownByLocation.keySet().singleOrNull() + } + + fun formatPageTitle(node: DocumentationNode): String { + val path = node.path + if (path.size() == 1) { + return path.first().name + } + val qualifiedName = path.drop(1).map { it.name }.filter { it.length() > 0 }.join(".") + if (qualifiedName.length() == 0 && path.size() == 2) { + return path.first().name + " / root package" + } + return path.first().name + " / " + qualifiedName + } } \ No newline at end of file diff --git a/src/Formats/HtmlTemplateService.kt b/src/Formats/HtmlTemplateService.kt index 5bb03fbd..54bfa300 100644 --- a/src/Formats/HtmlTemplateService.kt +++ b/src/Formats/HtmlTemplateService.kt @@ -1,7 +1,7 @@ package org.jetbrains.dokka public trait HtmlTemplateService { - fun appendHeader(to: StringBuilder) + fun appendHeader(to: StringBuilder, title: String?) fun appendFooter(to: StringBuilder) class object { @@ -11,9 +11,12 @@ public trait HtmlTemplateService { to.appendln("") to.appendln("") } - override fun appendHeader(to: StringBuilder) { + override fun appendHeader(to: StringBuilder, title: String?) { to.appendln("") to.appendln("") + if (title != null) { + to.appendln("$title") + } if (css != null) { to.appendln("") } diff --git a/test/data/format/classWithClassObject.html b/test/data/format/classWithClassObject.html index 79546418..5ccb5b7e 100644 --- a/test/data/format/classWithClassObject.html +++ b/test/data/format/classWithClassObject.html @@ -1,5 +1,6 @@ +test / Klass test /  / Klass
diff --git a/test/data/format/deprecated.package.html b/test/data/format/deprecated.package.html index cf563a8b..13a5edb2 100644 --- a/test/data/format/deprecated.package.html +++ b/test/data/format/deprecated.package.html @@ -1,5 +1,6 @@ +test / root package test / 
diff --git a/test/data/format/htmlEscaping.html b/test/data/format/htmlEscaping.html index 4f1409c4..0767d642 100644 --- a/test/data/format/htmlEscaping.html +++ b/test/data/format/htmlEscaping.html @@ -1,5 +1,6 @@ +test / x test /  / x
diff --git a/test/data/format/overloads.html b/test/data/format/overloads.html index 9ea88869..92296825 100644 --- a/test/data/format/overloads.html +++ b/test/data/format/overloads.html @@ -1,5 +1,6 @@ +test / root package test / 
-- cgit