feat: add include demo page to showcase include directive

- Add includes/some_partial.pug partial in demo views
- Add pages/include-demo.pug page using include directive
- Add /include-demo route in demo server
- Add link to include demo in about page
- Fix test_includes.zig path in build.zig
- Add test_views for include testing
This commit is contained in:
2026-01-25 16:35:27 +05:30
parent 7bcb79c7bc
commit 9d3b729c6c
9 changed files with 59 additions and 2 deletions

View File

@@ -5,7 +5,7 @@
.minimum_zig_version = "0.15.2",
.dependencies = .{
.pugz = .{
.path = "../..",
.path = "../../..",
},
.httpz = .{
.url = "git+https://github.com/karlseguin/http.zig?ref=master#9ef2ffe8d611ff2e1081e5cf39cb4632c145c5b9",

View File

@@ -301,6 +301,18 @@ fn about(app: *App, _: *httpz.Request, res: *httpz.Response) !void {
res.body = html;
}
fn includeDemo(app: *App, _: *httpz.Request, res: *httpz.Response) !void {
const html = app.view.render(res.arena, "pages/include-demo", .{
.title = "Include Demo",
.cartCount = "2",
}) catch |err| {
return renderError(res, err);
};
res.content_type = .HTML;
res.body = html;
}
fn notFound(app: *App, _: *httpz.Request, res: *httpz.Response) !void {
res.status = 404;
@@ -389,6 +401,7 @@ pub fn main() !void {
router.get("/products/:id", productDetail, .{});
router.get("/cart", cart, .{});
router.get("/about", about, .{});
router.get("/include-demo", includeDemo, .{});
// Static files
router.get("/css/*", serveStatic, .{});
@@ -410,6 +423,7 @@ pub fn main() !void {
\\ GET /products/:id - Product detail
\\ GET /cart - Shopping cart
\\ GET /about - About page
\\ GET /include-demo - Include directive demo
\\
\\ Press Ctrl+C to stop.
\\

View File

@@ -0,0 +1,4 @@
.info-box
h3 Included Partial
p This content comes from includes/some_partial.pug
p It demonstrates the include directive for reusable template fragments.

View File

@@ -47,5 +47,7 @@ block content
a(href="https://github.com/ankitpatial/pugz") GitHub Repository
li
a(href="/products") View Products
li
a(href="/include-demo") Include Demo
li
a(href="/") Back to Home

View File

@@ -0,0 +1,20 @@
extends layouts/base.pug
block title
title Include Demo | Pugz Store
block content
section.page-header
.container
h1 Include Demo
p Demonstrating the include directive
section.section
.container
h2 Content from this page
p The box below is included from a separate partial file.
include includes/some_partial.pug
h2 After the include
p This content comes after the included partial.