Browse Source

Remove unnecessary replacements and newline removal

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

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

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

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

@ -7,7 +7,9 @@ import java.io.File
*/
fun main(args: Array<String>) {
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"))
File("result.txt").apply {

Loading…
Cancel
Save