mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00
0.13 support
Add support for 0.13. For now, we can be compatible with both 0.12 and 0.13. We will drop 0.12 after a while.
This commit is contained in:
parent
9d12b5c717
commit
6b940e8a53
@ -173,7 +173,7 @@ pub fn jetzigInit(b: *std.Build, exe: *std.Build.Step.Compile, options: JetzigIn
|
||||
if (!std.mem.eql(u8, ".zig", std.fs.path.extension(entry.path))) continue;
|
||||
|
||||
const stat = try src_dir.statFile(entry.path);
|
||||
const src_data = try src_dir.readFileAlloc(b.allocator, entry.path, stat.size);
|
||||
const src_data = try src_dir.readFileAlloc(b.allocator, entry.path, @intCast(stat.size));
|
||||
defer b.allocator.free(src_data);
|
||||
|
||||
const relpath = try std.fs.path.join(b.allocator, &[_][]const u8{ "src", entry.path });
|
||||
@ -216,7 +216,7 @@ fn generateMarkdownFragments(b: *std.Build) ![]const u8 {
|
||||
}
|
||||
};
|
||||
const stat = try file.stat();
|
||||
const source = try file.readToEndAllocOptions(b.allocator, stat.size, null, @alignOf(u8), 0);
|
||||
const source = try file.readToEndAllocOptions(b.allocator, @intCast(stat.size), null, @alignOf(u8), 0);
|
||||
if (try getMarkdownFragmentsSource(b.allocator, source)) |markdown_fragments_source| {
|
||||
return try std.fmt.allocPrint(b.allocator,
|
||||
\\const std = @import("std");
|
||||
|
@ -3,12 +3,12 @@
|
||||
.version = "0.0.0",
|
||||
.dependencies = .{
|
||||
.zmd = .{
|
||||
.url = "https://github.com/jetzig-framework/zmd/archive/45a9ff0e3a55b4758163abad5a601bd3ef8127a8.tar.gz",
|
||||
.hash = "122067a3107499e4b561a883a9f1e9f39662c4b87249a2e4e630279bd91ab7840230",
|
||||
.url = "https://github.com/jetzig-framework/zmd/archive/557ab8a29c0f7b5d096070cde2858cf27da8b0f1.tar.gz",
|
||||
.hash = "1220482f07f2bbaef335f20d6890c15a1e14739950b784232bc69182423520e058a5",
|
||||
},
|
||||
.zmpl = .{
|
||||
.url = "https://github.com/jetzig-framework/zmpl/archive/9712b85e61f33879f388d5e1829856e326c53822.tar.gz",
|
||||
.hash = "1220b185cf8316ae5ad6dd7d45bea278575391986b7d8233a9d9b2c342e339d65ac0",
|
||||
.url = "https://github.com/jetzig-framework/zmpl/archive/046c05d376a4fe89d86c52596baa18137891cd87.tar.gz",
|
||||
.hash = "1220d8890b1161e4356d2c59d4b88280566d55480dae840b6f5dae34bf852bef6b56",
|
||||
},
|
||||
.args = .{
|
||||
.url = "https://github.com/MasterQ32/zig-args/archive/01d72b9a0128c474aeeb9019edd48605fa6d95f7.tar.gz",
|
||||
|
@ -42,7 +42,12 @@ pub fn run(
|
||||
var sub_args = std.ArrayList([]const u8).init(allocator);
|
||||
defer sub_args.deinit();
|
||||
|
||||
const map = std.ComptimeStringMap(Generator, .{
|
||||
var available_buf = std.ArrayList([]const u8).init(allocator);
|
||||
defer available_buf.deinit();
|
||||
|
||||
// XXX: 0.12 Compatibility
|
||||
const map = if (@hasDecl(std, "ComptimeStringMap")) blk: {
|
||||
const inner_map = std.ComptimeStringMap(Generator, .{
|
||||
.{ "view", .view },
|
||||
.{ "partial", .partial },
|
||||
.{ "layout", .layout },
|
||||
@ -51,10 +56,22 @@ pub fn run(
|
||||
.{ "middleware", .middleware },
|
||||
.{ "secret", .secret },
|
||||
});
|
||||
for (inner_map.kvs) |kv| try available_buf.append(kv.key);
|
||||
break :blk inner_map;
|
||||
} else if (@hasDecl(std, "StaticStringMap")) blk: {
|
||||
const inner_map = std.StaticStringMap(Generator).initComptime(.{
|
||||
.{ "view", .view },
|
||||
.{ "partial", .partial },
|
||||
.{ "layout", .layout },
|
||||
.{ "job", .job },
|
||||
.{ "mailer", .mailer },
|
||||
.{ "middleware", .middleware },
|
||||
.{ "secret", .secret },
|
||||
});
|
||||
for (inner_map.keys()) |key| try available_buf.append(key);
|
||||
break :blk inner_map;
|
||||
} else unreachable;
|
||||
|
||||
var available_buf = std.ArrayList([]const u8).init(allocator);
|
||||
defer available_buf.deinit();
|
||||
for (map.kvs) |kv| try available_buf.append(kv.key);
|
||||
const available_help = try std.mem.join(allocator, "|", available_buf.items);
|
||||
defer allocator.free(available_help);
|
||||
|
||||
|
@ -45,7 +45,7 @@ pub fn initDataModule(build: *std.Build) !*std.Build.Module {
|
||||
const stat = try dir.statFile(path);
|
||||
const encoded = base64Encode(
|
||||
build.allocator,
|
||||
try dir.readFileAlloc(build.allocator, path, stat.size),
|
||||
try dir.readFileAlloc(build.allocator, path, @intCast(stat.size)),
|
||||
);
|
||||
defer build.allocator.free(encoded);
|
||||
|
||||
|
@ -37,7 +37,7 @@ const Quote = struct {
|
||||
fn randomQuote(allocator: std.mem.Allocator) !Quote {
|
||||
const path = "src/app/config/quotes.json";
|
||||
const stat = try std.fs.cwd().statFile(path);
|
||||
const json = try std.fs.cwd().readFileAlloc(allocator, path, stat.size);
|
||||
const json = try std.fs.cwd().readFileAlloc(allocator, path, @intCast(stat.size));
|
||||
const quotes = try std.json.parseFromSlice([]Quote, allocator, json, .{});
|
||||
return quotes.value[std.crypto.random.intRangeLessThan(usize, 0, quotes.value.len)];
|
||||
}
|
||||
|
@ -16,9 +16,3 @@
|
||||
<div>Take a look at the <span class="font-mono">/demo/src/app/</span> directory to see how this application works.</div>
|
||||
<div>Visit <a class="font-bold text-[#39b54a]" href="https://jetzig.dev/">jetzig.dev</a> to get started.</div>
|
||||
</div>
|
||||
|
||||
@markdown {
|
||||
# Hello
|
||||
|
||||
[foobar](https://www.google.com)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ const JsonMimeType = struct {
|
||||
pub fn generateMimeModule(build: *std.Build) !*std.Build.Module {
|
||||
const file = try std.fs.openFileAbsolute(build.pathFromRoot("src/jetzig/http/mime/mimeData.json"), .{});
|
||||
const stat = try file.stat();
|
||||
const json = try file.readToEndAlloc(build.allocator, stat.size);
|
||||
const json = try file.readToEndAlloc(build.allocator, @intCast(stat.size));
|
||||
defer build.allocator.free(json);
|
||||
|
||||
const parsed_mime_types = try std.json.parseFromSlice(
|
||||
|
@ -296,7 +296,7 @@ const RouteSet = struct {
|
||||
|
||||
fn generateRoutesForView(self: *Routes, dir: std.fs.Dir, path: []const u8) !RouteSet {
|
||||
const stat = try dir.statFile(path);
|
||||
const source = try dir.readFileAllocOptions(self.allocator, path, stat.size, null, @alignOf(u8), 0);
|
||||
const source = try dir.readFileAllocOptions(self.allocator, path, @intCast(stat.size), null, @alignOf(u8), 0);
|
||||
defer self.allocator.free(source);
|
||||
|
||||
self.ast = try std.zig.Ast.parse(self.allocator, source, .zig);
|
||||
|
@ -33,7 +33,7 @@ pub fn render(
|
||||
else => err,
|
||||
};
|
||||
};
|
||||
const markdown_content = std.fs.cwd().readFileAlloc(allocator, full_path, stat.size) catch |err| {
|
||||
const markdown_content = std.fs.cwd().readFileAlloc(allocator, full_path, @intCast(stat.size)) catch |err| {
|
||||
switch (err) {
|
||||
error.FileNotFound => return null,
|
||||
else => return err,
|
||||
|
Loading…
x
Reference in New Issue
Block a user