update: full template

This commit is contained in:
Lucas F. 2026-01-14 14:09:09 -03:00
parent 0116e84c09
commit eaff212b63

View file

@ -9,33 +9,40 @@ pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const alloc = arena.allocator();
const base =
\\<html>
\\<head><title>{% block title %}Título Padrão{% endblock %}</title></head>
\\<body>
\\{% block content %}Conteúdo padrão{% endblock %}
\\</body>
\\</html>
;
// const base =
// \\<html>
// \\<head><title>{% block title %}Título Padrão{% endblock %}</title></head>
// \\<body>
// \\{% block content %}Conteúdo padrão{% endblock %}
// \\</body>
// \\</html>
// ;
//
// 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 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();
@ -45,12 +52,27 @@ pub fn main() !void {
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("child.html", buffer.writer(ctx.allocator()));
try renderer.render("home.html", buffer.writer(ctx.allocator()));
const output = buffer.items;