aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/input.rs
diff options
context:
space:
mode:
authorLibravatar vallentin <mail@vallentin.dev>2021-03-10 08:43:01 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2021-03-10 13:09:56 +0100
commit8566d8258a960fc1456d271b25428cbd312ba42b (patch)
tree2b41b81cb071f87f6178e6d87773a28373c7ae26 /askama_shared/src/input.rs
parent7291494e6a79928cce6ae8844d6ec3092ce51663 (diff)
downloadaskama-8566d8258a960fc1456d271b25428cbd312ba42b.tar.gz
askama-8566d8258a960fc1456d271b25428cbd312ba42b.tar.bz2
askama-8566d8258a960fc1456d271b25428cbd312ba42b.zip
Fixed extension to ignore common jinja extensions (fixes #457)
Diffstat (limited to '')
-rw-r--r--askama_shared/src/input.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs
index be380ea..febd51c 100644
--- a/askama_shared/src/input.rs
+++ b/askama_shared/src/input.rs
@@ -205,7 +205,17 @@ impl<'a> TemplateInput<'a> {
}
fn extension(path: &Path) -> Option<&str> {
- path.extension().map(|s| s.to_str().unwrap())
+ let ext = path.extension().map(|s| s.to_str().unwrap())?;
+
+ const JINJA_EXTENSIONS: [&str; 3] = ["j2", "jinja", "jinja2"];
+ if JINJA_EXTENSIONS.contains(&ext) {
+ Path::new(path.file_stem().unwrap())
+ .extension()
+ .map(|s| s.to_str().unwrap())
+ .or(Some(ext))
+ } else {
+ Some(ext)
+ }
}
pub enum Source {