From 7291494e6a79928cce6ae8844d6ec3092ce51663 Mon Sep 17 00:00:00 2001 From: vallentin Date: Tue, 9 Mar 2021 06:38:56 +0100 Subject: Refactored getting path extension --- askama_shared/src/input.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'askama_shared/src/input.rs') diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 59f1303..be380ea 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -1,6 +1,6 @@ use crate::{CompileError, Config, Syntax}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::str::FromStr; use quote::ToTokens; @@ -198,6 +198,14 @@ impl<'a> TemplateInput<'a> { path, }) } + + pub fn extension(&self) -> Option<&str> { + extension(&self.path) + } +} + +fn extension(path: &Path) -> Option<&str> { + path.extension().map(|s| s.to_str().unwrap()) } pub enum Source { -- cgit