Template helpers
This commit is contained in:
parent
58a0dd900f
commit
f33b4a856f
1 changed files with 14 additions and 6 deletions
|
@ -16,9 +16,7 @@ pub const notes = @import("./controllers/api/notes.zig");
|
|||
pub const streaming = @import("./controllers/api/streaming.zig");
|
||||
pub const timelines = @import("./controllers/api/timelines.zig");
|
||||
|
||||
const web = struct {
|
||||
const index = @import("./controllers/web/index.zig");
|
||||
};
|
||||
const web = @import("./controllers/web.zig");
|
||||
|
||||
pub fn routeRequest(api_source: anytype, req: *http.Request, res: *http.Response, alloc: std.mem.Allocator) void {
|
||||
// TODO: hashmaps?
|
||||
|
@ -54,9 +52,7 @@ const routes = .{
|
|||
follows.create,
|
||||
follows.query_followers,
|
||||
follows.query_following,
|
||||
|
||||
web.index,
|
||||
};
|
||||
} ++ web.routes;
|
||||
|
||||
fn parseRouteArgs(comptime route: []const u8, comptime Args: type, path: []const u8) !Args {
|
||||
var args: Args = undefined;
|
||||
|
@ -284,6 +280,18 @@ pub const Response = struct {
|
|||
self.opened = true;
|
||||
return self.res;
|
||||
}
|
||||
|
||||
pub fn template(self: *Self, status_code: http.Status, comptime templ: []const u8, data: anytype) !void {
|
||||
try self.headers.put("Content-Type", "text/html");
|
||||
|
||||
var stream = try self.open(status_code);
|
||||
defer stream.close();
|
||||
|
||||
const writer = stream.writer();
|
||||
try @import("template").execute(writer, templ, data);
|
||||
|
||||
try stream.finish();
|
||||
}
|
||||
};
|
||||
|
||||
const json_options = if (builtin.mode == .Debug)
|
||||
|
|
Loading…
Reference in a new issue