Add README and simplify ViewEngine API

- ViewEngine.init() no longer requires allocator
- render() and renderTpl() accept allocator parameter
- Remove deinit() - no resources to clean up
- Remove unused parse/renderDoc methods
- Add memory management guidance to runtime.zig
- Clean up unused imports and options
This commit is contained in:
2026-01-17 23:59:22 +05:30
parent 1fff91d7d9
commit 458de03c02
19 changed files with 1036 additions and 366 deletions

View File

@@ -21,18 +21,14 @@ const App = struct {
allocator: Allocator,
view: pugz.ViewEngine,
pub fn init(allocator: Allocator) !App {
pub fn init(allocator: Allocator) App {
return .{
.allocator = allocator,
.view = try pugz.ViewEngine.init(allocator, .{
.view = pugz.ViewEngine.init(.{
.views_dir = "src/examples/demo/views",
}),
};
}
pub fn deinit(self: *App) void {
self.view.deinit();
}
};
pub fn main() !void {
@@ -42,8 +38,7 @@ pub fn main() !void {
const allocator = gpa.allocator();
// Initialize view engine once at startup
var app = try App.init(allocator);
defer app.deinit();
var app = App.init(allocator);
const port = 8080;
var server = try httpz.Server(*App).init(allocator, .{ .port = port }, &app);
@@ -82,6 +77,7 @@ pub fn main() !void {
fn index(app: *App, _: *httpz.Request, res: *httpz.Response) !void {
const html = app.view.render(app.allocator, "index", .{
.title = "Home",
.authenticated = true,
}) catch |err| {
res.status = 500;
res.body = @errorName(err);

View File

@@ -7,3 +7,9 @@ html
| ballah
| ballah
+btn("click me ", "secondary")
br
a(href='//google.com' target="_blank") Google 1
br
a(class='button' href='//google.com' target="_blank") Google 2
br
a(class='button', href='//google.com' target="_blank") Google 3