diff --git a/src/main.zig b/src/main.zig
index 467a970..01d0fd9 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,27 +1,58 @@
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 {
- // Prints to stderr, ignoring potential errors.
- std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
- try zdt_prov.bufferedPrint();
-}
+ var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
+ const alloc = arena.allocator();
-test "simple test" {
- const gpa = std.testing.allocator;
- var list: std.ArrayList(i32) = .empty;
- defer list.deinit(gpa); // Try commenting this out and see if zig detects the memory leak!
- try list.append(gpa, 42);
- try std.testing.expectEqual(@as(i32, 42), list.pop());
-}
+ const base =
+ \\
+ \\
{% block title %}Título Padrão{% endblock %}
+ \\
+ \\{% block content %}Conteúdo padrão{% endblock %}
+ \\
+ \\
+ ;
-test "fuzz example" {
- const Context = struct {
- fn testOne(context: @This(), input: []const u8) anyerror!void {
- _ = context;
- // Try passing `--fuzz` to `zig build test` and see if it manages to fail this test case!
- try std.testing.expect(!std.mem.eql(u8, "canyoufindme", input));
- }
- };
- try std.testing.fuzz(Context{}, Context.testOne, .{});
+ 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 {};
+
+ var ctx = Context.init(alloc);
+ defer ctx.deinit();
+
+ var cache = TemplateCache.init(alloc);
+ defer cache.deinit();
+
+ const renderer = Renderer.init(&ctx, &cache);
+
+ try ctx.set("nome", "Lucas");
+
+ var buffer = std.ArrayList(u8){};
+ defer buffer.deinit(ctx.allocator());
+
+ try renderer.render("child.html", buffer.writer(ctx.allocator()));
+
+ const output = buffer.items;
+
+ std.debug.print("{s}\n", .{output});
}