Add a dependency to demo app

Use as a regression test to ensure dependencies always work.
This commit is contained in:
Bob Farrell 2024-03-28 21:07:16 +00:00
parent e4709e0c73
commit 29d13917a6
6 changed files with 38 additions and 4 deletions

View File

@ -146,7 +146,6 @@ pub fn jetzigInit(b: *std.Build, exe: *std.Build.Step.Compile, options: JetzigIn
}); });
exe.root_module.addImport("routes", routes_module); exe.root_module.addImport("routes", routes_module);
routes_module.addImport("jetzig", jetzig_module);
var it = exe.root_module.import_table.iterator(); var it = exe.root_module.import_table.iterator();
while (it.next()) |import| { while (it.next()) |import| {

View File

@ -191,6 +191,13 @@ pub fn run(
github_url, github_url,
}); });
try util.runCommand(allocator, realpath, &[_][]const u8{
"zig",
"fetch",
"--save",
"https://github.com/jetzig-framework/iguanas/archive/89c2abf29de0bc31054a9a6feac5a6a83bab0459.tar.gz",
});
// TODO: Use arg or interactive prompt to do Git setup in net project, default to no. // TODO: Use arg or interactive prompt to do Git setup in net project, default to no.
// const git_setup = false; // const git_setup = false;
// if (git_setup) try gitSetup(allocator, install_dir); // if (git_setup) try gitSetup(allocator, install_dir);

View File

@ -12,6 +12,12 @@ pub fn build(b: *std.Build) !void {
.optimize = optimize, .optimize = optimize,
}); });
// Example dependency:
const iguanas_dep = b.dependency("iguanas", .{ .optimize = optimize, .target = target });
exe.root_module.addImport("iguanas", iguanas_dep.module("iguanas"));
// All dependencies **must** be added to imports above this line.
try jetzig.jetzigInit(b, exe, .{}); try jetzig.jetzigInit(b, exe, .{});
b.installArtifact(exe); b.installArtifact(exe);

View File

@ -6,6 +6,10 @@
.jetzig = .{ .jetzig = .{
.path = "../", .path = "../",
}, },
.iguanas = .{
.url = "https://github.com/jetzig-framework/iguanas/archive/89c2abf29de0bc31054a9a6feac5a6a83bab0459.tar.gz",
.hash = "12202fd319a5ab4e124b00e8ddea474d07c19c4e005d77b6c29fc44860904ea01a5c",
},
}, },
.paths = .{ .paths = .{
// This makes *all* files, recursively, included in this package. It is generally // This makes *all* files, recursively, included in this package. It is generally

View File

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const jetzig = @import("jetzig"); const jetzig = @import("jetzig");
const iguanas = @import("iguanas");
/// This example uses a layout. A layout is a template that exists in `src/app/views/layouts` and /// This example uses a layout. A layout is a template that exists in `src/app/views/layouts` and
/// references `{zmpl.content}`. /// references `{zmpl.content}`.
@ -11,7 +12,21 @@ const jetzig = @import("jetzig");
/// and `demo/src/app/views/iguanas/index.zmpl` /// and `demo/src/app/views/iguanas/index.zmpl`
pub const layout = "application"; pub const layout = "application";
pub fn index(request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View { pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View {
_ = data; var root = try data.array();
const params = try request.params();
const count = if (params.get("iguanas")) |param|
try std.fmt.parseInt(usize, param.string.value, 10)
else
10;
const iguanas_slice = try iguanas.iguanas(request.allocator, count);
for (iguanas_slice) |iguana| {
try root.append(data.string(iguana));
}
return request.render(.ok); return request.render(.ok);
} }

View File

@ -1,3 +1,6 @@
<div> <div>
<span>Content goes here</span> var it = zmpl.value.?.array.iterator();
while (it.next()) |iguana| {
<div>{(iguana.string.value)}</div>
}
</div> </div>