Add ViewEngine for easy server integration

- ViewEngine manages views directory with path resolution
- Auto-loads mixins from views/mixins/ directory
- Simplifies template paths (relative to views dir, auto-adds extension)
- Updated example app to use ViewEngine
- Added example mixins (buttons.pug, cards.pug)
- Updated CLAUDE.md with ViewEngine documentation
This commit is contained in:
2026-01-17 18:50:16 +05:30
parent a65f01fdd0
commit 4538b17f0a
7 changed files with 363 additions and 89 deletions

View File

@@ -7,12 +7,33 @@
//! - Attributes and text interpolation
//! - Control flow (if/else, each, while)
//! - Mixins and template inheritance
//!
//! ## Quick Start (Server Usage)
//!
//! ```zig
//! const pugz = @import("pugz");
//!
//! // Initialize view engine once at startup
//! var engine = try pugz.ViewEngine.init(allocator, .{
//! .views_dir = "src/views",
//! });
//! defer engine.deinit();
//!
//! // Render templates (use arena allocator per request)
//! var arena = std.heap.ArenaAllocator.init(allocator);
//! defer arena.deinit();
//!
//! const html = try engine.render(arena.allocator(), "pages/home", .{
//! .title = "Home",
//! });
//! ```
pub const lexer = @import("lexer.zig");
pub const ast = @import("ast.zig");
pub const parser = @import("parser.zig");
pub const codegen = @import("codegen.zig");
pub const runtime = @import("runtime.zig");
pub const view_engine = @import("view_engine.zig");
// Re-export main types for convenience
pub const Lexer = lexer.Lexer;
@@ -32,6 +53,9 @@ pub const Value = runtime.Value;
pub const render = runtime.render;
pub const renderTemplate = runtime.renderTemplate;
// High-level API
pub const ViewEngine = view_engine.ViewEngine;
test {
_ = @import("std").testing.refAllDecls(@This());
}