aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/Document.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/Document.zig')
-rw-r--r--src/frontend/Document.zig46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/frontend/Document.zig b/src/frontend/Document.zig
new file mode 100644
index 0000000..0ba46b1
--- /dev/null
+++ b/src/frontend/Document.zig
@@ -0,0 +1,46 @@
+const std = @import("std");
+
+const Component = @import("Component.zig");
+const Head = @import("Head.zig");
+const File = @import("File.zig");
+
+const Self = @This();
+
+components: []const Component,
+head: Head,
+styles: []const File.Style,
+contents: []const File.Html,
+
+pub const empty: Self = .{
+ .head = .empty,
+ .components = &.{},
+ .styles = &.{},
+ .contents = &.{},
+};
+
+pub fn to_string(comptime self: Self) []const u8 {
+ comptime var content: []const u8 = "<!DOCTYPE html><html>";
+ content = content ++ comptime self.head.to_html_string(self.components, self.styles);
+ content = content ++ "<body>";
+
+ inline for (self.contents) |c| {
+ content = content ++ comptime c.to_html_string();
+ }
+
+ content = content ++ "</body></html>";
+
+ return content;
+}
+
+test {
+ const document: Self = comptime .{
+ .head = .default("test"),
+ .components = &.{
+ .path("./web/hello-world"),
+ },
+ .styles = &.{},
+ .contents = &.{.minify("./web/index.html")},
+ };
+
+ std.debug.print("{s}", .{document.to_string()});
+}