aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/Document.zig
blob: 0ba46b1d6c73c52a55e157f38c1a9c056b593cec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()});
}