diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-25 19:54:26 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-25 19:54:26 +0200 |
| commit | b0902c05ffc84d282e10a0179e041948d49fabf8 (patch) | |
| tree | 7a8a51b48f16d448915bf13c6b41cb176ac5d506 /src/eval | |
| parent | 0a0d579f34e12639c89d890d25be038c5ae81e00 (diff) | |
feat(): supports list unordored
Yes, these files were missing...
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/list.zig | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/eval/list.zig b/src/eval/list.zig new file mode 100644 index 0000000..6954fd1 --- /dev/null +++ b/src/eval/list.zig @@ -0,0 +1,50 @@ +const std = @import("std"); +const Allocator = std.mem.Allocator; +const HTML = Element.HTML; +const Element = @import("Element.zig"); + +fn List(comptime tag: []const u8) type { + return struct { + content: std.ArrayList(Element), + + const Self = @This(); + + pub fn init(alloc: Allocator) !*Self { + const v = try alloc.create(Self); + v.* = .{ + .content = try .initCapacity(alloc, 2), + }; + return v; + } + + pub fn element(self: *Self) Element { + return .{ .ptr = self, .vtable = .{ .deinit = destroy, .html = html } }; + } + + pub fn deinit(self: *Self, alloc: Allocator) void { + destroy(self, alloc); + } + + fn destroy(context: *anyopaque, alloc: Allocator) void { + var self: *Self = @ptrCast(@alignCast(context)); + for (self.content.items) |it| it.deinit(alloc); + self.content.deinit(alloc); + alloc.destroy(self); + } + + fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML { + const self: *Self = @ptrCast(@alignCast(context)); + var el = try HTML.init(alloc, .content, tag); + errdefer el.deinit(); + for (self.content.items) |it| { + var li = try HTML.init(alloc, .content, "li"); + try li.appendContent(try it.html(alloc)); + try el.appendContent(li); + } + return el; + } + }; +} + +pub const Ordored = List("ol"); +pub const Unordored = List("ul"); |
