From 8a25a1ee65031a687ad7d208eaa2843aed6c9752 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sun, 22 Jul 2018 14:59:56 +0100 Subject: Add Template method to return template extension Thanks to Ryan McGrath for the suggestion and initial implementation. --- askama_derive/src/generator.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'askama_derive/src') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 5af38c0..db9ac17 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -117,6 +117,11 @@ impl<'a> Generator<'a> { self.flush_ws(WS(false, false)); self.writeln("Ok(())"); self.writeln("}"); + + self.writeln("fn extension(&self) -> Option<&str> {"); + self.writeln(&format!("{:?}", self.input.path.extension().map(|s| s.to_str().unwrap()))); + self.writeln("}"); + self.writeln("}"); } -- cgit