handlebars-rust icon indicating copy to clipboard operation
handlebars-rust copied to clipboard

Publish source api

Open sunng87 opened this issue 3 years ago • 4 comments

sunng87 avatar Feb 16 '21 17:02 sunng87

This API would be useful for me, so I brought this branch up-to-date in #444.

mkantor avatar Jun 07 '21 00:06 mkantor

@mkantor may I know your use case for this feature?

sunng87 avatar Jun 07 '21 14:06 sunng87

@mkantor may I know your use case for this feature?

My use case is to set up a registry from already-open Files.

With handlebars-rust 3.x I'm using the old register_template_source method which accepts any Read. With the Source API published in this PR I could create a impl Source for File and use the new register_template_source from this changeset. (...I'm now realizing this might not be precisely what I want, since I think I'd have to clone the File in impl Source for File. I guess my ideal API would be something closer to the old one where the source may be consumed/mutated. For my use case it's fine to give away ownership of the File.)

If this doesn't get merged I'll probably use the path with register_template_file and let handlebars-rust open a new File, or maybe I'll just read the file contents to a String and use register_template_string, but I was kind of curious to try out dev mode.

mkantor avatar Jun 09 '21 04:06 mkantor

I ended up using register_template_file instead, which seems to be working nicely (https://github.com/mkantor/operator/pull/58). I don't think I have a strong use case for the source API after all.

mkantor avatar Jun 13 '21 17:06 mkantor