feat: add template inheritance (extends/block) support
- ViewEngine now supports extends and named blocks - Each route gets exclusive cached AST (no shared parent layouts) - Fix iteration over struct arrays in each loops - Add demo app with full e-commerce layout using extends - Serve static files from public folder - Bump version to 0.3.0
This commit is contained in:
61
build.zig
61
build.zig
@@ -3,10 +3,19 @@ const std = @import("std");
|
||||
pub fn build(b: *std.Build) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
// Get cache.zig dependency
|
||||
const cache_dep = b.dependency("cache", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const mod = b.addModule("pugz", .{
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{
|
||||
.{ .name = "cache", .module = cache_dep.module("cache") },
|
||||
},
|
||||
});
|
||||
|
||||
// Creates an executable that will run `test` blocks from the provided module.
|
||||
@@ -17,6 +26,32 @@ pub fn build(b: *std.Build) void {
|
||||
// A run step that will run the test executable.
|
||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
||||
|
||||
// Source file unit tests (lexer, parser, runtime, etc.)
|
||||
const source_files_with_tests = [_][]const u8{
|
||||
"src/lexer.zig",
|
||||
"src/parser.zig",
|
||||
"src/runtime.zig",
|
||||
"src/template.zig",
|
||||
"src/codegen.zig",
|
||||
"src/strip_comments.zig",
|
||||
"src/linker.zig",
|
||||
"src/load.zig",
|
||||
"src/error.zig",
|
||||
"src/pug.zig",
|
||||
};
|
||||
|
||||
var source_test_steps: [source_files_with_tests.len]*std.Build.Step.Run = undefined;
|
||||
inline for (source_files_with_tests, 0..) |file, i| {
|
||||
const file_tests = b.addTest(.{
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path(file),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
}),
|
||||
});
|
||||
source_test_steps[i] = b.addRunArtifact(file_tests);
|
||||
}
|
||||
|
||||
// Integration tests - general template tests
|
||||
const general_tests = b.addTest(.{
|
||||
.root_module = b.createModule(.{
|
||||
@@ -62,6 +97,10 @@ pub fn build(b: *std.Build) void {
|
||||
test_step.dependOn(&run_general_tests.step);
|
||||
test_step.dependOn(&run_doctype_tests.step);
|
||||
test_step.dependOn(&run_check_list_tests.step);
|
||||
// Add source file tests
|
||||
for (&source_test_steps) |step| {
|
||||
test_step.dependOn(&step.step);
|
||||
}
|
||||
|
||||
// Individual test steps
|
||||
const test_general_step = b.step("test-general", "Run general template tests");
|
||||
@@ -72,6 +111,9 @@ pub fn build(b: *std.Build) void {
|
||||
|
||||
const test_unit_step = b.step("test-unit", "Run unit tests (lexer, parser, etc.)");
|
||||
test_unit_step.dependOn(&run_mod_tests.step);
|
||||
for (&source_test_steps) |step| {
|
||||
test_unit_step.dependOn(&step.step);
|
||||
}
|
||||
|
||||
const test_check_list_step = b.step("test-check-list", "Run check_list template tests");
|
||||
test_check_list_step.dependOn(&run_check_list_tests.step);
|
||||
@@ -94,4 +136,23 @@ pub fn build(b: *std.Build) void {
|
||||
run_bench.setCwd(b.path("."));
|
||||
const bench_step = b.step("bench", "Run benchmark");
|
||||
bench_step.dependOn(&run_bench.step);
|
||||
|
||||
// Test includes example
|
||||
const test_includes_exe = b.addExecutable(.{
|
||||
.name = "test-includes",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("examples/test_includes.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.imports = &.{
|
||||
.{ .name = "pugz", .module = mod },
|
||||
},
|
||||
}),
|
||||
});
|
||||
b.installArtifact(test_includes_exe);
|
||||
|
||||
const run_test_includes = b.addRunArtifact(test_includes_exe);
|
||||
run_test_includes.setCwd(b.path("."));
|
||||
const test_includes_step = b.step("test-includes", "Test include/mixin rendering");
|
||||
test_includes_step.dependOn(&run_test_includes.step);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user