diff --git a/src/main/kotlin/net/shadowfacts/ekt/EKT.kt b/src/main/kotlin/net/shadowfacts/ekt/EKT.kt index 80c1a07..93b1c1e 100644 --- a/src/main/kotlin/net/shadowfacts/ekt/EKT.kt +++ b/src/main/kotlin/net/shadowfacts/ekt/EKT.kt @@ -3,6 +3,7 @@ package net.shadowfacts.ekt import java.io.File import javax.script.ScriptContext import javax.script.ScriptEngineManager +import javax.script.SimpleScriptContext /** * @author shadowfacts @@ -35,6 +36,10 @@ _result.toString() ScriptEngineManager() } + private val engine by lazy { + manager.getEngineByExtension("kts") + } + fun render(template: String, dumpGeneratedScript: File? = null, dataProvider: DataProviderContext.() -> Unit): String { @Suppress("NAME_SHADOWING") var template = template @@ -75,7 +80,7 @@ _result.toString() } internal fun eval(script: String, data: Map = mapOf()): Any? { - val engine = manager.getEngineByExtension("kts") + engine.context = SimpleScriptContext() val bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE) bindings.putAll(data)