mirror of https://github.com/shadowfacts/ekt.git
Add method for passing objects with generic type params
This commit is contained in:
parent
640aed6d5d
commit
86de475391
|
@ -78,12 +78,20 @@ _result.toString()
|
||||||
|
|
||||||
// Hack to allow data to be accessed by name from template instead of via bindings map
|
// Hack to allow data to be accessed by name from template instead of via bindings map
|
||||||
val unwrapBindings = data.keys.map {
|
val unwrapBindings = data.keys.map {
|
||||||
val type = data[it]!!::class.qualifiedName
|
val value = data[it]!!
|
||||||
"val $it = bindings[\"$it\"] as $type;"
|
if (value is Value) {
|
||||||
|
val type = value.type
|
||||||
|
"val $it = (bindings[\"$it\"] as net.shadowfacts.ekt.EKT.Value).value as $type"
|
||||||
|
} else {
|
||||||
|
val type = value::class.qualifiedName
|
||||||
|
"val $it = bindings[\"$it\"] as $type"
|
||||||
|
}
|
||||||
}.joinToString("\n")
|
}.joinToString("\n")
|
||||||
engine.eval(unwrapBindings)
|
engine.eval(unwrapBindings)
|
||||||
|
|
||||||
return engine.eval(script)
|
return engine.eval(script)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class Value(val value: Any, val type: String)
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,9 +7,7 @@ import java.io.File
|
||||||
*/
|
*/
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val res = EKT.render(File("template.ekt"), mapOf(
|
val res = EKT.render(File("template.ekt"), mapOf(
|
||||||
"title" to "EKT Test",
|
"list" to EKT.Value(listOf(1, 2, 3), "List<String>")
|
||||||
"body" to "some test content",
|
|
||||||
"value" to 42
|
|
||||||
), dumpGeneratedScript = File("script.kts"))
|
), dumpGeneratedScript = File("script.kts"))
|
||||||
|
|
||||||
File("result.txt").apply {
|
File("result.txt").apply {
|
||||||
|
|
Loading…
Reference in New Issue