Remove unnecessary replacements and newline removal

This commit is contained in:
Shadowfacts 2017-08-04 17:05:25 -04:00
parent 05279cb254
commit 65f62a8b9e
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 5 additions and 3 deletions

View File

@ -20,7 +20,7 @@ object EKT {
"#" to { s -> s + "/*" } "#" to { s -> s + "/*" }
) )
private val startStringRegex = Regex("(?:^|[^\\\\])([:=#])]\n?") private val startStringRegex = Regex("(?:^|[^\\\\])([:=#])]")
private val endStringRegex = Regex("\\[([:=#])") private val endStringRegex = Regex("\\[([:=#])")
private val scriptPrefix = """ private val scriptPrefix = """
@ -38,7 +38,7 @@ _result.toString()
fun render(template: String, data: Map<String, Any>, dumpGeneratedScript: File? = null): 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("$", "\${'$'}")
template = ":]$template[:" template = ":]$template[:"
template = template.replace(startStringRegex, { template = template.replace(startStringRegex, {
val c = it.groups[1]!!.value val c = it.groups[1]!!.value

View File

@ -7,7 +7,9 @@ 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 "title" to "EKT Test",
"body" to "some test content",
"value" to 42
), dumpGeneratedScript = File("script.kts")) ), dumpGeneratedScript = File("script.kts"))
File("result.txt").apply { File("result.txt").apply {