Use templating system
This commit is contained in:
parent
305c5f8c92
commit
432a11dbc9
4 changed files with 16 additions and 10 deletions
|
@ -23,10 +23,15 @@ const api_pkg = std.build.Pkg{
|
||||||
.dependencies = &.{ util_pkg, sql_pkg },
|
.dependencies = &.{ util_pkg, sql_pkg },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const template_pkg = std.build.Pkg{
|
||||||
|
.name = "template",
|
||||||
|
.source = std.build.FileSource.relative("src/template/lib.zig"),
|
||||||
|
};
|
||||||
|
|
||||||
const main_pkg = std.build.Pkg{
|
const main_pkg = std.build.Pkg{
|
||||||
.name = "main",
|
.name = "main",
|
||||||
.source = std.build.FileSource.relative("src/main/main.zig"),
|
.source = std.build.FileSource.relative("src/main/main.zig"),
|
||||||
.dependencies = &.{ util_pkg, http_pkg, sql_pkg, api_pkg },
|
.dependencies = &.{ util_pkg, http_pkg, sql_pkg, api_pkg, template_pkg },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn build(b: *std.build.Builder) void {
|
pub fn build(b: *std.build.Builder) void {
|
||||||
|
@ -48,6 +53,7 @@ pub fn build(b: *std.build.Builder) void {
|
||||||
exe.addPackage(util_pkg);
|
exe.addPackage(util_pkg);
|
||||||
exe.addPackage(http_pkg);
|
exe.addPackage(http_pkg);
|
||||||
exe.addPackage(api_pkg);
|
exe.addPackage(api_pkg);
|
||||||
|
exe.addPackage(template_pkg);
|
||||||
|
|
||||||
exe.linkSystemLibrary("sqlite3");
|
exe.linkSystemLibrary("sqlite3");
|
||||||
exe.linkSystemLibrary("pq");
|
exe.linkSystemLibrary("pq");
|
||||||
|
|
|
@ -44,6 +44,8 @@ pub fn serveConn(conn: std.net.StreamServer.Connection, ctx: anytype, handler: a
|
||||||
.stream = conn.stream,
|
.stream = conn.stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std.log.debug("{any}", .{req});
|
||||||
|
std.log.debug("Opening handler", .{});
|
||||||
handler(ctx, &req, &res);
|
handler(ctx, &req, &res);
|
||||||
std.log.debug("done handling", .{});
|
std.log.debug("done handling", .{});
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,17 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>{[community_name]s}</title>
|
<title>{ .community.name }</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1>{[community_name]s}</h1>
|
<h1>{ .community.name }</h1>
|
||||||
Cluster Admin pseudocommunity
|
|
||||||
</header>
|
</header>
|
||||||
<form action="/login" method="post">
|
<form action="/login" method="post">
|
||||||
<h2>Login</h2>
|
<h2>Login</h2>
|
||||||
<label>
|
<label>
|
||||||
Username
|
Username
|
||||||
<div>@<input type="text" name="username" placeholder="xion" />@{[community_host]s}</div>
|
<div>@<input type="text" name="username" placeholder="xion" />@{.community.host}</div>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Password
|
Password
|
|
@ -1,4 +1,4 @@
|
||||||
const std = @import("std");
|
const template = @import("template");
|
||||||
|
|
||||||
pub const path = "/";
|
pub const path = "/";
|
||||||
pub const method = .GET;
|
pub const method = .GET;
|
||||||
|
@ -9,12 +9,11 @@ pub fn handler(_: anytype, res: anytype, srv: anytype) !void {
|
||||||
var stream = try res.open(.ok);
|
var stream = try res.open(.ok);
|
||||||
defer stream.close();
|
defer stream.close();
|
||||||
|
|
||||||
try std.fmt.format(stream.writer(), template, .{
|
try template.execute(stream.writer(), tmpl, .{
|
||||||
.community_name = srv.community.name,
|
.community = srv.community,
|
||||||
.community_host = srv.community.host,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try stream.finish();
|
try stream.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
const template = @embedFile("./index.fmt.html");
|
const tmpl = @embedFile("./index.tmpl.html");
|
||||||
|
|
Loading…
Reference in a new issue