Browse Source

Change dumpGeneratedScript to File

master
Shadowfacts 5 years ago
parent
commit
05279cb254
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 12
      src/main/kotlin/net/shadowfacts/ekt/EKT.kt
  2. 2
      src/test/kotlin/net/shadowfacts/ekt/Test.kt

12
src/main/kotlin/net/shadowfacts/ekt/EKT.kt

@ -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 {
if (!exists()) createNewFile()
writeText(script)
}
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)
}

2
src/test/kotlin/net/shadowfacts/ekt/Test.kt

@ -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…
Cancel
Save