Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MustacheLoad to support loading from file #42

Closed
wants to merge 1 commit into from
Closed

Add MustacheLoad to support loading from file #42

wants to merge 1 commit into from

Conversation

sadbeast
Copy link
Contributor

According to the facil.io docs
(http://facil.io/0.7.x/fiobj_mustache#fiobj_mustache_new):

By setting the filename argument even when the data argument exists,
it will allow path resolution for partial templates. Otherwise, there
is no way to know where to find the partial templates.

This will allow partial templates to work.

However, this also introduces a breaking change to the existing MustacheNew function. This change makes it mirror the C version more closely where it accepts a MustacheLoadArgs struct instead of just the data. Although that's also a handy method to have, so I renamed that to MustacheData...maybe there's a better name?

According to the facil.io docs
(http://facil.io/0.7.x/fiobj_mustache#fiobj_mustache_new):

> By setting the filename argument even when the data argument exists,
> it will allow path resolution for partial templates. Otherwise, there
> is no way to know where to find the partial templates.

This will allow partial templates to work.

However, this also introduces a breaking change to the existing
MustacheNew function. This change makes it mirror the C version where it
accepts a MustacheLoadArgs struct instead of just the data.  That's also
a handy method to have, so I renamed that to MustacheData...maybe
there's a better name?
Copy link
Member

@renerocksai renerocksai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi and thanks a lot for this great PR! It got me thinking: IMHO, making MustacheLoadArgs the only arg to MustacheNew and not having a MustacheData at all would break existing apps, but if there are sane defaults, that shouldn't matter too much.

I propose a new MustacheLoadargs as "interface" for the zig side of things:

pub const MustacheLoadArgs = struct {
    filename : ?[]const u8 = null,
    data : ?[]const u8 = null,
};

That way, one can call MustacheNew(.{ .data = "xxx" }); which is really close to MustacheNew("xxx"). But at the same time, one could also provide a filename.

The MustacheNew would use an MustacheLoadArgsInternal struct to interface with facil.io (the then old MustacheLoadArgs)

Would you agree?

[Edit]: And while we're at it, I also propose to make the function names lowercase (camelCase). I don't know why I made them uppercase. Seems like a mistake on my side. (Not that everything else in Zap would be super-consistent but still... 😄)

@renerocksai
Copy link
Member

FYI I have applied your patch locally, and will add above suggestions before pushing. Thanks a lot, this is a great addition for Mustache users.

@renerocksai
Copy link
Member

Thanks a lot for this PR 🙏 , I merged it locally, applied my suggestions, and created a new release!!!

@renerocksai
Copy link
Member

BTW of course, your commit 8f5aa17 is preserved in git history, in case you are wondering.

@sadbeast
Copy link
Contributor Author

Fantastic, thanks so much! I agree with the separate MustacheLoadArgs approach, much cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants