2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-04-30 18:48:13 -07:00

Fixed template block overriding behavior, now properly resetting blockvalue and blockappend status

This commit is contained in:
Geert Bevin 2022-11-26 10:43:37 -05:00
parent c86b780e73
commit e534d665f1
7 changed files with 82 additions and 0 deletions

View file

@ -1043,6 +1043,13 @@ class_writer.visitEnd();
blockvalues_.add(id);
}
void removeBlockvalue(String id) {
assert id != null;
assert id.length() > 0;
blockvalues_.remove(id);
}
String getDefaultValue(String id) {
assert id != null;
assert id.length() > 0;

View file

@ -553,6 +553,7 @@ public class Parser implements Cloneable {
name = ctx.CTagName();
}
final var block_id = name.getText();
parsed_.removeBlockvalue(block_id);
blockIds_.push(block_id);
blocks_.put(block_id, new ParsedBlockData());
}

View file

@ -347,6 +347,34 @@ public class TestParser {
}
}
*/
@Test
public void testParseBlockoverrides() {
try {
Parsed template_parsed = parser_.parse("blockoverrides_in", null);
assertEquals(template_parsed.getBlocks().size(), 3);
assertNotNull(template_parsed.getContent());
assertNotNull(template_parsed.getBlock("BLOCK1"));
assertNotNull(template_parsed.getBlock("BLOCK2"));
assertEquals(template_parsed.getContent().countParts(), 4);
assertEquals(template_parsed.getBlock("BLOCK1").countParts(), 1);
assertFalse(template_parsed.hasBlockvalue("BLOCK1"));
assertEquals(template_parsed.getBlock("BLOCK2").countParts(), 1);
assertFalse(template_parsed.hasBlockvalue("BLOCK2"));
assertEquals(template_parsed.getContent().getPart(0).getData(), parser_.getTemplateContent("blockoverrides_out_content_0"));
assertEquals(template_parsed.getContent().getPart(1).getType(), ParsedBlockPart.Type.VALUE);
assertEquals(template_parsed.getContent().getPart(1).getData(), "BLOCK1");
assertEquals(template_parsed.getContent().getPart(2).getType(), ParsedBlockPart.Type.VALUE);
assertEquals(template_parsed.getContent().getPart(2).getData(), "BLOCK2");
assertEquals(template_parsed.getContent().getPart(3).getData(), parser_.getTemplateContent("blockoverrides_out_content_3"));
assertEquals(template_parsed.getBlock("BLOCK1").getPart(0).getData(), "block1");
assertEquals(parser_.getTemplateFactory().get("blockoverrides_in").getContent(), parser_.getTemplateContent("blockoverrides_content"));
} catch (TemplateException e) {
fail(ExceptionUtils.getExceptionStackTrace(e));
}
}
@Test
public void testParseBlocksNested() {
try {

View file

@ -0,0 +1,15 @@
<html>
<head>
<title>Template with blocks that override each other</title>
</head>
<body>
<h1>Template with blocks that override each other</h1>
<!--v BLOCK1/--><!--v BLOCK2/-->
</body>
</html>

View file

@ -0,0 +1,15 @@
<html>
<head>
<title>Template with blocks that override each other</title>
</head>
<body>
<h1>Template with blocks that override each other</h1>
<!--v BLOCK1/--><!--v BLOCK2/-->
<!--bv BLOCK1-->block1 value<!--/bv-->
<!--b BLOCK1-->block1<!--/b-->
<!--ba BLOCK2-->block2 append<!--/ba-->
<!--b BLOCK2-->block2<!--/b-->
<!--b BLOCK2-->block2b<!--/b-->
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Template with blocks that override each other</title>
</head>
<body>
<h1>Template with blocks that override each other</h1>

View file

@ -0,0 +1,8 @@
</body>
</html>