Genearte .zig verions of templates to use in production.
This commit is contained in:
13
benchmarks/compiled/friends.zig
Normal file
13
benchmarks/compiled/friends.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<div class=\"'friend'\"><h3>friend_name</h3><p>friend_email</p><p>friend_about</p><span class=\"'tag'\">tag_value</span></div>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
33
benchmarks/compiled/helpers.zig
Normal file
33
benchmarks/compiled/helpers.zig
Normal file
@@ -0,0 +1,33 @@
|
||||
// Auto-generated helpers for compiled Pug templates
|
||||
// This file is copied to the generated directory to provide shared utilities
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
/// Append HTML-escaped string to buffer
|
||||
pub fn appendEscaped(buf: *std.ArrayListUnmanaged(u8), allocator: std.mem.Allocator, str: []const u8) !void {
|
||||
for (str) |c| {
|
||||
switch (c) {
|
||||
'&' => try buf.appendSlice(allocator, "&"),
|
||||
'<' => try buf.appendSlice(allocator, "<"),
|
||||
'>' => try buf.appendSlice(allocator, ">"),
|
||||
'"' => try buf.appendSlice(allocator, """),
|
||||
'\'' => try buf.appendSlice(allocator, "'"),
|
||||
else => try buf.append(allocator, c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if a value is truthy (for conditionals)
|
||||
pub fn isTruthy(val: anytype) bool {
|
||||
const T = @TypeOf(val);
|
||||
return switch (@typeInfo(T)) {
|
||||
.bool => val,
|
||||
.int, .float => val != 0,
|
||||
.pointer => |ptr| switch (ptr.size) {
|
||||
.slice => val.len > 0,
|
||||
else => true,
|
||||
},
|
||||
.optional => if (val) |v| isTruthy(v) else false,
|
||||
else => true,
|
||||
};
|
||||
}
|
||||
13
benchmarks/compiled/if-expression.zig
Normal file
13
benchmarks/compiled/if-expression.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<p>Active</p><p>Inactive</p>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
13
benchmarks/compiled/projects-escaped.zig
Normal file
13
benchmarks/compiled/projects-escaped.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<li><a href=\"/project\">project_name</a>: project_description</li>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
10
benchmarks/compiled/root.zig
Normal file
10
benchmarks/compiled/root.zig
Normal file
@@ -0,0 +1,10 @@
|
||||
// Auto-generated by pug-compile
|
||||
// This file exports all compiled templates
|
||||
|
||||
pub const friends = @import("./friends.zig");
|
||||
pub const if_expression = @import("./if-expression.zig");
|
||||
pub const projects_escaped = @import("./projects-escaped.zig");
|
||||
pub const search_results = @import("./search-results.zig");
|
||||
pub const simple_0 = @import("./simple-0.zig");
|
||||
pub const simple_1 = @import("./simple-1.zig");
|
||||
pub const simple_2 = @import("./simple-2.zig");
|
||||
13
benchmarks/compiled/search-results.zig
Normal file
13
benchmarks/compiled/search-results.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<div><h3>result_title</h3><span>$result_price</span></div>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
13
benchmarks/compiled/simple-0.zig
Normal file
13
benchmarks/compiled/simple-0.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<p>Hello World</p>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
13
benchmarks/compiled/simple-1.zig
Normal file
13
benchmarks/compiled/simple-1.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<!DOCTYPE html><html><head><title>My Site</title></head><body><h1>Welcome</h1><p>This is a simple page</p></body></html>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
13
benchmarks/compiled/simple-2.zig
Normal file
13
benchmarks/compiled/simple-2.zig
Normal file
@@ -0,0 +1,13 @@
|
||||
const std = @import("std");
|
||||
const helpers = @import("helpers.zig");
|
||||
|
||||
pub const Data = struct {};
|
||||
|
||||
pub fn render(allocator: std.mem.Allocator, _: Data) ![]const u8 {
|
||||
var buf: std.ArrayListUnmanaged(u8) = .{};
|
||||
defer buf.deinit(allocator);
|
||||
|
||||
try buf.appendSlice(allocator, "<h1>Header</h1><h2>Header2</h2><h3>Header3</h3><h4>Header4</h4><h5>Header5</h5><h6>Header6</h6><ul><li>item1</li><li>item2</li><li>item3</li></ul>");
|
||||
|
||||
return buf.toOwnedSlice(allocator);
|
||||
}
|
||||
Reference in New Issue
Block a user