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

36 lines
1.3 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
import space.kscience.dataforge.context.Global
import space.kscience.visionforge.html.HtmlVisionFragment
import space.kscience.visionforge.html.Page
2021-03-07 16:19:43 +03:00
import space.kscience.visionforge.html.ResourceLocation
import space.kscience.visionforge.html.importScriptHeader
2021-03-07 16:19:43 +03:00
import space.kscience.visionforge.makeFile
2021-01-12 12:52:22 +03:00
import java.awt.Desktop
import java.nio.file.Path
public fun makeVisionFile(
2021-01-12 12:52:22 +03:00
path: Path? = null,
title: String = "VisionForge page",
resourceLocation: ResourceLocation = ResourceLocation.SYSTEM,
show: Boolean = true,
content: HtmlVisionFragment,
2021-01-12 12:52:22 +03:00
): Unit {
val actualPath = Page(Global, content = content).makeFile(path) { actualPath ->
2022-01-07 12:29:43 +03:00
mapOf(
"title" to Page.title(title),
"playground" to Page.importScriptHeader("js/visionforge-playground.js", resourceLocation, actualPath),
2022-01-07 12:29:43 +03:00
)
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)