Add Tera v2 support - #3010
Conversation
Co-authored-by: Peter W <peter.wischer@gmail.com>
|
I just realized that this also breaks tera autoescaping for some reason. I understand that the .html.tera files are not auto-escaped on version 2, because they are registered to tera without their file extension. However, I don't understand why this wasn't a problem with tera v1. |
|
@axoking Thanks for the PR! It wasn't an issue with Tera v1 because it had a fallback to look for the files the extensions - this functionality is different in v2. A few points to note:
I have integrated a tera_v2 feature into github.com/rustfoo/rkt with the above fixed. I have some more revisions to make before making it public - for rkt I am contemplating making the tera feature use tera_v2 and tera_v1 point to the now deprecated features. |
|
@martynp Thank you! So you got a solution for auto escaping? I'm also currently looking into the tera crate to see if you could add auto escaping functionality there, e.g. getting the extension from the file path, or giving other crates an option to manually enable auto-escaping on files (maybe this is already an option, I will have a look later) |
|
@axoking Yes — it's working in rustfoo/rkt now. Rather than change how templates are registered I kept the names and made the escape list explicit: pick out the escapable templates by their source path and pass their names to |
|
Ok nice! I will check that out I'm also working on the autoescaping stuff here: Keats/tera#1028 |
I added a feature
tera2which will use tera v2 instead of the deprecated v1. I left the oldterafeature working for compatibility.An
ifcondition that checks if the template exists could be omitted, because tera 2 early returns before that function is even called if the template does not exist.I did not write any documentation or testing, because I'm not familiar with that. But I tested both
teraandtera2with a seperate crate I wrote, and they work and render using the correct tera version.