diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-24 20:22:23 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-24 20:22:23 +0200 |
commit | 1c9066f9b40e0f4eb8fd67f6492efc96308eccd4 (patch) | |
tree | 94ace672710ca37cebd67ac45ca1c0276af6cb84 /askama_derive/src/generator.rs | |
parent | e530ec879a53015343489c16ab7d2f93eee70b5f (diff) | |
download | askama-1c9066f9b40e0f4eb8fd67f6492efc96308eccd4.tar.gz askama-1c9066f9b40e0f4eb8fd67f6492efc96308eccd4.tar.bz2 askama-1c9066f9b40e0f4eb8fd67f6492efc96308eccd4.zip |
Add support for user-defined filters
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 16 |
1 files changed, 15 insertions, 1 deletions
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 +]; |