@@ -4,11 +4,12 @@ const httpz = @import("httpz");
44
55const Template = @import ("Template.zig" );
66
7- const RequestVariables = struct {
7+ pub const Context = struct {
88 request : * httpz.Request ,
9+ subpath : []const u8 ,
910
1011 fn print (context : * const anyopaque , writer : * std.Io.Writer , name : []const u8 ) anyerror ! bool {
11- const self : * const RequestVariables = @ptrCast (@alignCast (context ));
12+ const self : * const Context = @ptrCast (@alignCast (context ));
1213 var split = std .mem .splitScalar (u8 , name , '.' );
1314
1415 const first = split .next ().? ;
@@ -61,14 +62,17 @@ const RequestVariables = struct {
6162 } else {
6263 try writer .writeAll (cookies .header );
6364 }
65+ } else if (std .mem .eql (u8 , first , "subpath" )) {
66+ if (optional_second != null ) return false ;
67+ try writer .writeAll (self .subpath );
6468 } else {
6569 return false ;
6670 }
6771
6872 return true ;
6973 }
7074
71- fn variables (self : * const RequestVariables ) Template.Variables {
75+ fn variables (self : * const Context ) Template.Variables {
7276 return .{
7377 .context = @ptrCast (self ),
7478 .vtable = &.{
@@ -78,9 +82,7 @@ const RequestVariables = struct {
7882 }
7983};
8084
81- pub fn render (template : Template , request : * httpz.Request , writer : * std.Io.Writer ) ! void {
82- const request_variables = RequestVariables { .request = request };
83- const variables = request_variables .variables ();
84-
85+ pub fn render (template : Template , context : * const Context , writer : * std.Io.Writer ) ! void {
86+ const variables = context .variables ();
8587 try template .render (writer , variables , .{});
8688}
0 commit comments