aboutsummaryrefslogtreecommitdiff
path: root/src/eval/blocks.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval/blocks.zig')
-rw-r--r--src/eval/blocks.zig43
1 files changed, 8 insertions, 35 deletions
diff --git a/src/eval/blocks.zig b/src/eval/blocks.zig
index 9357799..03b0d00 100644
--- a/src/eval/blocks.zig
+++ b/src/eval/blocks.zig
@@ -22,15 +22,7 @@ pub const Code = struct {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{
- .html = html,
- .node = getNode,
- } };
- }
-
- fn getNode(context: *anyopaque) *Node {
- const self: *Self = @ptrCast(@alignCast(context));
- return &self.node;
+ return Element.Wrapper(Self, html).init(self);
}
fn fromNode(context: *anyopaque) Element {
@@ -38,8 +30,7 @@ pub const Code = struct {
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, "pre");
if (self.attribute) |attr| try el.base.setAttribute("data-code", attr);
var code = try HTML.Content.init(alloc, "code");
@@ -69,12 +60,7 @@ pub const Figure = struct {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{ .html = html, .node = getNode } };
- }
-
- fn getNode(context: *anyopaque) *Node {
- const self: *Self = @ptrCast(@alignCast(context));
- return &self.node;
+ return Element.Wrapper(Self, html).init(self);
}
fn fromNode(context: *anyopaque) Element {
@@ -82,8 +68,7 @@ pub const Figure = struct {
return self.element();
}
- fn html(context: *anyopaque, parent: Allocator) HTML.Error!HTML {
- const self: *Self = @ptrCast(@alignCast(context));
+ fn html(self: *Self, parent: Allocator) HTML.Error!HTML {
var el = try HTML.Content.init(parent, "figure");
var root = try HTML.Root.init(parent);
const alloc = root.allocator();
@@ -116,12 +101,7 @@ pub const Callout = struct {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{ .html = html, .node = getNode } };
- }
-
- fn getNode(context: *anyopaque) *Node {
- const self: *Self = @ptrCast(@alignCast(context));
- return &self.node;
+ return Element.Wrapper(Self, html).init(self);
}
fn fromNode(context: *anyopaque) Element {
@@ -129,8 +109,7 @@ pub const Callout = struct {
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, "div");
try el.base.appendClass("callout");
const kind = self.kind orelse "default";
@@ -162,12 +141,7 @@ pub const Quote = struct {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{ .html = html, .node = getNode } };
- }
-
- fn getNode(context: *anyopaque) *Node {
- const self: *Self = @ptrCast(@alignCast(context));
- return &self.node;
+ return Element.Wrapper(Self, html).init(self);
}
fn fromNode(context: *anyopaque) Element {
@@ -175,8 +149,7 @@ pub const Quote = struct {
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 {
const quote = try HTML.Content.init(alloc, "blockquote");
quote.content = try self.content.html(alloc);
return quote.element();