Skip to content

Introduce OtherSamples.kt to generate tables for writerside docs outside Korro #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ val clearSamplesOutputs by tasks.creating {

doFirst {
delete {
delete(fileTree(File(projectDir, "../docs/StardustDocs/snippets")))
val generatedSnippets = fileTree(file("../docs/StardustDocs/snippets")).exclude("**/manual/**")
delete(generatedSnippets)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,7 @@ object PluginCallbackProxy : PluginCallback {
var output: DataFrameHtmlData
val manualOutput = this.manualOutput
if (manualOutput == null) {
output = DataFrameHtmlData.tableDefinitions() + DataFrameHtmlData(
// copy writerside stlyles
style = """
body {
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
}

:root {
color: #19191C;
background-color: #fff;
}

:root[theme="dark"] {
background-color: #19191C;
color: #FFFFFFCC
}

details details {
margin-left: 20px;
}

summary {
padding: 6px;
}
""".trimIndent()
)
output = DataFrameHtmlData.tableDefinitions() + WritersideStyle

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

private fun convertToHTML(dataframeLike: Any): DataFrameHtmlData {
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = { "" })
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = WritersideFooter)
fun FormattedFrame<*>.toHTML1() = toHTML(SamplesDisplayConfiguration)

return when (dataframeLike) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jetbrains.kotlinx.dataframe.explainer

import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration

val SamplesDisplayConfiguration = DisplayConfiguration(enableFallbackStaticTables = false)

val WritersideStyle = DataFrameHtmlData(
// copy writerside stlyles
style = """
body {
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
}

:root {
color: #19191C;
background-color: #fff;
}

:root[theme="dark"] {
background-color: #19191C;
color: #FFFFFFCC
}

details details {
margin-left: 20px;
}

summary {
padding: 6px;
}
""".trimIndent()
)

val WritersideFooter: (DataFrame<*>) -> String = { "" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jetbrains.kotlinx.dataframe.samples.api

import org.jetbrains.kotlinx.dataframe.AnyFrame
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
import org.jetbrains.kotlinx.dataframe.explainer.WritersideFooter
import org.jetbrains.kotlinx.dataframe.explainer.WritersideStyle
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
import org.junit.Test
import java.io.File

// To display code together with a table, we can use TransformDataFrameExpressions annotation together with korro
// This class provides an ability to save only a table that can be embedded anywhere in the documentation
class OtherSamples {
@Test
fun extensionPropertiesApi1() {
val df = dataFrameOf("example")(123)
writeTable(df, "extensionPropertiesApi1")
}

private fun writeTable(df: AnyFrame, name: String) {
val dir = File("../docs/StardustDocs/snippets/manual").also { it.mkdirs() }
val html = df.toStandaloneHTML(getFooter = WritersideFooter) + WritersideStyle
html.writeHTML(File(dir, "$name.html"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,7 @@ object PluginCallbackProxy : PluginCallback {
var output: DataFrameHtmlData
val manualOutput = this.manualOutput
if (manualOutput == null) {
output = DataFrameHtmlData.tableDefinitions() + DataFrameHtmlData(
// copy writerside stlyles
style = """
body {
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
}

:root {
color: #19191C;
background-color: #fff;
}

:root[theme="dark"] {
background-color: #19191C;
color: #FFFFFFCC
}

details details {
margin-left: 20px;
}

summary {
padding: 6px;
}
""".trimIndent()
)
output = DataFrameHtmlData.tableDefinitions() + WritersideStyle

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

private fun convertToHTML(dataframeLike: Any): DataFrameHtmlData {
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = { "" })
fun DataFrame<*>.toHTML() = toHTML(SamplesDisplayConfiguration, getFooter = WritersideFooter)
fun FormattedFrame<*>.toHTML1() = toHTML(SamplesDisplayConfiguration)

return when (dataframeLike) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jetbrains.kotlinx.dataframe.explainer

import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.io.DataFrameHtmlData
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration

val SamplesDisplayConfiguration = DisplayConfiguration(enableFallbackStaticTables = false)

val WritersideStyle = DataFrameHtmlData(
// copy writerside stlyles
style = """
body {
font-family: "JetBrains Mono",SFMono-Regular,Consolas,"Liberation Mono",Menlo,Courier,monospace;
}

:root {
color: #19191C;
background-color: #fff;
}

:root[theme="dark"] {
background-color: #19191C;
color: #FFFFFFCC
}

details details {
margin-left: 20px;
}

summary {
padding: 6px;
}
""".trimIndent()
)

val WritersideFooter: (DataFrame<*>) -> String = { "" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.jetbrains.kotlinx.dataframe.samples.api

import org.jetbrains.kotlinx.dataframe.AnyFrame
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
import org.jetbrains.kotlinx.dataframe.explainer.WritersideFooter
import org.jetbrains.kotlinx.dataframe.explainer.WritersideStyle
import org.jetbrains.kotlinx.dataframe.io.toStandaloneHTML
import org.junit.Test
import java.io.File

// To display code together with a table, we can use TransformDataFrameExpressions annotation together with korro
// This class provides an ability to save only a table that can be embedded anywhere in the documentation
class OtherSamples {
@Test
fun extensionPropertiesApi1() {
val df = dataFrameOf("example")(123)
writeTable(df, "extensionPropertiesApi1")
}

private fun writeTable(df: AnyFrame, name: String) {
val dir = File("../docs/StardustDocs/snippets/manual").also { it.mkdirs() }
val html = df.toStandaloneHTML(getFooter = WritersideFooter) + WritersideStyle
html.writeHTML(File(dir, "$name.html"))
}
}