diff options
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/input.rs | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs index cfc8855..cf1ad90 100644 --- a/askama_derive/src/input.rs +++ b/askama_derive/src/input.rs @@ -4,7 +4,7 @@ use quote::ToTokens; use shared::path; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use syn; @@ -98,24 +98,6 @@ impl<'a> TemplateInput<'a> { } }; - let escaping = match escaping { - Some(m) => m, - None => { - let ext = match source { - Source::Path(ref p) => Path::new(p) - .extension() - .map(|s| s.to_str().unwrap()) - .unwrap_or(""), - Source::Source(_) => ext.as_ref().unwrap(), // Already panicked if None - }; - if HTML_EXTENSIONS.contains(&ext) { - EscapeMode::Html - } else { - EscapeMode::None - } - } - }; - let parent = match ast.data { syn::Data::Struct(syn::DataStruct { fields: syn::Fields::Named(ref fields), @@ -132,7 +114,7 @@ impl<'a> TemplateInput<'a> { ast, source, print, - escaping, + escaping: escaping.unwrap_or_else(|| EscapeMode::from_path(&path)), ext, parent, path, @@ -162,6 +144,17 @@ impl From<String> for EscapeMode { } } +impl EscapeMode { + fn from_path(path: &PathBuf) -> EscapeMode { + let extension = path.extension().map(|s| s.to_str().unwrap()).unwrap_or(""); + if HTML_EXTENSIONS.contains(&extension) { + EscapeMode::Html + } else { + EscapeMode::None + } + } +} + #[derive(PartialEq)] pub enum Print { All, |