authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-07 19:02:03 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-07 19:02:03 -07:00
logaa52db981ada69dcebc9fec54956fe2cd17e58a4
treedeef4956522230719c9e9597fda00a42c5644108
parentea85af3e59831ccb105fdc36dc32d8c55d2aa0a6

implement `#ifequal`


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

src/lib.zig+10
...@@ -117,6 +117,16 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype...@@ -117,6 +117,16 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
117 }117 }
118 }118 }
119 },119 },
120 .ifequal => {
121 comptime assertEqual(v.args.len, 2);
122 const x = comptime search(data, v.args[0]);
123 const y = comptime search(data, v.args[1]);
124 if (x == y) {
125 inline for (v.body) |val| {
126 try do(writer, val, data, ctx, indent, flag1);
127 }
128 }
129 },
120 else => @compileError("pek: block: TODO " ++ @tagName(v.name)),130 else => @compileError("pek: block: TODO " ++ @tagName(v.name)),
121 }131 }
122 },132 },
src/main.zig+4
...@@ -31,6 +31,10 @@ const example_document =...@@ -31,6 +31,10 @@ const example_document =
31 \\ {#ifnot is_it_my_birthday}31 \\ {#ifnot is_it_my_birthday}
32 \\ p("#2")32 \\ p("#2")
33 \\ /ifnot/33 \\ /ifnot/
34 \\
35 \\ {#ifequal top_cities.len best_rating}
36 \\ p("#3")
37 \\ /ifequal/
34 \\ )38 \\ )
35 \\)39 \\)
36;40;
test.html+1
...@@ -24,5 +24,6 @@...@@ -24,5 +24,6 @@
24 <p>Spooky text: &LT;strong&GT;I better not be in bold&period;&LT;&sol;strong&GT;</p>24 <p>Spooky text: &LT;strong&GT;I better not be in bold&period;&LT;&sol;strong&GT;</p>
25 <p>#1</p>25 <p>#1</p>
26 <p>#2</p>26 <p>#2</p>
27 <p>#3</p>
27 </body>28 </body>
28</html>29</html>