bug in PagesFrom
This commit is contained in:
parent
23a736a012
commit
285057fbb0
@ -2,10 +2,7 @@ package space.kscience.snark
|
||||
|
||||
import io.ktor.server.application.call
|
||||
import io.ktor.server.html.respondHtml
|
||||
import io.ktor.server.http.content.*
|
||||
import io.ktor.server.routing.Route
|
||||
import io.ktor.server.routing.get
|
||||
import io.ktor.server.routing.route
|
||||
import space.kscience.dataforge.data.DataTree
|
||||
import space.kscience.dataforge.data.DataTreeItem
|
||||
import space.kscience.dataforge.data.await
|
||||
@ -17,44 +14,45 @@ import space.kscience.dataforge.meta.string
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.dataforge.names.plus
|
||||
import java.nio.file.Path
|
||||
import kotlin.collections.component1
|
||||
import kotlin.collections.component2
|
||||
import kotlin.reflect.typeOf
|
||||
|
||||
internal const val DESIGNATION_KEY = "designation"
|
||||
|
||||
private fun Route.staticFrom(rootMeta: Meta) = static {
|
||||
rootMeta.getIndexed("resource".asName()).forEach { (_, meta) ->
|
||||
val resourcePackage by meta.string()
|
||||
val remotePath by meta.string()
|
||||
val resourceName by meta.string()
|
||||
|
||||
//If remote path provided, use a single resource
|
||||
remotePath?.let {
|
||||
resource(it, resourceName ?: it, resourcePackage)
|
||||
return@forEach
|
||||
}
|
||||
|
||||
//otherwise use package resources
|
||||
resources(resourcePackage)
|
||||
}
|
||||
private fun SnarkRoute.staticFrom(rootMeta: Meta) {
|
||||
// rootMeta.getIndexed("resource".asName()).forEach { (_, meta) ->
|
||||
// val resourcePackage by meta.string()
|
||||
// val remotePath by meta.string()
|
||||
// val resourceName by meta.string()
|
||||
//
|
||||
// //If remote path provided, use a single resource
|
||||
// remotePath?.let {
|
||||
// resource(it, resourceName ?: it, resourcePackage)
|
||||
// return@forEach
|
||||
// }
|
||||
//
|
||||
// //otherwise use package resources
|
||||
// resources(resourcePackage)
|
||||
// }
|
||||
|
||||
rootMeta.getIndexed("file".asName()).forEach { (_, meta) ->
|
||||
val remotePath by meta.string { error("File remote path is not provided") }
|
||||
val path by meta.string { error("File path is not provided") }
|
||||
file(remotePath, path)
|
||||
staticFile(remotePath, Path.of(path))
|
||||
}
|
||||
|
||||
rootMeta.getIndexed("directory".asName()).forEach { (_, meta) ->
|
||||
val path by meta.string { error("Directory path is not provided") }
|
||||
files(path)
|
||||
staticDirectory("", Path.of(path))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represent pages in a [DataTree]
|
||||
*/
|
||||
fun Route.pagesFrom(prefix: Name, data: DataTree<*>) {
|
||||
context(PageContext) fun SnarkRoute.pagesFrom(prefix: Name, data: DataTree<*>) {
|
||||
if (data.meta[DESIGNATION_KEY].string == "page") {
|
||||
TODO("Implement node-based pages")
|
||||
// route(prefix.tokens.joinToString(separator = "/")) {
|
||||
|
Loading…
Reference in New Issue
Block a user