aboutsummaryrefslogtreecommitdiff
path: root/src/z/App
diff options
context:
space:
mode:
Diffstat (limited to 'src/z/App')
-rw-r--r--src/z/App/root.zig80
1 files changed, 44 insertions, 36 deletions
diff --git a/src/z/App/root.zig b/src/z/App/root.zig
index 42ef26f..8fce591 100644
--- a/src/z/App/root.zig
+++ b/src/z/App/root.zig
@@ -1,13 +1,14 @@
const builtin = @import("builtin");
const std = @import("std");
-const h = @import("../html.zig");
+const Element = @import("../root.zig").html.Element;
+const Document = @import("../root.zig").html.Document;
const Component = @import("../root.zig").Component;
pub const Options = struct {
name: []const u8,
globals: []const Global,
components: []const Component,
- body: h.Element,
+ body: Element,
theme: []const u8,
pub const Global = struct {
@@ -49,44 +50,51 @@ pub fn App(comptime options: Options) type {
}
};
} else {
- return struct {
- html: []const u8 = h.Element.native(.html, .{}, .children(&.{
- .native(.head, .{}, .children(&.{
- .native(.title, .{}, .content(options.name)),
- .native(.meta, .{
- .name = "viewport",
- .content = "width=device-width, initial-scale=1.0",
- }, .void),
- .native(.style, .{}, .content(options.theme)),
- })),
- .native(.body, .{}, .children(&.{
- .native(.script, .{}, .content(@embedFile("object-store.js"))),
- .native(.script, .{}, .content(reg: {
- var register_code: []const u8 = "";
+ const components: []const Element = (comp: {
+ var cs: []const Element = &.{};
+
+ for (options.components) |component| {
+ cs = cs ++ component.toElement();
+ }
- for (options.globals, 1..) |field, id| {
- register_code = register_code ++ std.fmt.comptimePrint(
- "ObjectStore.registerObject({}, {s});",
- .{ id, field.name },
- );
- }
+ break :comp cs;
+ });
+
+ return struct {
+ const node: Document = .{
+ .root = .node("html", .{}, &.{
+ .node("head", .{}, &.{
+ .node("title", .{}, &.{.text(options.name)}),
+ .void("meta", .{
+ .name = "viewport",
+ .content = "width=device-width, initial-scale=1.0",
+ }),
+ .node("style", .{}, &.{.text(options.theme)}),
+ }),
+ .node(
+ "body",
+ .{},
+ &[_]Element{
+ .node("script", .{}, &.{.text(@embedFile("object-store.js"))}),
+ .node("script", .{}, &.{.text(reg: {
+ var register_code: []const u8 = "";
- break :reg register_code;
- })),
- .native(.script, .{}, .content(@embedFile("main.js"))),
- .transparent(.children(comp: {
- var cs: []const h.Element = &.{};
+ for (options.globals, 1..) |field, id| {
+ register_code = register_code ++ std.fmt.comptimePrint(
+ "ObjectStore.registerObject({}, {s});",
+ .{ id, field.name },
+ );
+ }
- for (options.components) |component| {
- const c: []const h.Element = &.{component.toElement()};
- cs = cs ++ c;
- }
+ break :reg register_code;
+ })}),
+ .node("script", .{}, &.{.text(@embedFile("main.js"))}),
+ } ++ components ++ &[1]Element{options.body},
+ ),
+ }),
+ };
- break :comp cs;
- })),
- options.body,
- })),
- })).toDocument(),
+ html: []const u8 = std.fmt.comptimePrint("{f}", .{node}),
pub const init: @This() = .{};
};