Added recursive Templator logic

This commit is contained in:
Ziver Koc 2015-11-16 12:36:53 +01:00
parent ad04f622d3
commit b92465b62b
3 changed files with 20 additions and 12 deletions

View file

@ -8,17 +8,6 @@
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="libs">
<CLASSES>

3
src/zutil/parser/Templator.java Normal file → Executable file
View file

@ -411,6 +411,9 @@ public class Templator {
public void compile(StringBuilder str) {
Object obj = getObject();
if(obj != null)
if(obj instanceof Templator)
str.append(((Templator) obj).compile());
else
str.append(obj.toString());
else
str.append("{{").append(tag).append("}}");

16
test/zutil/test/TemplatorTest.java Normal file → Executable file
View file

@ -271,4 +271,20 @@ public class TemplatorTest {
assertEquals(
"<HTML>111</HTML>", tmpl.compile());
}
@Test
public void recursiveTemplateorTest(){
Templator tmpl2 = new Templator(
"{{value1}},{{value2}}");
tmpl2.set("value1", "sub1");
tmpl2.set("value2", "sub2");
Templator tmpl = new Templator(
"<HTML>{{parent}}:{{child}}</HTML>");
tmpl.set("parent", "super");
tmpl.set("child", tmpl2);
assertEquals(
"<HTML>super:sub1,sub2</HTML>", tmpl.compile());
}
}