diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-05 20:34:18 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-05 20:34:18 +0200 |
commit | f02ade3b94e0eb7f97498439142a2448ebdcdfcc (patch) | |
tree | f481e79056576dc5a6c50daaa2bf864f16e5aff2 /askama_shared/src/input.rs | |
parent | 84fee0cf890fcc88ae9db1e1a17d0d784a73871a (diff) | |
download | askama-f02ade3b94e0eb7f97498439142a2448ebdcdfcc.tar.gz askama-f02ade3b94e0eb7f97498439142a2448ebdcdfcc.tar.bz2 askama-f02ade3b94e0eb7f97498439142a2448ebdcdfcc.zip |
Introduce attribute parameter to disable escaping
Diffstat (limited to 'askama_shared/src/input.rs')
-rw-r--r-- | askama_shared/src/input.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 73b9a60..40dc39f 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -32,6 +32,7 @@ impl<'a> TemplateInput<'a> { pub struct TemplateMeta<'a> { source: Source<'a>, pub print: Print, + pub escaping: EscapeMode, } impl<'a> TemplateMeta<'a> { @@ -46,6 +47,7 @@ impl<'a> TemplateMeta<'a> { let attr = attr.unwrap(); let mut source = None; let mut print = Print::None; + let mut escaping = EscapeMode::Html; if let syn::MetaItem::List(_, ref inner) = attr.value { for nm_item in inner { if let syn::NestedMetaItem::MetaItem(ref item) = *nm_item { @@ -66,6 +68,11 @@ impl<'a> TemplateMeta<'a> { } else { panic!("print value must be string literal"); }, + "escape" => if let syn::Lit::Str(ref s, _) = *val { + escaping = s.into(); + } else { + panic!("escape value must be string literal"); + }, _ => { panic!("unsupported annotation key found") } } } @@ -74,7 +81,7 @@ impl<'a> TemplateMeta<'a> { } match source { - Some(s) => TemplateMeta { source: s, print }, + Some(s) => TemplateMeta { source: s, print, escaping }, None => panic!("template path or source not found in struct attributes"), } } @@ -86,6 +93,23 @@ enum Source<'a> { } #[derive(PartialEq)] +pub enum EscapeMode { + Html, + None, +} + +impl<'a> From<&'a String> for EscapeMode { + fn from(s: &'a String) -> EscapeMode { + use self::EscapeMode::*; + match s.as_ref() { + "html" => Html, + "none" => None, + v => panic!("invalid value for escape option: {}", v), + } + } +} + +#[derive(PartialEq)] pub enum Print { All, Ast, |