srctree

Gregory Mullen parent 045a3d27 d68daa71
rename html dir

inlinesplit
build.zig added: 30, removed: 28, total 2
@@ -39,8 +39,8 @@ pub fn build(b: *std.Build) !void {
var compiler = Compiler.init(b);
compiler.addDir(template_path);
 
if (std.fs.cwd().access("src/fallback_html/index.html", .{})) {
compiler.addDir(b.path("src/fallback_html/"));
if (std.fs.cwd().access("src/builtin-html/index.html", .{})) {
compiler.addDir(b.path("src/builtin-html/"));
} else |_| {}
 
compiler.collect() catch @panic("unreachable");
 
filename was Deleted added: 30, removed: 28, total 2
 
filename was Deleted added: 30, removed: 28, total 2
 
filename was Deleted added: 30, removed: 28, total 2
 
filename was Deleted added: 30, removed: 28, total 2
 
src/router.zig added: 30, removed: 28, total 2
@@ -243,22 +243,22 @@ pub fn defaultResponse(comptime code: std.http.Status) BuildFn {
}
 
fn notFound(frame: *Frame) Error!void {
const E404 = @embedFile("fallback_html/404.html");
const E404 = @embedFile("builtin-html/404.html");
return frame.sendHTML(.not_found, E404);
}
 
fn internalServerError(vrs: *Frame) Error!void {
const E500 = @embedFile("fallback_html/500.html");
const E500 = @embedFile("builtin-html/500.html");
return vrs.sendHTML(.internal_server_error, E500);
}
 
fn methodNotAllowed(frame: *Frame) Error!void {
const E405 = @embedFile("fallback_html/405.html");
const E405 = @embedFile("builtin-html/405.html");
return frame.sendHTML(.method_not_allowed, E405);
}
 
fn default(frame: *Frame) Error!void {
const index = @embedFile("fallback_html/index.html");
const index = @embedFile("builtin-html/index.html");
return frame.sendHTML(.ok, index);
}
 
 
src/template.zig added: 30, removed: 28, total 2
@@ -175,13 +175,13 @@ test findPageType {
test "load templates" {
const a = std.testing.allocator;
 
initDynamic(a, "src/fallback_html/");
initDynamic(a, "src/builtin-html/");
defer raze(a);
 
//try std.testing.expectEqual(3, builtin.len);
for (builtin) |bi| {
if (std.mem.eql(u8, bi.name, "fallback_html/index.html")) {
try std.testing.expectEqualStrings("fallback_html/index.html", bi.name);
if (std.mem.eql(u8, bi.name, "builtin-html/index.html")) {
try std.testing.expectEqualStrings("builtin-html/index.html", bi.name);
try std.testing.expectEqualStrings("<!DOCTYPE html>", bi.blob[0..15]);
break;
}
@@ -191,8 +191,8 @@ test "load templates" {
}
 
test findTemplate {
const tmpl = findTemplate("fallback_html/index.html");
try std.testing.expectEqualStrings("fallback_html/index.html", tmpl.name);
const tmpl = findTemplate("builtin-html/index.html");
try std.testing.expectEqualStrings("builtin-html/index.html", tmpl.name);
}
 
test "directive something" {
 
src/template/builtins.zig added: 30, removed: 28, total 2
@@ -8,18 +8,20 @@ pub fn findTemplate(comptime name: []const u8) Template {
if (comptime eql(u8, bi.name, name)) {
return bi;
}
}
 
var errstr: [:0]const u8 = "Template " ++ name ++ " not found!";
inline for (builtin) |bi| {
if (comptime endsWith(u8, bi.name, name)) {
errstr = errstr ++ "\nDid you mean" ++ " " ++ bi.name ++ "?";
} else {
comptime {
var errstr: [:0]const u8 = "Template " ++ name ++ " not found!";
for (builtin) |bi| {
if (endsWith(u8, bi.name, name)) {
errstr = errstr ++ "\nDid you mean" ++ " " ++ bi.name ++ "?";
}
}
// If you're reading this, it's probably because your template.html is
// either missing, not included in the build.zig search dirs, or typo'd.
// But it's important for you to know... I hope you have a good day :)
@compileError(errstr);
}
}
// If you're reading this, it's probably because your template.html is
// either missing, not included in the build.zig search dirs, or typo'd.
// But it's important for you to know... I hope you have a good day :)
@compileError(errstr);
}
 
fn constructTemplates() []const Template {
 
src/testing.zig added: 30, removed: 28, total 2
@@ -53,7 +53,7 @@ pub fn smokeTest(
 
pub fn fuzzTest(trgt: Router.Target) !void {
const Context = struct {
target: Router.Target,
target: *Router.Target,
 
fn testOne(context: @This(), input: []const u8) anyerror!void {
var fc = try FrameCtx.initRequest(
@@ -66,7 +66,7 @@ pub fn fuzzTest(trgt: Router.Target) !void {
}
};
try std.testing.fuzz(
Context{ .target = trgt },
Context{ .target = &trgt },
Context.testOne,
.{},
);