authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-07 19:02:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-07 19:02:19 -07:00
log5ff076490192e777e8f2dd3bdb712622abb30faa
tree64a443fab5bbdd2910444b5f146a36ba07869047
parentaa52db981ada69dcebc9fec54956fe2cd17e58a4

implement `#ifnotequal`


3 files changed, 15 insertions(+), 1 deletions(-)

src/lib.zig+10-1
......@@ -127,7 +127,16 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
127127 }
128128 }
129129 },
130 else => @compileError("pek: block: TODO " ++ @tagName(v.name)),
130 .ifnotequal => {
131 comptime assertEqual(v.args.len, 2);
132 const x = comptime search(data, v.args[0]);
133 const y = comptime search(data, v.args[1]);
134 if (x != y) {
135 inline for (v.body) |val| {
136 try do(writer, val, data, ctx, indent, flag1);
137 }
138 }
139 },
131140 }
132141 },
133142 else => unreachable,
src/main.zig+4
......@@ -35,6 +35,10 @@ const example_document =
3535 \\ {#ifequal top_cities.len best_rating}
3636 \\ p("#3")
3737 \\ /ifequal/
38 \\
39 \\ {#ifnotequal favorite.color sky}
40 \\ p("#4")
41 \\ /ifnotequal/
3842 \\ )
3943 \\)
4044;
test.html+1
......@@ -25,5 +25,6 @@
2525 <p>#1</p>
2626 <p>#2</p>
2727 <p>#3</p>
28 <p>#4</p>
2829 </body>
2930</html>