aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--askama/src/lib.rs2
-rw-r--r--askama_derive/src/generator.rs5
-rw-r--r--testing/tests/simple.rs1
3 files changed, 8 insertions, 0 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs
index 77e49f2..c7cd182 100644
--- a/askama/src/lib.rs
+++ b/askama/src/lib.rs
@@ -337,6 +337,8 @@ pub trait Template {
self.render_into(&mut buf)?;
Ok(buf)
}
+ /// Helper method to inspect the template's extension
+ fn extension(&self) -> Option<&str>;
}
pub use askama_derive::*;
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("}");
}
diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs
index 95c14b1..4af2cea 100644
--- a/testing/tests/simple.rs
+++ b/testing/tests/simple.rs
@@ -27,6 +27,7 @@ fn test_variables() {
Iñtërnâtiônàlizætiøn is important\n\
in vars too: Iñtërnâtiônàlizætiøn"
);
+ assert_eq!(s.extension(), Some("html"));
}
#[derive(Template)]