//! Auto-generated by pugz.compileTemplates() //! Do not edit manually - regenerate by running: zig build const std = @import("std"); const Allocator = std.mem.Allocator; const ArrayList = std.ArrayList(u8); // ───────────────────────────────────────────────────────────────────────────── // Helpers // ───────────────────────────────────────────────────────────────────────────── const esc_lut: [256]?[]const u8 = blk: { var t: [256]?[]const u8 = .{null} ** 256; t['&'] = "&"; t['<'] = "<"; t['>'] = ">"; t['"'] = """; t['\''] = "'"; break :blk t; }; fn esc(o: *ArrayList, a: Allocator, s: []const u8) Allocator.Error!void { var i: usize = 0; for (s, 0..) |c, j| { if (esc_lut[c]) |e| { if (j > i) try o.appendSlice(a, s[i..j]); try o.appendSlice(a, e); i = j + 1; } } if (i < s.len) try o.appendSlice(a, s[i..]); } fn truthy(v: anytype) bool { return switch (@typeInfo(@TypeOf(v))) { .bool => v, .optional => v != null, .pointer => |p| if (p.size == .slice) v.len > 0 else true, .int, .comptime_int => v != 0, else => true, }; } var int_buf: [32]u8 = undefined; fn strVal(v: anytype) []const u8 { const T = @TypeOf(v); switch (@typeInfo(T)) { .pointer => |p| switch (p.size) { .slice => return v, .one => { // For pointer-to-array, slice it const child_info = @typeInfo(p.child); if (child_info == .array) { const arr_info = child_info.array; const ptr: [*]const arr_info.child = @ptrCast(v); return ptr[0..arr_info.len]; } return strVal(v.*); }, else => @compileError("unsupported pointer type"), }, .array => @compileError("arrays must be passed by pointer"), .int, .comptime_int => return std.fmt.bufPrint(&int_buf, "{d}", .{v}) catch "0", .optional => return if (v) |val| strVal(val) else "", else => @compileError("strVal: unsupported type " ++ @typeName(T)), } } // ───────────────────────────────────────────────────────────────────────────── // Templates // ───────────────────────────────────────────────────────────────────────────── pub fn index(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "hello

some thing

ballahballah"); { const text = "click me "; const @"type" = "secondary"; try o.appendSlice(a, ""); try esc(&o, a, strVal(text)); try o.appendSlice(a, ""); } try o.appendSlice(a, "
Google 1
Google 2
Google 3"); _ = d; return o.items; } pub fn sub_layout(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "My Site - "); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

nothing

nothing

some footer content

"); return o.items; } pub fn _404(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return "

Route no found

"; } pub fn mixins_alert(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return ""; } pub fn mixins_buttons(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return ""; } pub fn mixins_cards(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return ""; } pub fn mixins_alert_error(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return ""; } pub fn mixins_input_text(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return ""; } pub fn home(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, ""); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

"); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

"); if (truthy(@field(d, "authenticated"))) { try o.appendSlice(a, "Welcome back!"); } try o.appendSlice(a, "

This page is rendered using a compiled template.

Compiled templates are 3x faster than Pug.js!

"); return o.items; } pub fn page_a(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "My Site - "); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

"); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

Welcome to the pets page!


one
two
sdfsdfsbtn
"); { const name = "firstName"; const label = "First Name"; const placeholder = "first name"; try o.appendSlice(a, "
"); try esc(&o, a, strVal(label)); try o.appendSlice(a, "
"); } try o.appendSlice(a, "
"); { const name = "lastName"; const label = "Last Name"; const placeholder = "last name"; try o.appendSlice(a, "
"); try esc(&o, a, strVal(label)); try o.appendSlice(a, "
"); } try o.appendSlice(a, "sumit"); if (truthy(@field(d, "error"))) { { const message = @field(d, "error"); { try o.appendSlice(a, ""); try esc(&o, a, strVal(message)); try o.appendSlice(a, ""); } } } try o.appendSlice(a, "

some footer content

"); return o.items; } pub fn page_b(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "My Site - "); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

nothing

nothing

some footer content

"); return o.items; } pub fn layout_2(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return ""; } pub fn layout(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "My Site - "); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

some footer content

"); return o.items; } pub fn page_append(a: Allocator, d: anytype) Allocator.Error![]u8 { _ = .{ a, d }; return "

cheks manually the head section
hello there

"; } pub fn users(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "Users

User List

    "); for (@field(d, "users")) |user| { try o.appendSlice(a, "
  • "); try esc(&o, a, strVal(user.name)); try o.appendSlice(a, ""); try esc(&o, a, strVal(user.email)); try o.appendSlice(a, "
  • "); } try o.appendSlice(a, "
"); return o.items; } pub fn page_appen_optional_blk(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "My Site - "); try esc(&o, a, strVal(@field(d, "title"))); try o.appendSlice(a, "

some footer content

"); return o.items; } pub fn pet(a: Allocator, d: anytype) Allocator.Error![]u8 { var o: ArrayList = .empty; try o.appendSlice(a, "

"); try esc(&o, a, strVal(@field(d, "petName"))); try o.appendSlice(a, "

"); return o.items; } pub const template_names = [_][]const u8{ "index", "sub_layout", "_404", "mixins_alert", "mixins_buttons", "mixins_cards", "mixins_alert_error", "mixins_input_text", "home", "page_a", "page_b", "layout_2", "layout", "page_append", "users", "page_appen_optional_blk", "pet", };