Change dumpGeneratedScript to File

This commit is contained in:
Shadowfacts 2017-08-04 16:58:17 -04:00
parent d809453101
commit 05279cb254
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 6 additions and 8 deletions

View File

@ -35,7 +35,7 @@ _result.toString()
ScriptEngineManager() 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") @Suppress("NAME_SHADOWING")
var template = template var template = template
template = template.replace("\"", "\\\"").replace("$", "\${'$'}") template = template.replace("\"", "\\\"").replace("$", "\${'$'}")
@ -59,17 +59,15 @@ _result.toString()
val script = scriptPrefix + template + scriptSuffix val script = scriptPrefix + template + scriptSuffix
if (dumpGeneratedScript) { dumpGeneratedScript?.apply {
File("script.kts").apply { if (!exists()) createNewFile()
if (!exists()) createNewFile() writeText(script)
writeText(script)
}
} }
return eval(script, data) as String 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) return render(template.readText(), data, dumpGeneratedScript)
} }

View File

@ -8,7 +8,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(
"value" to 11 "value" to 11
), dumpGeneratedScript = true) ), dumpGeneratedScript = File("script.kts"))
File("result.txt").apply { File("result.txt").apply {
if (!exists()) createNewFile() if (!exists()) createNewFile()