You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice if templates could be rendered without using build scripts.
The current approach is not very bad, but it could be more ergonomic with macros.
The pro for using macros is that special build scripts would be unnecessary, and this crate would no longer need "special treatment" to set up. It might also be friendlier for development tools, but I am not entirely sure on this point.
The con is that, as far as I understand, this would require setting up another ructe-codegen crate that hosts the procedural macro(s). This might also require exposing some previously private apis in altered form.
For what an api using macros could look like, something like this comes to mind:
At least naively implemented, this has the disadvantage that templates will need to be parsed once for every use of that template. Also having so many arguments is just not very pretty or readable.
might be worth considering even though it is imo less intuitive because the macro looks more like a function call than a function definition.
let hello_args = template!("templates/hello_args_two.rs.html");letmut buf = Vec::new();
hello_args.render(&mut buf,25,"prime",false);
where template! returns an instance of some struct generated from within the macro might also work.
As you can tell, this idea is not very fleshed out yet, but I believe it has a lot of potential in making the library easier to use, and I would love to hear ideas and opinions on the matter.
The text was updated successfully, but these errors were encountered:
Yes, some way of working as a macro has been in my long-term vision for ructe pretty much since the start. So It's nice to finally having an issue for it. :-)
I have mainly had something like template_module!("templates") in mind (i.e. a single macro that replaces the include! of generated code in projects using current ructe). Maybe handling one template at a a time (and static files separately) is a good idea, at least for getting started.
It would be nice if templates could be rendered without using build scripts.
The current approach is not very bad, but it could be more ergonomic with macros.
The pro for using macros is that special build scripts would be unnecessary, and this crate would no longer need "special treatment" to set up. It might also be friendlier for development tools, but I am not entirely sure on this point.
The con is that, as far as I understand, this would require setting up another
ructe-codegen
crate that hosts the procedural macro(s). This might also require exposing some previously private apis in altered form.For what an api using macros could look like, something like this comes to mind:
At least naively implemented, this has the disadvantage that templates will need to be parsed once for every use of that template. Also having so many arguments is just not very pretty or readable.
Alternatively, something like
might be worth considering even though it is imo less intuitive because the macro looks more like a function call than a function definition.
where
template!
returns an instance of some struct generated from within the macro might also work.As you can tell, this idea is not very fleshed out yet, but I believe it has a lot of potential in making the library easier to use, and I would love to hear ideas and opinions on the matter.
The text was updated successfully, but these errors were encountered: