Add Kotlin based ScriptTemplateView rendering test
Kotlin JSR 223 support currently requires kotlin-script-util dependency (jcabi-aether, maven-core and aether-api can be excluded since they are only used for live import of dependencies and bring a lot of JARs in the classpath) and a /META-INF/services/javax.script.ScriptEngineFactory file specifying the ScriptEngineFactory to use, in that case org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory. Issue: SPR-15059
This commit is contained in:
@@ -0,0 +1 @@
|
||||
org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory
|
||||
@@ -0,0 +1,10 @@
|
||||
import javax.script.*
|
||||
|
||||
// TODO Use engine.eval(String, Bindings) when https://youtrack.jetbrains.com/issue/KT-15450 will be fixed
|
||||
fun render(template: String, model: Map<String, Any>, url: String): String {
|
||||
val engine = ScriptEngineManager().getEngineByName("kotlin")
|
||||
val bindings = SimpleBindings()
|
||||
bindings.putAll(model)
|
||||
engine.setBindings(bindings, ScriptContext.ENGINE_SCOPE)
|
||||
return engine.eval(template) as String
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
"""<html><head><title>${bindings["title"]}</title></head><body><p>${bindings["body"]}</p></body></html>"""
|
||||
Reference in New Issue
Block a user