From 7c17e3e80103a825ecf615c82167e81c67a94795 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 7 Aug 2017 17:22:43 -0400 Subject: [PATCH] Move bindings unwrapping to eval and re-enable caching for includes --- src/main/kotlin/net/shadowfacts/ekt/EKT.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/net/shadowfacts/ekt/EKT.kt b/src/main/kotlin/net/shadowfacts/ekt/EKT.kt index 1a8a1e6..426a891 100644 --- a/src/main/kotlin/net/shadowfacts/ekt/EKT.kt +++ b/src/main/kotlin/net/shadowfacts/ekt/EKT.kt @@ -29,7 +29,7 @@ val _env = bindings["_env"] as net.shadowfacts.ekt.EKT.TemplateEnvironment val _result = StringBuilder() fun echo(it: Any) { _result.append(it) } fun include(include: String) { - val env = net.shadowfacts.ekt.EKT.TemplateEnvironment(include, _env, cacheDir = null) + val env = net.shadowfacts.ekt.EKT.TemplateEnvironment(include, _env) echo(net.shadowfacts.ekt.EKT.render(env, env.include)) } """ @@ -67,13 +67,7 @@ _result.toString() } }) -// Hack to allow data to be accessed by name from template instead of via bindings map - val unwrapBindings = env.data.keys.map { - val type = env.data[it]!!.type - "val $it = (bindings[\"$it\"] as net.shadowfacts.ekt.EKT.TypedValue).value as $type" - }.joinToString("\n") - - val script = unwrapBindings + scriptPrefix + template + scriptSuffix + val script = scriptPrefix + template + scriptSuffix if (env.cacheDir != null) { env.cacheFile.apply { @@ -108,6 +102,13 @@ _result.toString() bindings.putAll(env.data) bindings.put("_env", env) +// Hack to allow data to be accessed by name from template instead of via bindings map + val unwrapBindings = env.data.keys.map { + val type = env.data[it]!!.type + "val $it = (bindings[\"$it\"] as net.shadowfacts.ekt.EKT.TypedValue).value as $type" + }.joinToString("\n") + engine.eval(unwrapBindings) + return engine.eval(script) as String }