Giter VIP home page Giter VIP logo

mustache-zig's People

Contributors

batiati avatar bobf avatar jared-miller avatar mfashby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mustache-zig's Issues

UTF-16 support

Should be possible to read a template from a UTF-16 or "wide char" source, currently, only 8bits chars are supported.

  • Support UTF-16 for both parsing and rendering would save some work spent on conversions.
  • Interpret the BOM when reading from a file

stage3: tuple does not work with funciton pointer

mustache-zig: stage3
zig: 0.11.0-dev.1636+47e14b7ff

> zig build run
error: _bug...
error: The following command terminated unexpectedly:
const std = @import("std");
const mustache = @import("mustache-zig/src/mustache.zig");

pub const Server = struct {
    handler_fns: std.StringHashMap(HandlerFn),

    pub const HandlerFn = *const fn(Request) void;

    fn handle(self: *Server) !void {
        var req = Request{ .path = "/test"};
        if (self.handler_fns.get(req.path)) |f| f(req);
    }
};

pub const Request = struct {
    path: []const u8 = undefined,
};

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(!gpa.deinit());
    const allocator = gpa.allocator();
    
    var fns = std.StringHashMap(Server.HandlerFn).init(allocator);
    try fns.put("/test", rqTest);
    defer fns.deinit();

    var srv = Server{.handler_fns = fns};
	
    try srv.handle();
}

fn rqTest(req: Request) void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer std.debug.assert(!gpa.deinit());
    const allocator = gpa.allocator();
	
    // const Ctx = struct {name: []const u8};
    // const ctx: Ctx = .{.name = req.path};
    const ctx = .{.name = req.path};
    
    const html = mustache.allocRenderText(allocator, "Hello {{name}} from Zig", ctx) catch return;
    defer allocator.free(html);
    
    std.debug.print("{s}\n", .{html});
}

Not sure since I'm new to zig, is this a problem of the zig compiler?

Windows Support

Hi, I'm excited to use this library in my Zig project.
Is there an estimate for how long it would take to implement full Windows support?

Build fails

I am trying to build the library, in the git root I run zig build and get the following output

src/ffi/extern_types.zig:51:10: error: extern structs cannot contain fields of type
'?fn(?*const anyopaque, *const ffi.extern_types.Path, *ffi.extern_types.UserData) ca
llconv(.C) ffi.extern_types.PathResolution'
    get: ?fn (user_data_handle: UserDataHandle, path: *const Path, out_value: *UserD
ata) callconv(.C) PathResolution,
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/ffi/extern_types.zig:51:10: note: only pointer like optionals are extern compati
ble
referenced by:
    UserData: src/ffi/extern_types.zig:49:29
    UserData: src/ffi/extern_types.zig:51:80
    remaining reference traces hidden; use '-freference-trace' to see all reference
traces

src/parsing/parser.zig:140:68: error: expected type '*parsing.text_part.TextPart(.{.
source = .{ .string = .{.copy_strings = true} }, .output = .cache, .features = .{.al
low_redefining_delimiters = true, .preseve_line_breaks_and_indentation = true, .lamb
das = .{ .enabled = .{ ... } }}

Incidently I am trying to also get it working as a package, how can I statically link the library into my zig project ( can they be built a long side one another ? ). Sorry I am new to zig :).

example

Could you add an example how to use it from zig 0.11 as dynamic link library?

Decimal Interpolation

We fail with this test from mustaches spec

- name: Basic Decimal Interpolation
    desc: Decimals should interpolate seamlessly with proper significance.
    data: { power: 1.210 }
    template: '"{{power}} jiggawatts!"'
    expected: '"1.21 jiggawatts!"'

Suggestions:

  • Implement a custom formatter for floats
  • Introduce a new configuration for max float precision, preventing from rendering things like 1.21000345698
  • Maybe waiting for Ryu floating point printing

Improve parser errors

Parser errors are very limited, and they have few test cases.
There are some missing features in parser errors:

  • Closing tags are not checked, you can open a tag with triple-mustaches and close with regular ones {{{invalid}}
  • Define the correct behavior when dealing with triple-mustaches and custom delimiters, for now, any delimiter + { is recognized as a triple-mustache
  • Improve error messages, maybe by printing parser errors on the output writer when rendering in the streamed mode and comptime mode.

Review comptime options

There are a lot of comptime options, some of them still not implemented, poorly named, or not so obvious.
Some options could be visible internally only.

Example:

pub const Features = struct {
    allow_redefining_delimiters: bool = true,
    preseve_line_breaks_and_indentation: bool = true,
    lambdas: Lambdas = .{ .enabled = .{} },
};

Here we can keep track of all comptime options, and the current status:

Option Meaning Status
ParseTextOptions.copy_strings Parsed templates should dupe all strings or just take slices from the template source Implemented
ParseFileOptions.read_buffer_size Buffer size of the streamed parser. Implemented, but it could have a better name
Features.allow_redefining_delimiters Allows redefining the delimiters through the tags '{{=' and '=}}' Not implemented
Features.preseve_line_breaks_and_indentation Follow strict mustache's rules about blank spaces and indentation Implemented, but it could have a better name
Lambdas.disabled Disable lambdas support, which means, there is no need to store the tag's content Implemented
Lambdas..enabled.max_recursion When enabled, prevents recursive lambda expansion Not implemented
ContextMisses.empty or fail Behaviour when interpolating an unknown variable Not implemented, defaults to "empty" always

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.