diff options
Diffstat (limited to '')
-rw-r--r-- | askama/src/filters/mod.rs | 2 | ||||
-rw-r--r-- | askama_derive/src/generator.rs | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/askama/src/filters/mod.rs b/askama/src/filters/mod.rs index ca229ca..73b311d 100644 --- a/askama/src/filters/mod.rs +++ b/askama/src/filters/mod.rs @@ -2,6 +2,8 @@ //! //! Contains all the built-in filter functions for use in templates. //! Currently, there is no way to define filters outside this module. +// +// WHEN ADDING FILTERS, DON'T FORGET TO UPDATE `BUILT_IN_FILTERS` in askama_derive::generator. #[cfg(feature = "serde-json")] mod json; diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 1d8e8f2..c0986da 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -228,8 +228,10 @@ impl<'a> Generator<'a> { fn visit_filter(&mut self, name: &str, args: &[Expr]) { if name == "format" { self.write("format!("); - } else { + } else if BUILT_IN_FILTERS.contains(&name) { self.write(&format!("::askama::filters::{}(&", name)); + } else { + self.write(&format!("filters::{}(&", name)); } for (i, arg) in args.iter().enumerate() { @@ -707,3 +709,15 @@ impl<'a, T: 'a> SetChain<'a, T> where T: cmp::Eq + hash::Hash { } type MacroMap<'a> = HashMap<&'a str, (WS, &'a str, Vec<&'a str>, Vec<Node<'a>>, WS)>; + +const BUILT_IN_FILTERS: [&str; 9] = [ + "e", + "escape", + "format", + "lower", + "lowercase", + "trim", + "upper", + "uppercase", + "json", // Optional feature; reserve the name anyway +]; |