maciejhirsz / ramhorns

Fast Mustache template engine implementation in pure Rust.
https://crates.io/crates/ramhorns
Mozilla Public License 2.0
293 stars 29 forks source link

Add the callback attribute #56

Closed grego closed 2 years ago

grego commented 2 years ago

A new attribute callback is added, to be used as #[ramhorns(callback = "some_fn"). For a field of type T, it allows one to pass a function of type (&T, &mut E) -> Result<(), E::Error)> where E: Encoder to customise the rendering of the field.

#[md] attribute is replaced with #[ramhorns(md)] for clarity and consistency with other attributes. render_cmark method is deleted as it no longer serves a purpose (a callback is used instead).

maciejhirsz commented 2 years ago

Hey @grego, will do a review later today, just a quick note that I think it would be better to do #[ramhorns(callback = some_fn)] with a raw ident, partly for readability, partly because it lets you us pass the correct span on call site in case there are some compile issues. I can do that later on my own if need be.

grego commented 2 years ago

Sure, that's a good idea.

grego commented 2 years ago

As syn::MetaNameValue must contain a literal after =, I've changed the syntax to #[ramhorns(callback(some_fn))] where a raw ident can be used.

maciejhirsz commented 2 years ago

Yeah, it needs some manual work there, I'll give it a go in the morning, cheers :)

grego commented 2 years ago

Please also bump the pulldown_cmark dependency to 0.8.