diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-30 17:56:55 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-30 17:56:55 +0200 |
| commit | a13df3ca580dc31544ef092d5d37e18089af3517 (patch) | |
| tree | cfcf8c1d8322ee8e97783e263105eac9f5c00f33 /src/eval/Title.zig | |
| parent | 5ecd48d4b9f928beb4143f88e802ee4d9e25a2bd (diff) | |
refactor(element): generalize element creation
Diffstat (limited to 'src/eval/Title.zig')
| -rw-r--r-- | src/eval/Title.zig | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/eval/Title.zig b/src/eval/Title.zig index 1841ce7..1300832 100644 --- a/src/eval/Title.zig +++ b/src/eval/Title.zig @@ -1,11 +1,11 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const HTML = Parent.HTML; -const Parent = @import("Element.zig"); -const Node = Parent.Node; +const HTML = Element.HTML; +const Element = @import("Element.zig"); +const Node = Element.Node; level: u3, -content: Parent, +content: Element, node: Node = .{ .ptr = undefined, .vtable = .{ .element = fromNode }, @@ -13,29 +13,23 @@ node: Node = .{ const Self = @This(); -pub fn init(alloc: Allocator, level: u3, content: Parent) !*Self { +pub fn init(alloc: Allocator, level: u3, content: Element) !*Self { const v = try alloc.create(Self); v.* = .{ .level = level, .content = content }; v.node.ptr = v; return v; } -pub fn element(self: *Self) Parent { - return .{ .ptr = self, .vtable = .{ .html = html, .node = getNode } }; +pub fn element(self: *Self) Element { + return Element.Wrapper(Self, html).init(self); } -fn getNode(context: *anyopaque) *Node { - const self: *Self = @ptrCast(@alignCast(context)); - return &self.node; -} - -fn fromNode(context: *anyopaque) Parent { +fn fromNode(context: *anyopaque) Element { const self: *Self = @ptrCast(@alignCast(context)); return self.element(); } -fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML { - const self: *Self = @ptrCast(@alignCast(context)); +fn html(self: *Self, alloc: Allocator) HTML.Error!HTML { var el = try HTML.Content.init(alloc, switch (self.level) { 1 => "h1", 2 => "h2", |
