aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/input.rs
diff options
context:
space:
mode:
authorLibravatar mash <mashedcode@users.noreply.github.com>2018-06-29 13:23:15 +0000
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:25:27 +0200
commit4ead8e8c9302ce67d322e51909f0897082483ca3 (patch)
tree24fddc4f12f4e19aee5cb2cad39217a86f304725 /askama_derive/src/input.rs
parente604deb4dfddb9ad9e325b488c18dd7a395846e5 (diff)
downloadaskama-4ead8e8c9302ce67d322e51909f0897082483ca3.tar.gz
askama-4ead8e8c9302ce67d322e51909f0897082483ca3.tar.bz2
askama-4ead8e8c9302ce67d322e51909f0897082483ca3.zip
Simplify escape mode determination
Diffstat (limited to 'askama_derive/src/input.rs')
-rw-r--r--askama_derive/src/input.rs33
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,