Skip to content

Commit 6874063

Browse files
committed
Introduce OtherSamples.kt to generate tables for writerside docs outside Korro
1 parent 0ca67a4 commit 6874063

File tree

9 files changed

+128
-65
lines changed

9 files changed

+128
-65
lines changed

core/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ val clearSamplesOutputs by tasks.creating {
136136

137137
doFirst {
138138
delete {
139-
delete(fileTree(File(projectDir, "../docs/StardustDocs/snippets")))
139+
val generatedSnippets = fileTree(file("../docs/StardustDocs/snippets")).exclude("**/manual/**")
140+
delete(generatedSnippets)
140141
}
141142
}
142143
}

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,7 @@ object PluginCallbackProxy : PluginCallback {
7575
var output: DataFrameHtmlData
7676
val manualOutput = this.manualOutput
7777
if (manualOutput == null) {
78-
output = DataFrameHtmlData.tableDefinitions() + DataFrameHtmlData(
79-
// copy writerside stlyles
80-
style = """
81-
body {
82-
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
83-
}
84-
85-
:root {
86-
color: #19191C;
87-
background-color: #fff;
88-
}
89-
90-
:root[theme="dark"] {
91-
background-color: #19191C;
92-
color: #FFFFFFCC
93-
}
94-
95-
details details {
96-
margin-left: 20px;
97-
}
98-
99-
summary {
100-
padding: 6px;
101-
}
102-
""".trimIndent()
103-
)
78+
output = DataFrameHtmlData.tableDefinitions() + WritersideStyle
10479

10580
// make copy to avoid concurrent modification exception
10681
val statements = expressionsByStatement.toMap()
@@ -243,7 +218,7 @@ object PluginCallbackProxy : PluginCallback {
243218
}
244219

245220
private fun convertToHTML(dataframeLike: Any): DataFrameHtmlData {
246-
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = { "" })
221+
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = WritersideFooter)
247222
fun FormattedFrame<*>.toHTML1() = toHTML(SamplesDisplayConfiguration)
248223

249224
return when (dataframeLike) {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesDisplayConfiguration.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.jetbrains.kotlinx.dataframe.explainer
2+
3+
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
5+
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
6+
7+
val SamplesDisplayConfiguration = DisplayConfiguration(enableFallbackStaticTables = false)
8+
9+
val WritersideStyle = DataFrameHtmlData(
10+
// copy writerside stlyles
11+
style = """
12+
body {
13+
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
14+
}
15+
16+
:root {
17+
color: #19191C;
18+
background-color: #fff;
19+
}
20+
21+
:root[theme="dark"] {
22+
background-color: #19191C;
23+
color: #FFFFFFCC
24+
}
25+
26+
details details {
27+
margin-left: 20px;
28+
}
29+
30+
summary {
31+
padding: 6px;
32+
}
33+
""".trimIndent()
34+
)
35+
36+
val WritersideFooter: (DataFrame<*>) -> String = { "" }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.jetbrains.kotlinx.dataframe.samples.api
2+
3+
import org.jetbrains.kotlinx.dataframe.AnyFrame
4+
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
5+
import org.jetbrains.kotlinx.dataframe.explainer.WritersideFooter
6+
import org.jetbrains.kotlinx.dataframe.explainer.WritersideStyle
7+
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
8+
import org.junit.Test
9+
import java.io.File
10+
11+
// To display code together with a table, we can use TransformDataFrameExpressions annotation together with korro
12+
// This class provides an ability to save only a table that can be embedded anywhere in the documentation
13+
class OtherSamples {
14+
@Test
15+
fun extensionPropertiesApi1() {
16+
val df = dataFrameOf("example")(123)
17+
writeTable(df, "extensionPropertiesApi1")
18+
}
19+
20+
private fun writeTable(df: AnyFrame, name: String) {
21+
val dir = File("../docs/StardustDocs/snippets/manual").also { it.mkdirs() }
22+
val html = df.toStandaloneHTML(getFooter = WritersideFooter) + WritersideStyle
23+
html.writeHTML(File(dir, "$name.html"))
24+
}
25+
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/PluginCallbackProxy.kt

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,7 @@ object PluginCallbackProxy : PluginCallback {
7575
var output: DataFrameHtmlData
7676
val manualOutput = this.manualOutput
7777
if (manualOutput == null) {
78-
output = DataFrameHtmlData.tableDefinitions() + DataFrameHtmlData(
79-
// copy writerside stlyles
80-
style = """
81-
body {
82-
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
83-
}
84-
85-
:root {
86-
color: #19191C;
87-
background-color: #fff;
88-
}
89-
90-
:root[theme="dark"] {
91-
background-color: #19191C;
92-
color: #FFFFFFCC
93-
}
94-
95-
details details {
96-
margin-left: 20px;
97-
}
98-
99-
summary {
100-
padding: 6px;
101-
}
102-
""".trimIndent()
103-
)
78+
output = DataFrameHtmlData.tableDefinitions() + WritersideStyle
10479

10580
// make copy to avoid concurrent modification exception
10681
val statements = expressionsByStatement.toMap()
@@ -243,7 +218,7 @@ object PluginCallbackProxy : PluginCallback {
243218
}
244219

245220
private fun convertToHTML(dataframeLike: Any): DataFrameHtmlData {
246-
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = { "" })
221+
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = WritersideFooter)
247222
fun FormattedFrame<*>.toHTML1() = toHTML(SamplesDisplayConfiguration)
248223

249224
return when (dataframeLike) {

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/explainer/SamplesDisplayConfiguration.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.jetbrains.kotlinx.dataframe.explainer
2+
3+
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
5+
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
6+
7+
val SamplesDisplayConfiguration = DisplayConfiguration(enableFallbackStaticTables = false)
8+
9+
val WritersideStyle = DataFrameHtmlData(
10+
// copy writerside stlyles
11+
style = """
12+
body {
13+
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
14+
}
15+
16+
:root {
17+
color: #19191C;
18+
background-color: #fff;
19+
}
20+
21+
:root[theme="dark"] {
22+
background-color: #19191C;
23+
color: #FFFFFFCC
24+
}
25+
26+
details details {
27+
margin-left: 20px;
28+
}
29+
30+
summary {
31+
padding: 6px;
32+
}
33+
""".trimIndent()
34+
)
35+
36+
val WritersideFooter: (DataFrame<*>) -> String = { "" }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.jetbrains.kotlinx.dataframe.samples.api
2+
3+
import org.jetbrains.kotlinx.dataframe.AnyFrame
4+
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
5+
import org.jetbrains.kotlinx.dataframe.explainer.WritersideFooter
6+
import org.jetbrains.kotlinx.dataframe.explainer.WritersideStyle
7+
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
8+
import org.junit.Test
9+
import java.io.File
10+
11+
// To display code together with a table, we can use TransformDataFrameExpressions annotation together with korro
12+
// This class provides an ability to save only a table that can be embedded anywhere in the documentation
13+
class OtherSamples {
14+
@Test
15+
fun extensionPropertiesApi1() {
16+
val df = dataFrameOf("example")(123)
17+
writeTable(df, "extensionPropertiesApi1")
18+
}
19+
20+
private fun writeTable(df: AnyFrame, name: String) {
21+
val dir = File("../docs/StardustDocs/snippets/manual").also { it.mkdirs() }
22+
val html = df.toStandaloneHTML(getFooter = WritersideFooter) + WritersideStyle
23+
html.writeHTML(File(dir, "$name.html"))
24+
}
25+
}

0 commit comments

Comments
 (0)