From b1a21d63df3423649af27b1df552880384ccfe71 Mon Sep 17 00:00:00 2001 From: Samuel Webb Date: Fri, 13 Sep 2024 13:44:38 -0400 Subject: [PATCH] Update Jetzig --- .gitignore | 4 ++-- build.zig.zon | 4 ++-- src/app/views/music.zig | 41 ++++++++++++++++++++++++++++++++++ src/app/views/music/index.zmpl | 2 ++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/app/views/music.zig create mode 100644 src/app/views/music/index.zmpl diff --git a/.gitignore b/.gitignore index 9f6d7b4..23cb6fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ zig-out/ -zig-cache/ +.zig-cache/ *.core static/ .jetzig -src/app/database/data.db-journal \ No newline at end of file +src/app/database/data.db-journal diff --git a/build.zig.zon b/build.zig.zon index ff7ee12..849ffe0 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -15,8 +15,8 @@ // Once all dependencies are fetched, `zig build` no longer requires // internet connectivity. .dependencies = .{ .jetzig = .{ - .url = "https://github.com/jetzig-framework/jetzig/archive/88abe2243d87b28ad110c5fe9fe90b716a6c6583.tar.gz", - .hash = "12200d15cef72d4c37a01c930db53c3ffafdc05142462afddeab818701a0291327d1", + .url = "https://github.com/jetzig-framework/jetzig/archive/dda433bb73000614482af10a277d47dc9d89600c.tar.gz", + .hash = "12202ce84b803a8b300c91d98afbc7c326298b55a23bf05cf603182e934b621008ec", }, .iguanas = .{ .url = "https://github.com/jetzig-framework/iguanas/archive/89c2abf29de0bc31054a9a6feac5a6a83bab0459.tar.gz", .hash = "12202fd319a5ab4e124b00e8ddea474d07c19c4e005d77b6c29fc44860904ea01a5c", diff --git a/src/app/views/music.zig b/src/app/views/music.zig new file mode 100644 index 0000000..4dd0d07 --- /dev/null +++ b/src/app/views/music.zig @@ -0,0 +1,41 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub const static_params = .{ + .index = .{ + //.{ .params = .{ .foo = "hi", .bar = "bye" } }, + //.{ .params = .{ .foo = "hello", .bar = "goodbye" } }, + }, + //.get = .{ + // .{ .id = "1", .params = .{ .foo = "hi", .bar = "bye" } }, + // .{ .id = "2", .params = .{ .foo = "hello", .bar = "goodbye" } }, + //}, +}; + +pub fn index(request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View { + var root = try data.object(); + + const params = try request.params(); + + if (params.get("foo")) |foo| try root.put("foo", foo); + if (params.get("foo") == null) try root.put("foo", data.string("no foo")); + if (params.get("bar")) |bar| try root.put("bar", bar); + if (params.get("bar") == null) try root.put("bar", data.string("no bar")); + + return request.render(.ok); +} + +//pub fn get(id: []const u8, request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View { +// var root = try data.object(); +// +// const params = try request.params(); +// +// if (std.mem.eql(u8, id, "1")) { +// try root.put("id", data.string("id is '1'")); +// } +// +// if (params.get("foo")) |foo| try root.put("foo", foo); +// if (params.get("bar")) |bar| try root.put("bar", bar); +// +// return request.render(.created); +//} \ No newline at end of file diff --git a/src/app/views/music/index.zmpl b/src/app/views/music/index.zmpl new file mode 100644 index 0000000..a14b357 --- /dev/null +++ b/src/app/views/music/index.zmpl @@ -0,0 +1,2 @@ +
{{.foo}}
+
{{.bar}}
\ No newline at end of file