const std = @import("std"); const zdt_prov = @import("zdt_prov"); const Context = @import("context.zig").Context; const Renderer = @import("renderer.zig").Renderer; const parser = @import("parser.zig"); const TemplateCache = @import("cache.zig").TemplateCache; pub fn main() !void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); const alloc = arena.allocator(); // const base = // \\ // \\{% block title %}Título Padrão{% endblock %} // \\ // \\{% block content %}Conteúdo padrão{% endblock %} // \\ // \\ // ; // // const child = // \\{% extends "base.html" %} // \\{% block title %}Meu Título{% endblock %} // \\{% block content %} // \\Olá {{ nome }}! // \\{% endblock %} // ; // // try std.fs.cwd().writeFile(.{ // .sub_path = "base.html", // .data = base, // }); // try std.fs.cwd().writeFile(.{ // .sub_path = "child.html", // .data = child, // }); // defer std.fs.cwd().deleteFile("base.html") catch {}; // defer std.fs.cwd().deleteFile("child.html") catch {}; const User =struct { name: []const u8, email: []const u8, notifications: i64 = 0 }; var ctx = Context.init(alloc); defer ctx.deinit(); var cache = TemplateCache.init(alloc); defer cache.deinit(); const renderer = Renderer.init(&ctx, &cache); const user = User{ .name = "Lucas", .email = "lucas@email", .notifications = 5 }; const itens = [3][]const u8{"Livro", "Caneta", "Caderno"}; try ctx.set("nome", "Lucas"); try ctx.set("user", user); try ctx.set("msg", "Bazinga!"); try ctx.set("itens", itens); for(ctx.get("itens").?.list) |item| { std.debug.print(" - {s}\n", .{item.string}); } var buffer = std.ArrayList(u8){}; defer buffer.deinit(ctx.allocator()); try renderer.render("home.html", buffer.writer(ctx.allocator())); const output = buffer.items; std.debug.print("{s}\n", .{output}); }