From 54559668a51aa04aaba88e16f5e7f880f2341739 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sat, 7 Oct 2023 10:33:24 +0100 Subject: [PATCH] Fixes messed up condition block handling, release 0.9.2. --- pom.xml | 2 +- .../com/sshtools/tinytemplate/Templates.java | 2 +- .../sshtools/tinytemplate/TemplatesTest.java | 92 +++++++++++++++++++ 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a390a19..8a44693 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,7 @@ 4.0.0 com.sshtools tinytemplate - 0.9.1 + 0.9.2 TinyTemplate UTF-8 diff --git a/src/main/java/com/sshtools/tinytemplate/Templates.java b/src/main/java/com/sshtools/tinytemplate/Templates.java index dc714b4..3b5d780 100644 --- a/src/main/java/com/sshtools/tinytemplate/Templates.java +++ b/src/main/java/com/sshtools/tinytemplate/Templates.java @@ -824,7 +824,7 @@ else if (ch == 't') { logger.ifPresent(lg -> lg.debug("Leaving scope {0}", block.scope)); return; } else { - if(isIf) { + if(directive.equals(block.scope) && isIf) { buf.setLength(0); } else { diff --git a/src/test/java/com/sshtools/tinytemplate/TemplatesTest.java b/src/test/java/com/sshtools/tinytemplate/TemplatesTest.java index f31beb9..3f319f7 100644 --- a/src/test/java/com/sshtools/tinytemplate/TemplatesTest.java +++ b/src/test/java/com/sshtools/tinytemplate/TemplatesTest.java @@ -488,6 +488,98 @@ public void testTemplateIfWithVariables() { variable("var1", "Some Name"))); } + + @Test + public void testTemplateIncludeWithList() { + Assertions.assertEquals(""" + + + + + + + + + + + + + + + + + + + """, + createParser().process(TemplateModel.ofContent( + """ + + + + + + + + """). + include("alerts", + TemplateModel.ofContent(""" + + + + """).list("items", (content) -> { + var l = new ArrayList(); + for(int i = 0 ; i < 5 ; i++) { + var itemMdl = TemplateModel.ofContent(content). + variable("style", "style-" + i). + variable("title", "Title " + i); + if(i > 2) + itemMdl.variable("icon", "icon-" + i); + if(i > 3) + itemMdl.variable("description", "Description" + i); + l.add(itemMdl); + } + return l; + }) + ) + ).stripIndent()); + } + @Test public void testTemplateIfWithInclude() { Assertions.assertEquals("""