Skip to content

Commit

Permalink
Get rid of INVISIBLE
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Feb 21, 2023
1 parent 53ef99c commit 24880f3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 41 deletions.
10 changes: 9 additions & 1 deletion plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,19 @@ open class HtmlRenderer(
content(this, page)
}

private fun PageNode.getDocumentableType(): String? =
when(this) {
is PackagePage -> "package"
is ClasslikePage -> "classlike"
is MemberPage -> "member"
else -> null
}

open fun buildHtml(page: PageNode, resources: List<String>, content: FlowContent.() -> Unit): String =
templater.renderFromTemplate(DokkaTemplateTypes.BASE) {
val generatedContent =
createHTML().div("main-content") {
page.getDocumentableType()?.let { attributes["documentable-type"] = it }
id = "content"
(page as? ContentPage)?.let {
attributes["pageIds"] = "${context.configuration.moduleName}::${page.pageId}"
Expand Down Expand Up @@ -989,7 +997,7 @@ private val PageNode.isNavigable: Boolean
get() = this !is RendererSpecificPage || strategy != RenderingStrategy.DoNothing

private fun PropertyContainer<ContentNode>.extraHtmlAttributes() = allOfType<SimpleAttr>()
private fun PropertyContainer<ContentNode>.extraToggleableContentType() = allOfType<TabbedContentTypeExtra>().lastOrNull()
private fun PropertyContainer<ContentNode>.extraToggleableContentType() = this[TabbedContentTypeExtra]

private val ContentNode.sourceSetsFilters: String
get() = sourceSets.sourceSetIDs.joinToString(" ") { it.toString() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,31 +311,27 @@ open class DefaultPageCreator(
"Properties",
BasicTabbedContentType.PROPERTY,
memberProperties + extensionProperties,
sourceSets,
isVisibleHeader = isClasslike
sourceSets
)
propertiesBlock(
"Inherited properties",
BasicTabbedContentType.PROPERTY,
inheritedProperties + inheritedExtensionProperties,
sourceSets,
isVisibleHeader = isClasslike
sourceSets
)
functionsBlock("Functions", BasicTabbedContentType.FUNCTION, memberFunctions + extensionFunctions, isVisibleHeader = isClasslike)
functionsBlock("Functions", BasicTabbedContentType.FUNCTION, memberFunctions + extensionFunctions)
functionsBlock(
"Inherited functions",
BasicTabbedContentType.FUNCTION,
inheritedFunctions + inheritedExtensionFunctions,
isVisibleHeader = isClasslike
inheritedFunctions + inheritedExtensionFunctions
)
} else {
functionsBlock("Functions", BasicTabbedContentType.FUNCTION, functions + extensionFuns, isVisibleHeader = isClasslike)
functionsBlock("Functions", BasicTabbedContentType.FUNCTION, functions + extensionFuns)
propertiesBlock(
"Properties",
BasicTabbedContentType.PROPERTY,
properties + extensionProps,
sourceSets,
isVisibleHeader = isClasslike
sourceSets
)
}
}
Expand Down Expand Up @@ -435,7 +431,6 @@ open class DefaultPageCreator(
needsSorting = false,
needsAnchors = true,
extra = mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.ENTRY),
headerExtra = mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.ENTRY),
styles = emptySet()
) { key, ds ->
link(key, ds.first().dri)
Expand Down Expand Up @@ -542,34 +537,22 @@ open class DefaultPageCreator(
private fun DocumentableContentBuilder.functionsBlock(
name: String,
tabbedContentType: TabbedContentType,
list: Collection<DFunction>,
isVisibleHeader: Boolean = false
list: Collection<DFunction>
) {
val onlyExtensions = list.all { it.isExtension() }
val headerExtra =
when {
// corner case: when we have only extensions, the header should be only for EXTENSION
onlyExtensions && isVisibleHeader -> mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.EXTENSION)
isVisibleHeader -> mainExtra
!isVisibleHeader -> mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.INVISIBLE)
else -> throw IllegalStateException()
}

divergentBlock(
name,
list.sorted(),
ContentKind.Functions,
extra = mainExtra + TabbedContentTypeExtra(tabbedContentType),
headerExtra = headerExtra
extra = mainExtra + TabbedContentTypeExtra(if (onlyExtensions) BasicTabbedContentType.EXTENSION else tabbedContentType)
)
}

private fun DocumentableContentBuilder.propertiesBlock(
name: String,
tabbedContentType: TabbedContentType,
list: Collection<DProperty>,
sourceSets: Set<DokkaSourceSet>,
isVisibleHeader: Boolean = false
sourceSets: Set<DokkaSourceSet>
) {
data class NameAndIsExtension(val name:String, val isExtension: Boolean)

Expand All @@ -578,27 +561,17 @@ open class DefaultPageCreator(
groupedElements.sortedWith(compareBy<Pair<NameAndIsExtension, List<DProperty>>, String>(String.CASE_INSENSITIVE_ORDER) { it.first.name }.thenBy { it.first.isExtension })

val onlyExtensions = list.all { it.isExtension() }
val headerExtra =
when {
// corner case: when we have only extensions, the header should be only for EXTENSION
onlyExtensions && isVisibleHeader -> mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.EXTENSION)
isVisibleHeader -> mainExtra
!isVisibleHeader -> mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.INVISIBLE)
else -> throw IllegalStateException()
}

multiBlock(
name,
2,
ContentKind.Properties,
sortedGroupedElements.map { it.first.name to it.second },
sourceSets,
needsAnchors = true,
extra = mainExtra + TabbedContentTypeExtra(tabbedContentType),
extra = mainExtra + TabbedContentTypeExtra(if(onlyExtensions) BasicTabbedContentType.EXTENSION else tabbedContentType),
headers = listOf(
headers("Name", "Summary")
),
headerExtra = headerExtra,
)
) { key, props ->
val extra =
if (props.all { it.isExtension() }) mainExtra + TabbedContentTypeExtra(BasicTabbedContentType.EXTENSION) else mainExtra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,12 @@ open class PageContentBuilder(
needsSorting: Boolean = true,
headers: List<ContentGroup> = emptyList(),
needsAnchors: Boolean = false,
headerExtra: PropertyContainer<ContentNode> = extra,
operation: DocumentableContentBuilder.(String, List<Documentable>) -> Unit
) {

if (renderWhenEmpty || groupedElements.any()) {
group(extra = extra) {
header(level, name, kind = kind, extra = headerExtra) { }
header(level, name, kind = kind) { }
contents += ContentTable(
header = headers,
children = groupedElements
Expand Down
5 changes: 5 additions & 0 deletions plugins/base/src/main/resources/dokka/styles/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,8 @@ div.runnablesample {
.floating-right {
float: right;
}

// the hack to hide the headers inside tabs for a package page
.main-content[documentable-type="package"] .tabs-section-body > h2 {
display: none;
}

0 comments on commit 24880f3

Please sign in to comment.