visionforge/demo/playground/src/jvmMain/kotlin/serverExtensions.kt

45 lines
1.6 KiB
Kotlin
Raw Normal View History

2021-03-07 16:19:43 +03:00
package space.kscience.visionforge.examples
2021-01-12 12:52:22 +03:00
2021-05-05 15:28:06 +03:00
import space.kscience.dataforge.context.Context
2021-03-07 16:19:43 +03:00
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.visionforge.html.ResourceLocation
2021-05-05 15:28:06 +03:00
import space.kscience.visionforge.html.VisionTagConsumer
2021-03-07 16:19:43 +03:00
import space.kscience.visionforge.html.page
import space.kscience.visionforge.html.scriptHeader
import space.kscience.visionforge.makeFile
import space.kscience.visionforge.three.server.VisionServer
import space.kscience.visionforge.three.server.useScript
2022-01-02 14:28:24 +03:00
import space.kscience.visionforge.visionManager
2021-01-12 12:52:22 +03:00
import java.awt.Desktop
import java.nio.file.Path
public fun VisionServer.usePlayground(): Unit {
useScript("js/visionforge-playground.js")
}
2021-05-05 15:28:06 +03:00
@OptIn(DFExperimental::class)
public fun Context.makeVisionFile(
2021-01-12 12:52:22 +03:00
path: Path? = null,
title: String = "VisionForge page",
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true,
2022-01-07 12:29:43 +03:00
content: VisionTagConsumer<*>.() -> Unit,
2021-01-12 12:52:22 +03:00
): Unit {
2022-01-02 14:28:24 +03:00
val actualPath = visionManager.page(title, content = content).makeFile(path) { actualPath ->
2022-01-07 12:29:43 +03:00
mapOf(
"playground" to scriptHeader("js/visionforge-playground.js", resourceLocation, actualPath),
)
2021-01-12 12:52:22 +03:00
}
if (show) Desktop.getDesktop().browse(actualPath.toFile().toURI())
}
2021-02-24 18:26:15 +03:00
2021-05-05 15:28:06 +03:00
//@DFExperimental
//public fun Context.makeVisionFile(
// vision: Vision,
// path: Path? = null,
// title: String = "VisionForge page",
// resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
// show: Boolean = true,
//): Unit = makeVisionFile({ vision(vision) }, path, title, resourceLocation, show)