diff --git a/contrib/dyn_templates/Cargo.toml b/contrib/dyn_templates/Cargo.toml index 4276e602..e597275b 100644 --- a/contrib/dyn_templates/Cargo.toml +++ b/contrib/dyn_templates/Cargo.toml @@ -24,7 +24,11 @@ normpath = "1" tera = { version = "1.19.0", optional = true } handlebars = { version = "5.1", optional = true } -minijinja = { version = "1.0.16", optional = true, features = ["loader"] } + +[dependencies.minijinja] +version = "2.0.1" +optional = true +features = ["loader", "speedups", "json", "urlencode"] [dependencies.rocket] version = "0.5.0" diff --git a/contrib/dyn_templates/src/engine/mod.rs b/contrib/dyn_templates/src/engine/mod.rs index 785b1c84..b190a52b 100644 --- a/contrib/dyn_templates/src/engine/mod.rs +++ b/contrib/dyn_templates/src/engine/mod.rs @@ -156,24 +156,21 @@ impl Engines { /// Returns iterator over template (name, engine_extension). pub(crate) fn templates(&self) -> impl Iterator { - #[cfg(all(feature = "tera", feature = "handlebars"))] { - self.tera.get_template_names() - .map(|name| (name, Tera::EXT)) - .chain(self.handlebars.get_templates().keys() - .map(|name| (name.as_str(), Handlebars::EXT))) - } + #[cfg(feature = "tera")] + let tera = self.tera.get_template_names().map(|name| (name, Tera::EXT)); - #[cfg(all(feature = "tera", not(feature = "handlebars")))] { - self.tera.get_template_names().map(|name| (name, Tera::EXT)) - } + #[cfg(feature = "handlebars")] + let handlebars = self.handlebars.get_templates().keys() + .map(|name| (name.as_str(), Handlebars::EXT)); - #[cfg(all(feature = "handlebars", not(feature = "tera")))] { - self.handlebars.get_templates().keys() - .map(|name| (name.as_str(), Handlebars::EXT)) - } + #[cfg(feature = "minijinja")] + let minijinja = self.minijinja.templates() + .map(|(name, _)| (name, Environment::EXT)); - #[cfg(not(any(feature = "tera", feature = "handlebars")))] { - None.into_iter() - } + #[cfg(not(feature = "tera"))] let tera = std::iter::empty(); + #[cfg(not(feature = "handlebars"))] let handlebars = std::iter::empty(); + #[cfg(not(feature = "minijinja"))] let minijinja = std::iter::empty(); + + tera.chain(handlebars).chain(minijinja) } } diff --git a/contrib/dyn_templates/src/lib.rs b/contrib/dyn_templates/src/lib.rs index 066585ec..f35658a5 100644 --- a/contrib/dyn_templates/src/lib.rs +++ b/contrib/dyn_templates/src/lib.rs @@ -30,7 +30,7 @@ //! [configurable]: #configuration //! [Tera]: https://docs.rs/crate/tera/1 //! [Handlebars]: https://docs.rs/crate/handlebars/5 -//! [MiniJinja]: https://docs.rs/minijinja/1 +//! [MiniJinja]: https://docs.rs/minijinja/2 //! //! 3. Attach `Template::fairing()` and return a [`Template`] from your routes //! via [`Template::render()`], supplying the name of the template file