Added recursive Templator logic
This commit is contained in:
parent
ad04f622d3
commit
b92465b62b
3 changed files with 20 additions and 12 deletions
11
Zutil.iml
11
Zutil.iml
|
|
@ -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>
|
||||
|
|
|
|||
5
src/zutil/parser/Templator.java
Normal file → Executable file
5
src/zutil/parser/Templator.java
Normal file → Executable file
|
|
@ -411,7 +411,10 @@ public class Templator {
|
|||
public void compile(StringBuilder str) {
|
||||
Object obj = getObject();
|
||||
if(obj != null)
|
||||
str.append(obj.toString());
|
||||
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
16
test/zutil/test/TemplatorTest.java
Normal file → Executable 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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue