Execute else branches
This commit is contained in:
parent
bb297a4f6e
commit
f8a799abfb
2 changed files with 10 additions and 3 deletions
|
@ -52,7 +52,11 @@ fn executeStatement(writer: anytype, comptime stmt: Statement, args: anytype, ca
|
|||
.@"if" => |if_stmt| {
|
||||
const condition = evaluateExpression(if_stmt.header.condition, args, captures);
|
||||
const subtemplate = if_stmt.subtemplate;
|
||||
if (condition) try executeTemplate(writer, subtemplate, args, captures);
|
||||
if (condition) {
|
||||
try executeTemplate(writer, subtemplate, args, captures);
|
||||
} else {
|
||||
if (if_stmt.else_branch) |branch| try executeTemplate(writer, branch, args, captures);
|
||||
}
|
||||
},
|
||||
//else => @compileError("TODO"),
|
||||
}
|
||||
|
@ -178,6 +182,8 @@ fn parseTemplate(
|
|||
.@"if" = .{
|
||||
.subtemplate = subtemplate.items,
|
||||
.header = header,
|
||||
|
||||
.else_branch = if (else_subtemplate) |sub| sub.items else null,
|
||||
},
|
||||
},
|
||||
}};
|
||||
|
@ -516,6 +522,7 @@ const ForHeader = struct {
|
|||
const If = struct {
|
||||
subtemplate: []const TemplateItem,
|
||||
header: IfHeader,
|
||||
else_branch: ?[]const TemplateItem,
|
||||
};
|
||||
|
||||
const IfHeader = struct {
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
{$b}:
|
||||
{= /for =}
|
||||
{= /for}
|
||||
{#if .qux}qux!{#else}!qux!{/if=}
|
||||
{#if .quxx}quxx!{#else}!quxx!{/if}
|
||||
{#if .qux}qux{#else}!qux{/if}
|
||||
{#if .quxx}quxx{#else}!quxx{/if}
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue