Skip to content

Commit

Permalink
Merge pull request #46 from jetzig-framework/replicate-exe-imports
Browse files Browse the repository at this point in the history
Replicate exe imports
  • Loading branch information
bobf authored Mar 28, 2024
2 parents a702d12 + 29d1391 commit c2cc9c5
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
7 changes: 6 additions & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions cli/commands/init.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions demo/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions demo/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions demo/src/app/views/iguanas.zig
Original file line number Diff line number Diff line change
@@ -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}`.
Expand All @@ -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);
}
5 changes: 4 additions & 1 deletion demo/src/app/views/iguanas/index.zmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<div>
<span>Content goes here</span>
var it = zmpl.value.?.array.iterator();
while (it.next()) |iguana| {
<div>{(iguana.string.value)}</div>
}
</div>

0 comments on commit c2cc9c5

Please sign in to comment.