mirror of https://github.com/shadowfacts/ekt.git
Remove unnecessary replacements and newline removal
This commit is contained in:
parent
05279cb254
commit
65f62a8b9e
|
@ -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
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue