aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilip Zybała <fzybala@virtuslab.com>2020-03-26 17:17:17 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-03-31 14:45:37 +0200
commitc29d660242027eb23ff9c5d7c176eb188abcef74 (patch)
treee1189c600012f98f93815ee196f0e21498c50c7a
parenta8f8ac319de698528c04db9ebeceb986a8ced7f0 (diff)
downloaddokka-c29d660242027eb23ff9c5d7c176eb188abcef74.tar.gz
dokka-c29d660242027eb23ff9c5d7c176eb188abcef74.tar.bz2
dokka-c29d660242027eb23ff9c5d7c176eb188abcef74.zip
Added platformTags rendering. Provided simple css classes. TODO adjust css, add onHover
-rw-r--r--core/src/main/kotlin/pages/ContentNodes.kt9
-rw-r--r--core/src/main/resources/dokka/styles/style.css73
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt36
-rw-r--r--plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt46
4 files changed, 140 insertions, 24 deletions
diff --git a/core/src/main/kotlin/pages/ContentNodes.kt b/core/src/main/kotlin/pages/ContentNodes.kt
index 46a71bc0..03014530 100644
--- a/core/src/main/kotlin/pages/ContentNodes.kt
+++ b/core/src/main/kotlin/pages/ContentNodes.kt
@@ -167,7 +167,14 @@ interface Style
interface Kind
enum class ContentKind : Kind {
- Comment, Constructors, Functions, Parameters, Properties, Classlikes, Packages, Symbol, Sample, Main, BriefComment, Empty
+ Comment, Constructors, Functions, Parameters, Properties, Classlikes, Packages, Symbol, Sample, Main, BriefComment, Empty;
+
+ companion object{
+ fun shouldBePlatformTagged(kind: Kind) : Boolean {
+ val platformTagged = listOf(Constructors, Functions, Parameters, Properties, Classlikes, Packages)
+ return platformTagged.contains(kind)
+ }
+ }
}
enum class TextStyle : Style {
diff --git a/core/src/main/resources/dokka/styles/style.css b/core/src/main/resources/dokka/styles/style.css
index 46a78467..1fa74ca4 100644
--- a/core/src/main/resources/dokka/styles/style.css
+++ b/core/src/main/resources/dokka/styles/style.css
@@ -348,6 +348,79 @@ footer {
bottom: 50px;
}
+.platform-tagged {
+ flex: auto;
+ display: flex;
+ flex-direction: row-reverse;
+ padding: 0px;
+}
+
+.platform-tag {
+ display: flex;
+ justify-content: center;
+ flex-direction: row;
+ padding: 4px 8px;
+
+ width: 67px;
+ height: 24px;
+ right: 0px;
+ top: 0px;
+
+ background: #F4F4F4;
+ border-radius: 100px;
+
+ flex: none;
+ order: 0
+ align--self: end;
+}
+
+.platform-tagged > .platform-tag {
+ align-self: center;
+}
+
+.platform-tag.jvm {
+ border: crimson;
+ border-style: solid;
+ border-width: 1px;
+ border-color: crimson;
+ background-color: crimson;
+ color: white;
+}
+
+.platform-tag.js {
+ border: orange;
+ border-style: solid;
+ border-width: 1px;
+ border-color: orange;
+ background-color: orange;
+ color: white;
+}
+
+.platform-tag.native {
+ border: blue;
+ border-style: solid;
+ border-width: 1px;
+ border-color: blue;
+ background-color: blue;
+ color: white;
+}
+
+.platform-tag.common {
+ border: gray;
+ border-style: solid;
+ border-width: 1px;
+ border-color: gray;
+ color: gray;
+ background-color: gray;
+ color: white;
+}
+
+.platform-tagged > .content {
+ display: block;
+
+ flex: auto;
+}
+
@media print, screen and (max-width: 960px) {
div.wrapper {
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 53222325..439a8fbe 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -27,6 +27,7 @@ open class HtmlRenderer(
) {
val additionalClasses = node.style.joinToString(" ") { it.toString().toLowerCase() }
return when {
+ ContentKind.shouldBePlatformTagged(node.dci.kind) -> wrapPlatformTagged(node, pageContext) { childrenCallback() }
node.dci.kind == ContentKind.Symbol -> div("symbol $additionalClasses") { childrenCallback() }
node.dci.kind == ContentKind.BriefComment -> div("brief $additionalClasses") { childrenCallback() }
node.style.contains(TextStyle.Paragraph) -> p(additionalClasses) { childrenCallback() }
@@ -35,6 +36,23 @@ open class HtmlRenderer(
}
}
+ private fun FlowContent.wrapPlatformTagged(
+ node: ContentGroup,
+ pageContext: ContentPage,
+ childrenCallback: FlowContent.() -> Unit
+ ) {
+ div("platform-tagged"){
+ node.platforms.forEach {
+ div("platform-tag ${it.platformType.name}"){
+ text(it.platformType.key.toUpperCase())
+ }
+ }
+ div("content"){
+ childrenCallback()
+ }
+ }
+ }
+
override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) {
val distinct = content.platforms.map {
it to createHTML(prettyPrint = false).div {
@@ -97,6 +115,22 @@ open class HtmlRenderer(
}
}
+ private fun TR.buildPlatformTags(
+ node: ContentGroup
+ ) {
+ if(ContentKind.shouldBePlatformTagged(node.dci.kind)) {
+ td {
+ div("platform-tagged"){
+ node.platforms.forEach {
+ div(("platform-tag ${it.platformType.key}")) {
+ text(it.platformType.key.toUpperCase())
+ }
+ }
+ }
+ }
+ }
+ }
+
override fun FlowContent.buildTable(
node: ContentTable,
pageContext: ContentPage,
@@ -122,12 +156,14 @@ open class HtmlRenderer(
it.build(this, pageContext, platformRestriction)
}
}
+ buildPlatformTags(it)
}
}
}
}
}
+
override fun FlowContent.buildHeader(level: Int, content: FlowContent.() -> Unit) {
when (level) {
1 -> h1(block = content)
diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
index 11f57696..349d9970 100644
--- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
+++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt
@@ -63,7 +63,9 @@ open class DefaultPageCreator(
}
protected open fun contentForPackage(p: DPackage) = contentBuilder.contentFor(p) {
- header(1) { text("Package ${p.name}") }
+ group(p.dri, p.platformData.toSet(), ContentKind.Packages){
+ header(1) { text("Package ${p.name}") }
+ }
+contentForScope(p, p.dri, p.platformData)
}
@@ -99,6 +101,7 @@ open class DefaultPageCreator(
platformDependentHint(it.dri, it.platformData.toSet()) {
+buildSignature(it)
}
+ breakLine()
group(kind = ContentKind.BriefComment) {
text(it.briefDocumentation())
}
@@ -124,11 +127,12 @@ open class DefaultPageCreator(
}
protected open fun contentForClasslike(c: DClasslike) = contentBuilder.contentFor(c) {
- header(1) { text(c.name.orEmpty()) }
- platformDependentHint(c.dri, c.platformData.toSet()) {
- +buildSignature(c)
+ group(c.dri, c.platformData.toSet(), ContentKind.Classlikes){
+ header(1) { text(c.name.orEmpty()) }
+ platformDependentHint(c.dri, c.platformData.toSet()) {
+ +buildSignature(c)
+ }
}
- breakLine()
+contentForComments(c) { it !is Property }
if (c is WithConstructors) {
@@ -140,26 +144,20 @@ open class DefaultPageCreator(
c.platformData.toSet()
) {
link(it.name, it.dri)
- group {
- platformDependentHint(it.dri, it.platformData.toSet()) {
- +buildSignature(it)
- }
- group(kind = ContentKind.BriefComment) {
- text(it.briefDocumentation())
- }
+ platformDependentHint(it.dri, it.platformData.toSet()) {
+ +buildSignature(it)
+ }
+ group(kind = ContentKind.BriefComment) {
+ text(it.briefDocumentation())
}
}
}
if (c is DEnum) {
- block(
- "Entries", 2, ContentKind.Classlikes, c.entries, c.platformData.toSet()
- ) {
+ block("Entries", 2, ContentKind.Classlikes, c.entries, c.platformData.toSet()) {
link(it.name.orEmpty(), it.dri)
- group {
- +buildSignature(it)
- group(kind = ContentKind.BriefComment) {
- text(it.briefDocumentation())
- }
+ +buildSignature(it)
+ group(kind = ContentKind.BriefComment) {
+ text(it.briefDocumentation())
}
}
}
@@ -196,9 +194,11 @@ open class DefaultPageCreator(
}.children
protected open fun contentForFunction(f: DFunction) = contentBuilder.contentFor(f) {
- header(1) { text(f.name) }
- platformDependentHint(f.dri, f.platformData.toSet()) {
- +buildSignature(f)
+ group(f.dri, f.platformData.toSet(), ContentKind.Functions) {
+ header(1) { text(f.name) }
+ platformDependentHint(f.dri, f.platformData.toSet()) {
+ +buildSignature(f)
+ }
}
+contentForComments(f)
}