mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 23:24:09 +00:00
Merge pull request #59 from BrookJeynes/mustache-doc-comments
Mustache doc comments
This commit is contained in:
commit
29b90f0626
1 changed files with 11 additions and 8 deletions
|
@ -37,9 +37,9 @@ pub const Mustache = struct {
|
||||||
err: [*c]mustache_error_en,
|
err: [*c]mustache_error_en,
|
||||||
};
|
};
|
||||||
|
|
||||||
handler: *mustache_s,
|
/// Handle to the underlying fiobj mustache instance.
|
||||||
|
handle: *mustache_s,
|
||||||
|
|
||||||
pub const Status = enum(c_int) {};
|
|
||||||
pub const Error = error{
|
pub const Error = error{
|
||||||
MUSTACHE_ERR_TOO_DEEP,
|
MUSTACHE_ERR_TOO_DEEP,
|
||||||
MUSTACHE_ERR_CLOSURE_MISMATCH,
|
MUSTACHE_ERR_CLOSURE_MISMATCH,
|
||||||
|
@ -78,7 +78,7 @@ pub const Mustache = struct {
|
||||||
const ret = fiobj_mustache_new(args);
|
const ret = fiobj_mustache_new(args);
|
||||||
switch (err) {
|
switch (err) {
|
||||||
0 => return Self{
|
0 => return Self{
|
||||||
.handler = ret.?,
|
.handle = ret.?,
|
||||||
},
|
},
|
||||||
1 => return Error.MUSTACHE_ERR_TOO_DEEP,
|
1 => return Error.MUSTACHE_ERR_TOO_DEEP,
|
||||||
2 => return Error.MUSTACHE_ERR_CLOSURE_MISMATCH,
|
2 => return Error.MUSTACHE_ERR_CLOSURE_MISMATCH,
|
||||||
|
@ -110,7 +110,7 @@ pub const Mustache = struct {
|
||||||
|
|
||||||
/// Free the data backing a `Mustache` instance.
|
/// Free the data backing a `Mustache` instance.
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
fiobj_mustache_free(self.handler);
|
fiobj_mustache_free(self.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement these - fiobj_mustache.c
|
// TODO: implement these - fiobj_mustache.c
|
||||||
|
@ -139,8 +139,9 @@ pub const Mustache = struct {
|
||||||
|
|
||||||
/// Build the Mustache template; `deinit()` should be called on the build
|
/// Build the Mustache template; `deinit()` should be called on the build
|
||||||
/// result to free the data.
|
/// result to free the data.
|
||||||
/// TODO: This build is slow because it needs to translate to a FIOBJ data
|
// TODO: The build may be slow because it needs to convert zig types to facil.io
|
||||||
/// object - FIOBJ_T_HASH
|
// types. However, this needs to be investigated into.
|
||||||
|
// See `fiobjectify` for more information.
|
||||||
pub fn build(self: *Self, data: anytype) MustacheBuildResult {
|
pub fn build(self: *Self, data: anytype) MustacheBuildResult {
|
||||||
const T = @TypeOf(data);
|
const T = @TypeOf(data);
|
||||||
if (@typeInfo(T) != .Struct) {
|
if (@typeInfo(T) != .Struct) {
|
||||||
|
@ -150,11 +151,13 @@ pub const Mustache = struct {
|
||||||
var result: MustacheBuildResult = .{};
|
var result: MustacheBuildResult = .{};
|
||||||
|
|
||||||
result.fiobj_context = fiobjectify(data);
|
result.fiobj_context = fiobjectify(data);
|
||||||
result.fiobj_result = fiobj_mustache_build(self.handler, result.fiobj_context);
|
result.fiobj_result = fiobj_mustache_build(self.handle, result.fiobj_context);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fiobjectify(
|
/// Internal function used to convert zig types to facil.io types.
|
||||||
|
/// Used when providing the context to `fiobj_mustache_build`.
|
||||||
|
fn fiobjectify(
|
||||||
value: anytype,
|
value: anytype,
|
||||||
) fio.FIOBJ {
|
) fio.FIOBJ {
|
||||||
const T = @TypeOf(value);
|
const T = @TypeOf(value);
|
||||||
|
|
Loading…
Add table
Reference in a new issue