Remove main.zig CLI executable
Library-only project - examples are in src/examples/
This commit is contained in:
41
build.zig
41
build.zig
@@ -8,37 +8,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
.target = target,
|
.target = target,
|
||||||
});
|
});
|
||||||
|
|
||||||
const exe = b.addExecutable(.{
|
|
||||||
.name = "pugz",
|
|
||||||
.root_module = b.createModule(.{
|
|
||||||
.root_source_file = b.path("src/main.zig"),
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
.imports = &.{
|
|
||||||
.{ .name = "pugz", .module = mod },
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
b.installArtifact(exe);
|
|
||||||
const run_step = b.step("run", "Run the app");
|
|
||||||
|
|
||||||
const run_cmd = b.addRunArtifact(exe);
|
|
||||||
run_step.dependOn(&run_cmd.step);
|
|
||||||
|
|
||||||
// By making the run step depend on the default step, it will be run from the
|
|
||||||
// installation directory rather than directly from within the cache directory.
|
|
||||||
run_cmd.step.dependOn(b.getInstallStep());
|
|
||||||
|
|
||||||
// This allows the user to pass arguments to the application in the build
|
|
||||||
// command itself, like this: `zig build run -- arg1 arg2 etc`
|
|
||||||
if (b.args) |args| {
|
|
||||||
run_cmd.addArgs(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates an executable that will run `test` blocks from the provided module.
|
// Creates an executable that will run `test` blocks from the provided module.
|
||||||
// Here `mod` needs to define a target, which is why earlier we made sure to
|
|
||||||
// set the releative field.
|
|
||||||
const mod_tests = b.addTest(.{
|
const mod_tests = b.addTest(.{
|
||||||
.root_module = mod,
|
.root_module = mod,
|
||||||
});
|
});
|
||||||
@@ -46,16 +16,6 @@ pub fn build(b: *std.Build) void {
|
|||||||
// A run step that will run the test executable.
|
// A run step that will run the test executable.
|
||||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
const run_mod_tests = b.addRunArtifact(mod_tests);
|
||||||
|
|
||||||
// Creates an executable that will run `test` blocks from the executable's
|
|
||||||
// root module. Note that test executables only test one module at a time,
|
|
||||||
// hence why we have to create two separate ones.
|
|
||||||
const exe_tests = b.addTest(.{
|
|
||||||
.root_module = exe.root_module,
|
|
||||||
});
|
|
||||||
|
|
||||||
// A run step that will run the second test executable.
|
|
||||||
const run_exe_tests = b.addRunArtifact(exe_tests);
|
|
||||||
|
|
||||||
// Integration tests - general template tests
|
// Integration tests - general template tests
|
||||||
const general_tests = b.addTest(.{
|
const general_tests = b.addTest(.{
|
||||||
.root_module = b.createModule(.{
|
.root_module = b.createModule(.{
|
||||||
@@ -100,7 +60,6 @@ pub fn build(b: *std.Build) void {
|
|||||||
// make the two of them run in parallel.
|
// make the two of them run in parallel.
|
||||||
const test_step = b.step("test", "Run all tests");
|
const test_step = b.step("test", "Run all tests");
|
||||||
test_step.dependOn(&run_mod_tests.step);
|
test_step.dependOn(&run_mod_tests.step);
|
||||||
test_step.dependOn(&run_exe_tests.step);
|
|
||||||
test_step.dependOn(&run_general_tests.step);
|
test_step.dependOn(&run_general_tests.step);
|
||||||
test_step.dependOn(&run_doctype_tests.step);
|
test_step.dependOn(&run_doctype_tests.step);
|
||||||
test_step.dependOn(&run_inheritance_tests.step);
|
test_step.dependOn(&run_inheritance_tests.step);
|
||||||
|
|||||||
62
src/main.zig
62
src/main.zig
@@ -1,62 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const pugz = @import("pugz");
|
|
||||||
|
|
||||||
pub fn main() !void {
|
|
||||||
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
|
|
||||||
defer _ = gpa.deinit();
|
|
||||||
|
|
||||||
// Use arena allocator - recommended for templates (all memory freed at once)
|
|
||||||
var arena = std.heap.ArenaAllocator.init(gpa.allocator());
|
|
||||||
defer arena.deinit();
|
|
||||||
const allocator = arena.allocator();
|
|
||||||
|
|
||||||
std.debug.print("=== Pugz Template Engine ===\n\n", .{});
|
|
||||||
|
|
||||||
// Simple API: renderTemplate - one function call does everything
|
|
||||||
std.debug.print("--- Simple API (recommended for servers) ---\n", .{});
|
|
||||||
const html = try pugz.renderTemplate(allocator,
|
|
||||||
\\doctype html
|
|
||||||
\\html
|
|
||||||
\\ head
|
|
||||||
\\ title= title
|
|
||||||
\\ body
|
|
||||||
\\ h1 Hello, #{name}!
|
|
||||||
\\ p Welcome to Pugz.
|
|
||||||
\\ ul
|
|
||||||
\\ each item in items
|
|
||||||
\\ li= item
|
|
||||||
, .{
|
|
||||||
.title = "My Page",
|
|
||||||
.name = "World",
|
|
||||||
.items = &[_][]const u8{ "First", "Second", "Third" },
|
|
||||||
});
|
|
||||||
std.debug.print("{s}\n", .{html});
|
|
||||||
|
|
||||||
// Advanced API: parse once, render multiple times with different data
|
|
||||||
std.debug.print("--- Advanced API (parse once, render many) ---\n", .{});
|
|
||||||
|
|
||||||
const source =
|
|
||||||
\\p Hello, #{name}!
|
|
||||||
;
|
|
||||||
|
|
||||||
// Tokenize & Parse (do this once)
|
|
||||||
var lexer = pugz.Lexer.init(allocator, source);
|
|
||||||
const tokens = try lexer.tokenize();
|
|
||||||
var parser = pugz.Parser.init(allocator, tokens);
|
|
||||||
const doc = try parser.parse();
|
|
||||||
|
|
||||||
// Render multiple times with different data
|
|
||||||
const html1 = try pugz.render(allocator, doc, .{ .name = "Alice" });
|
|
||||||
const html2 = try pugz.render(allocator, doc, .{ .name = "Bob" });
|
|
||||||
|
|
||||||
std.debug.print("Render 1: {s}", .{html1});
|
|
||||||
std.debug.print("Render 2: {s}", .{html2});
|
|
||||||
}
|
|
||||||
|
|
||||||
test "simple test" {
|
|
||||||
const gpa = std.testing.allocator;
|
|
||||||
var list: std.ArrayListUnmanaged(i32) = .empty;
|
|
||||||
defer list.deinit(gpa);
|
|
||||||
try list.append(gpa, 42);
|
|
||||||
try std.testing.expectEqual(@as(i32, 42), list.pop());
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user