diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-26 09:23:55 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-26 09:23:55 +0100 |
| commit | 91d9b6992ac0ebee13704a3faefa8fd41a00075e (patch) | |
| tree | ea0a30cc0cfb2232d3e60c845c20a67b6cdf0b99 /src/zilch/App/root.zig | |
| parent | 65300a13dcd11037218bf8ba61efd8ca19e5920e (diff) | |
zilch: dynamic element creation
Diffstat (limited to 'src/zilch/App/root.zig')
| -rw-r--r-- | src/zilch/App/root.zig | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/zilch/App/root.zig b/src/zilch/App/root.zig index a7700d9..01e2695 100644 --- a/src/zilch/App/root.zig +++ b/src/zilch/App/root.zig @@ -45,7 +45,6 @@ pub fn App(comptime options: Options) type { break :g gl; }, - Methods: type = enum(u16) {}, pub const init: @This() = .{}; @@ -56,21 +55,29 @@ pub fn App(comptime options: Options) type { } }; } else { - const components: []const Element = (comp: { + const components: []const Element, const registry: []const u8 = (comp: { var cs: []const Element = &.{}; + var registry: []const u8 = "const component_registry = {"; for (options.components) |component| { cs = cs ++ component.toElement(); + registry = registry ++ std.fmt.comptimePrint("{}: '{s}-{s}',", .{ + component.id, + component.namespace, + component.name, + }); } - break :comp cs; + registry = registry ++ "};"; + + break :comp .{ cs, registry }; }); const functions: []const u8 = func: { var buf: []const u8 = "ObjectStore.methods = {"; for (options.functions) |function| { - buf = buf ++ std.fmt.comptimePrint("{}: {s},", .{function.id, function.content}); + buf = buf ++ std.fmt.comptimePrint("{}: {s},", .{ function.id, function.content }); } buf = buf ++ "}"; @@ -111,6 +118,7 @@ pub fn App(comptime options: Options) type { "body", .{}, &[_]Element{ + .node("script", .{}, &.{.text(registry)}), } ++ components ++ options.body.elements, ), }), |