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 +++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') 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("") } -- cgit From 4591cbccbe3bd0afb9c89471c4753a7be80818d0 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 16 Jan 2015 18:45:55 +0100 Subject: use same code for calculating page titles in HTML and Jekyll --- src/Formats/HtmlFormatService.kt | 34 +++++++++++++++++++--------------- src/Formats/JekyllFormatService.kt | 2 +- 2 files changed, 20 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/Formats/HtmlFormatService.kt b/src/Formats/HtmlFormatService.kt index a50f2c8b..1ae6a81b 100644 --- a/src/Formats/HtmlFormatService.kt +++ b/src/Formats/HtmlFormatService.kt @@ -9,12 +9,15 @@ public open class HtmlFormatService(locationService: LocationService, override public fun formatText(text: String): String { return text.htmlEscape() } + override fun formatSymbol(text: String): String { return "${formatText(text)}" } + override fun formatKeyword(text: String): String { return "${formatText(text)}" } + override fun formatIdentifier(text: String): String { return "${formatText(text)}" } @@ -122,23 +125,24 @@ public open class HtmlFormatService(locationService: LocationService, override fun appendOutlineChildren(to: StringBuilder, nodes: Iterable) { } + override fun appendOutlineHeader(to: StringBuilder, node: DocumentationNode) { } +} - fun getPageTitle(nodes: Iterable): String? { - val breakdownByLocation = nodes.groupBy { node -> formatPageTitle(node) } - return breakdownByLocation.keySet().singleOrNull() - } +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 +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" } -} \ No newline at end of file + return path.first().name + " / " + qualifiedName +} diff --git a/src/Formats/JekyllFormatService.kt b/src/Formats/JekyllFormatService.kt index 93861113..93ba4704 100644 --- a/src/Formats/JekyllFormatService.kt +++ b/src/Formats/JekyllFormatService.kt @@ -15,6 +15,6 @@ public open class JekyllFormatService(locationService: LocationService, } protected open fun appendFrontMatter(nodes: Iterable, to: StringBuilder) { - to.appendln("title: ${nodes.first().name}") + to.appendln("title: ${getPageTitle(nodes)}") } } \ No newline at end of file -- cgit