diff options
author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-01-10 15:09:53 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2024-01-12 10:38:15 +0100 |
commit | d5fbebecbd746e4dda0bcd81cb861b61afd8a309 (patch) | |
tree | 8982ca0c06c53fa961e5b7d32d39106555a3f832 /askama_derive/src | |
parent | 84c2094e871b7ef16ab51c77b4a3568794c75638 (diff) | |
download | askama-d5fbebecbd746e4dda0bcd81cb861b61afd8a309.tar.gz askama-d5fbebecbd746e4dda0bcd81cb861b61afd8a309.tar.bz2 askama-d5fbebecbd746e4dda0bcd81cb861b61afd8a309.zip |
Add `as_ref` builtin filter
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 0f9a2af..2040cac 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -1210,6 +1210,20 @@ impl<'a> Generator<'a> { Ok(DisplayWrap::Wrapped) } + fn _visit_as_ref_filter( + &mut self, + buf: &mut Buffer, + args: &[Expr<'_>], + ) -> Result<(), CompileError> { + let arg = match args { + [arg] => arg, + _ => return Err("unexpected argument(s) in `as_ref` filter".into()), + }; + buf.write("&"); + self.visit_expr(buf, arg)?; + Ok(()) + } + fn visit_filter( &mut self, buf: &mut Buffer, @@ -1230,6 +1244,9 @@ impl<'a> Generator<'a> { return Ok(DisplayWrap::Unwrapped); } else if name == "markdown" { return self._visit_markdown_filter(buf, args); + } else if name == "as_ref" { + self._visit_as_ref_filter(buf, args)?; + return Ok(DisplayWrap::Wrapped); } if name == "tojson" { |