2026-01-25 15:23:57 +05:30
|
|
|
const std = @import("std");
|
|
|
|
|
const pugz = @import("pugz");
|
|
|
|
|
|
|
|
|
|
pub fn main() !void {
|
|
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
|
defer _ = gpa.deinit();
|
|
|
|
|
const allocator = gpa.allocator();
|
|
|
|
|
|
2026-01-27 16:45:04 +05:30
|
|
|
// Use ArenaAllocator for ViewEngine (recommended pattern)
|
|
|
|
|
var arena = std.heap.ArenaAllocator.init(allocator);
|
|
|
|
|
defer arena.deinit();
|
|
|
|
|
const arena_alloc = arena.allocator();
|
|
|
|
|
|
2026-01-25 16:35:27 +05:30
|
|
|
// Test: Simple include from test_views
|
2026-01-27 16:04:02 +05:30
|
|
|
var engine = pugz.ViewEngine.init(.{
|
2026-01-27 15:09:08 +05:30
|
|
|
.views_dir = "tests/sample/01",
|
2026-01-27 16:04:02 +05:30
|
|
|
});
|
2026-01-25 15:23:57 +05:30
|
|
|
defer engine.deinit();
|
|
|
|
|
|
2026-01-27 16:45:04 +05:30
|
|
|
const html = engine.render(arena_alloc, "home", .{}) catch |err| {
|
2026-01-25 15:23:57 +05:30
|
|
|
std.debug.print("Error: {}\n", .{err});
|
|
|
|
|
return err;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std.debug.print("=== Rendered HTML ===\n{s}\n=== End ===\n", .{html});
|
2026-01-25 16:35:27 +05:30
|
|
|
|
2026-01-27 16:45:04 +05:30
|
|
|
// Verify output contains mixin-generated content
|
|
|
|
|
if (std.mem.indexOf(u8, html, "card") != null and
|
|
|
|
|
std.mem.indexOf(u8, html, "Title") != null and
|
|
|
|
|
std.mem.indexOf(u8, html, "content here") != null)
|
2026-01-25 16:35:27 +05:30
|
|
|
{
|
2026-01-27 16:45:04 +05:30
|
|
|
std.debug.print("\nSUCCESS: Include and mixin directives work correctly!\n", .{});
|
2026-01-25 16:35:27 +05:30
|
|
|
} else {
|
2026-01-27 16:45:04 +05:30
|
|
|
std.debug.print("\nFAILURE: Expected content not found!\n", .{});
|
2026-01-25 16:35:27 +05:30
|
|
|
return error.TestFailed;
|
|
|
|
|
}
|
2026-01-25 15:23:57 +05:30
|
|
|
}
|