Fix whitespace stripping after control blocks

This commit is contained in:
jaina heartles 2022-11-18 03:32:30 -08:00
parent 229acd6d3b
commit fdf0a84593
2 changed files with 6 additions and 3 deletions

View File

@ -39,6 +39,7 @@ fn executeStatement(writer: anytype, comptime stmt: Statement, args: anytype, ca
.@"for" => |loop| {
const iterable = evaluateExpression(loop.header.iterable, args, captures);
const subtemplate = loop.subtemplate;
//std.log.debug("{any}", .{subtemplate});
for (iterable) |v| {
try executeTemplate(
writer,
@ -155,6 +156,7 @@ fn parseTemplate(
switch (cb.block) {
.expression => |expr| items = items ++ [_]TemplateItem{.{ .statement = .{ .expression = expr } }},
.if_header => |header| {
if (i != tokens.len - 1 and tokens[i + 1] == .whitespace and cb.strip_after) i += 1;
const subtemplate = parseTemplate(tokens, i + 1, .if_block);
items = items ++ [_]TemplateItem{.{
.statement = .{
@ -167,6 +169,7 @@ fn parseTemplate(
i = subtemplate.new_iter;
},
.for_header => |header| {
if (i != tokens.len - 1 and tokens[i + 1] == .whitespace and cb.strip_after) i += 1;
const subtemplate = parseTemplate(tokens, i + 1, .for_block);
items = items ++ [_]TemplateItem{.{
.statement = .{

View File

@ -9,12 +9,12 @@
<h2> {{ REAL BRACKETS }} </h2>
<section>
{= #for .baz |$f| =}
{#for .baz |$f| =}
{= #for $f |$b| =}
{$b}:
{= /for =}
{= /for =}
{#if .qux}qux!{/if}
{= /for}
{#if .qux}qux!{/if=}
{#if .quxx}quxx!{/if}
</section>
</body>