diff --git a/build.zig b/build.zig index 8407f87..f86691f 100644 --- a/build.zig +++ b/build.zig @@ -146,7 +146,12 @@ pub fn jetzigInit(b: *std.Build, exe: *std.Build.Step.Compile, options: JetzigIn }); exe.root_module.addImport("routes", routes_module); - routes_module.addImport("jetzig", jetzig_module); + + var it = exe.root_module.import_table.iterator(); + while (it.next()) |import| { + routes_module.addImport(import.key_ptr.*, import.value_ptr.*); + exe_static_routes.root_module.addImport(import.key_ptr.*, import.value_ptr.*); + } exe_static_routes.root_module.addImport("routes", routes_module); exe_static_routes.root_module.addImport("jetzig", jetzig_module); diff --git a/cli/commands/init.zig b/cli/commands/init.zig index 87ace36..a6758b0 100644 --- a/cli/commands/init.zig +++ b/cli/commands/init.zig @@ -191,6 +191,13 @@ pub fn run( 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. // const git_setup = false; // if (git_setup) try gitSetup(allocator, install_dir); diff --git a/demo/build.zig b/demo/build.zig index ffa5359..8f2e0ae 100644 --- a/demo/build.zig +++ b/demo/build.zig @@ -12,6 +12,12 @@ pub fn build(b: *std.Build) !void { .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, .{}); b.installArtifact(exe); diff --git a/demo/build.zig.zon b/demo/build.zig.zon index 321158c..649531f 100644 --- a/demo/build.zig.zon +++ b/demo/build.zig.zon @@ -6,6 +6,10 @@ .jetzig = .{ .path = "../", }, + .iguanas = .{ + .url = "https://github.com/jetzig-framework/iguanas/archive/89c2abf29de0bc31054a9a6feac5a6a83bab0459.tar.gz", + .hash = "12202fd319a5ab4e124b00e8ddea474d07c19c4e005d77b6c29fc44860904ea01a5c", + }, }, .paths = .{ // This makes *all* files, recursively, included in this package. It is generally diff --git a/demo/src/app/views/iguanas.zig b/demo/src/app/views/iguanas.zig index e96c180..3229685 100644 --- a/demo/src/app/views/iguanas.zig +++ b/demo/src/app/views/iguanas.zig @@ -1,5 +1,6 @@ const std = @import("std"); 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 /// references `{zmpl.content}`. @@ -11,7 +12,21 @@ const jetzig = @import("jetzig"); /// and `demo/src/app/views/iguanas/index.zmpl` pub const layout = "application"; -pub fn index(request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View { - _ = data; +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + 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); } diff --git a/demo/src/app/views/iguanas/index.zmpl b/demo/src/app/views/iguanas/index.zmpl index 76457d0..7651164 100644 --- a/demo/src/app/views/iguanas/index.zmpl +++ b/demo/src/app/views/iguanas/index.zmpl @@ -1,3 +1,6 @@