Release v0.1.14-pre
Pre-release
Pre-release
ZAP Release v0.1.14-pre
Updates
Community Patch: Mustache Revamp Update (BREAKING CHANGE)
Thanks to @sadbeast on GitHub, new Mustache functionality has been
added: file-based and partial templates! We took the opportunity to
simplify and ziggify the interface of the Mustache related functions.
- the
MustacheLoadArgs
struct has only optional slices for convenience - function names have been lower-cased
Here is the MustacheLoadArgs
struct used for passing into the Mustache
creation functions:
/// Mustache load args used in mustacheNew
pub const MustacheLoadArgs = struct {
/// optional filename, enables partial templates on filesystem
filename: ?[]const u8 = null,
/// optional string data. should be used if no filename is specified.
data: ?[]const u8 = null,
};
You can now create a Mustache
via the following functions:
/// use if both filename and data need to be passed
pub fn mustacheNew(load_args: MustacheLoadArgs) MustacheError!*Mustache;
/// use if only data needs to be passed
pub fn mustacheData(data: []const u8) MustacheError!*Mustache;
/// use if only filename needs to be passed
pub fn mustacheLoad(filename: []const u8) MustacheError!*Mustache;
So, real use cases look like this:
const lM = try zap.mustacheLoad("./src/tests/testtemplate.html");
const dM = try zap.mustacheData(template);
const cM = zap.mustacheNew(.{
.filename = "test.html",
.data = "{{=<< >>=}}<<>testpartial.html>>",
});
Again, many thanks to @sadbeast for improving the Mustache situation!
Using it
To use in your own projects, put this dependency into your build.zig.zon
:
// zap v0.1.14-pre
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
.hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",
}
Here is a complete build.zig.zon
example:
.{
.name = "My example project",
.version = "0.0.1",
.dependencies = .{
// zap v0.1.14-pre
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.14-pre.tar.gz",
.hash = "122067d12bc7abb93f7ce623f61b94cadfdb180cef12da6559d092e6b374202acda3",
}
}
}
Then, in your build.zig
's build
function, add the following before exe.install()
:
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
});
exe.addModule("zap", zap.module("zap"));
exe.linkLibrary(zap.artifact("facil.io"));