- Add TypeHint node type in parser for //- @TypeOf(field): type syntax
- Support scalar types (f32, i32, bool, etc.) and array/struct types
- Use helpers.appendValue() for non-string typed fields
- Filter out loop variable references from Data struct fields
- Preserve @TypeOf comments during comment stripping
Example usage:
//- @TypeOf(subtotal): f32
span $#{subtotal}
//- @TypeOf(items): []{name: []const u8, price: f32}
each item in items
h3 #{item.name}
Pugz Demo App
A comprehensive e-commerce demo showcasing Pugz template engine capabilities.
Features
- Template inheritance (extends/block)
- Partial includes (header, footer)
- Mixins with parameters (product-card, rating, forms)
- Conditionals and loops
- Data binding
- Pretty printing
Running the Demo
Option 1: Runtime Templates (Default)
cd examples/demo
zig build run
Then visit http://localhost:5882 in your browser.
Option 2: Compiled Templates (Experimental)
Compiled templates offer maximum performance by pre-compiling templates to Zig functions at build time.
Note: Compiled templates currently have some code generation issues and are disabled by default.
To try compiled templates:
-
Compile templates:
# From demo directory ./compile_templates.sh # Or manually from project root cd ../.. zig build demo-compile-templatesThis generates compiled templates in
generated/root.zig -
Enable in code:
- Open
src/main.zig - Set
USE_COMPILED_TEMPLATES = true
- Open
-
Build and run:
zig build run
The build.zig automatically detects if generated/ exists and includes the templates module.
Template Structure
views/
├── layouts/ # Layout templates
│ └── base.pug
├── pages/ # Page templates
│ ├── home.pug
│ ├── products.pug
│ ├── cart.pug
│ └── ...
├── partials/ # Reusable partials
│ ├── header.pug
│ ├── footer.pug
│ └── head.pug
├── mixins/ # Reusable components
│ ├── product-card.pug
│ ├── buttons.pug
│ ├── forms.pug
│ └── ...
└── includes/ # Other includes
└── ...
Known Issues with Compiled Templates
The template code generation (src/tpl_compiler/zig_codegen.zig) has some bugs:
helpers.zigimport paths need to be relative- Double quotes being escaped incorrectly in string literals
- Field names with dots causing syntax errors
- Some undefined variables in generated code
These will be fixed in a future update. For now, runtime templates work perfectly!