Skip to content

Commit

Permalink
Templates: Support elsif in addition to elseif (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Mar 13, 2024
1 parent 3b5e345 commit b1bc0ae
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions korlibs-template/src/korlibs/template/KorteDefaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ object KorteDefaultTags {

for (part in chunks) {
when (part.tag.name) {
"if", "elseif", "unless", "elseunless" -> branches += Branch(part)
"if", "elseif", "elsif", "unless", "elseunless" -> branches += Branch(part)
"else" -> elseBranch = part.body
}
}
Expand All @@ -281,8 +281,8 @@ object KorteDefaultTags {
return node
}

val If = KorteTag("if", setOf("else", "elseif", "elseunless"), setOf("end", "endif")) { BuildIf(isIf = true) }
val Unless = KorteTag("unless", setOf("else", "elseif", "elseunless"), setOf("end", "endunless")) { BuildIf(isIf = true) }
val If = KorteTag("if", setOf("else", "elseif", "elsif", "elseunless"), setOf("end", "endif")) { BuildIf(isIf = true) }
val Unless = KorteTag("unless", setOf("else", "elseif", "elsif", "elseunless"), setOf("end", "endunless")) { BuildIf(isIf = true) }

val Import = KorteTag("import", setOf(), null) {
val part = chunks.first()
Expand Down
2 changes: 1 addition & 1 deletion korlibs-template/test/korlibs/template/TemplateTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class TemplateTest : BaseTest() {
@Test
fun testSimpleElseIf() = suspendTest {
val tpl =
KorteTemplate("{% if v == 1 %}one{% elseif v == 2 %}two{% elseif v < 5 %}less than five{% elseif v > 8 %}greater than eight{% else %}other{% end %}")
KorteTemplate("{% if v == 1 %}one{% elseif v == 2 %}two{% elsif v < 5 %}less than five{% elseif v > 8 %}greater than eight{% else %}other{% end %}")
assertEquals("one", tpl("v" to 1))
assertEquals("two", tpl("v" to 2))
assertEquals("less than five", tpl("v" to 3))
Expand Down

0 comments on commit b1bc0ae

Please sign in to comment.