jetzig-framework / jetzig

Jetzig is a web framework written in Zig
MIT License
458 stars 21 forks source link

Sometimes templates cannot be found on custom routes #96

Closed roman542 closed 1 month ago

roman542 commented 1 month ago

In file src/jetzig/App.zig in the route function:

    const member = @tagName(action);
    const viewFn = @field(module, member);
    const module_name = comptime std.mem.trimLeft(u8, @typeName(module), "app.views.");

std.mem.trimLeft removes all values from the left up to the first value not in the provided set. It can remove more than the prefix, e.g., when the module name is app.views.article (becomes rticle). Also, the string apviews. will have the same effect as app.views..

Possible solution:

    const module_full = @typeName(module);
    const module_name = module_full["app.views.".len .. module_full.len];
bobf commented 1 month ago

@roman542 Thanks for reporting this ! Definitely I misunderstood what std.mem.trimLeft was doing here. I used your suggested fix (slightly modified). Let me know if you have any issues. :pray:

roman542 commented 1 month ago

Works like a charm.

Definitely I misunderstood what std.mem.trimLeft was doing here.

Yep, me too!