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()
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue