Something went wrong. Try again.
Dev fork of jetzig jetzig.dev
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677//! Output stream for writing values into a rendered template. The render data is the//! comptime-known `Context` declared by the template's `@context` block and passed to `render`.const std = @import("std");const zmpl = @import("root.zig");pub const Interface = @import("Interface.zig");const matte = @import("matte");
const Allocator = std.mem.Allocator;const Io = std.Io;const ArenaAllocator = std.heap.ArenaAllocator;const Writer = std.Io.Writer;const Stringify = std.json.Stringify;const cyan = matte.style.fg(.cyan);const yellow = matte.style.fg(.yellow);const bright_red = matte.style.fg(.bright_red);const red = matte.style.fg(.red);const util = zmpl.util;
pub var log_errors = true;
pub const LayoutContent = struct { data: []const u8,
pub fn format(self: LayoutContent, writer: *Writer) !void { try writer.writeAll(self.data); }};
pub const Slot = struct { data: []const u8,
pub fn format(self: Slot, writer: *Writer) !void { try writer.writeAll(self.data); }};
pub const ErrorName = enum { ref, type, syntax, constant, compare };pub const ZmplError = error{ ZmplUnknownDataReferenceError, ZmplTypeError, ZmplSyntaxError, ZmplConstantError, ZmplCompareError, ZmplCoerceError,};
pub fn zmplError(comptime err_name: ErrorName, comptime message: []const u8, args: anytype) ZmplError { const err = switch (err_name) { .ref => error.ZmplUnknownDataReferenceError, .type => error.ZmplTypeError, .syntax => error.ZmplSyntaxError, .constant => error.ZmplConstantError, .compare => error.ZmplCompareError, };
if (log_errors) { std.debug.print( std.fmt.comptimePrint( "{s} [{s}:{s}] {s}\n", .{ cyan.renderComptime("[zmpl]"), yellow.renderComptime("error"), bright_red.renderComptime(@errorName(err)), red.renderComptime(message), }, ), args, ); }
return err;}
pub fn unknownRef(name: []const u8) ZmplError { return zmplError(.ref, "Unknown data reference: `{s}`", .{name});}