mirror of https://github.com/shadowfacts/ekt.git
Change dumpGeneratedScript to File
This commit is contained in:
parent
d809453101
commit
05279cb254
|
@ -35,7 +35,7 @@ _result.toString()
|
|||
ScriptEngineManager()
|
||||
}
|
||||
|
||||
fun render(template: String, data: Map<String, Any>, dumpGeneratedScript: Boolean = false): String {
|
||||
fun render(template: String, data: Map<String, Any>, dumpGeneratedScript: File? = null): String {
|
||||
@Suppress("NAME_SHADOWING")
|
||||
var template = template
|
||||
template = template.replace("\"", "\\\"").replace("$", "\${'$'}")
|
||||
|
@ -59,17 +59,15 @@ _result.toString()
|
|||
|
||||
val script = scriptPrefix + template + scriptSuffix
|
||||
|
||||
if (dumpGeneratedScript) {
|
||||
File("script.kts").apply {
|
||||
dumpGeneratedScript?.apply {
|
||||
if (!exists()) createNewFile()
|
||||
writeText(script)
|
||||
}
|
||||
}
|
||||
|
||||
return eval(script, data) as String
|
||||
}
|
||||
|
||||
fun render(template: File, data: Map<String, Any>, dumpGeneratedScript: Boolean = false): String {
|
||||
fun render(template: File, data: Map<String, Any>, dumpGeneratedScript: File? = null): String {
|
||||
return render(template.readText(), data, dumpGeneratedScript)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.io.File
|
|||
fun main(args: Array<String>) {
|
||||
val res = EKT.render(File("template.ekt"), mapOf(
|
||||
"value" to 11
|
||||
), dumpGeneratedScript = true)
|
||||
), dumpGeneratedScript = File("script.kts"))
|
||||
|
||||
File("result.txt").apply {
|
||||
if (!exists()) createNewFile()
|
||||
|
|
Loading…
Reference in New Issue