diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-07 20:42:54 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-07 20:42:54 +0200 |
commit | ee9db1dbf441b0fd17058b56d39a27abf9d3e517 (patch) | |
tree | 4c1a5b7754a4bd85ad231e74ad0686039f7cedc6 | |
parent | 5503b945cc9ec274ae3d859330767e1088b13a52 (diff) | |
download | askama-ee9db1dbf441b0fd17058b56d39a27abf9d3e517.tar.gz askama-ee9db1dbf441b0fd17058b56d39a27abf9d3e517.tar.bz2 askama-ee9db1dbf441b0fd17058b56d39a27abf9d3e517.zip |
Make ext attribute mandatory for source-specified templates
-rw-r--r-- | askama_shared/src/input.rs | 12 | ||||
-rw-r--r-- | testing/tests/filters.rs | 2 | ||||
-rw-r--r-- | testing/tests/simple.rs | 6 | ||||
-rw-r--r-- | testing/tests/vars.rs | 2 |
4 files changed, 13 insertions, 9 deletions
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 7d27eb3..371cf6d 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -101,10 +101,14 @@ impl<'a> TemplateMeta<'a> { match source { Some(s) => { - if let Source::Path(_) = s { - if ext.is_some() { - panic!("'ext' attribute cannot be used with 'path' attribute"); - } + match (&s, ext.is_some()) { + (&Source::Path(_), true) => { + panic!("'ext' attribute cannot be used with 'path' attribute") + }, + (&Source::Source(_), false) => { + panic!("must include 'ext' attribute when using 'source' attribute") + }, + _ => {}, } TemplateMeta { source: s, print, escaping, ext } }, diff --git a/testing/tests/filters.rs b/testing/tests/filters.rs index b24ff61..39fe0ff 100644 --- a/testing/tests/filters.rs +++ b/testing/tests/filters.rs @@ -33,7 +33,7 @@ fn filter_format() { #[derive(Template)] -#[template(source = "{{ s|myfilter }}")] +#[template(source = "{{ s|myfilter }}", ext = "txt")] struct MyFilterTemplate<'a> { s: &'a str, } diff --git a/testing/tests/simple.rs b/testing/tests/simple.rs index 57887c8..8fd61d2 100644 --- a/testing/tests/simple.rs +++ b/testing/tests/simple.rs @@ -184,7 +184,7 @@ fn test_composition() { #[derive(Template)] -#[template(source = "{{ foo }}")] +#[template(source = "{{ foo }}", ext = "html")] struct ImplicitEscapedTemplate<'a> { foo: &'a str, } @@ -197,7 +197,7 @@ fn test_implicit_escaped() { #[derive(Template)] -#[template(source = "{{ foo }}", escape = "html")] +#[template(source = "{{ foo }}", ext = "html", escape = "html")] struct ExplicitEscapedTemplate<'a> { foo: &'a str, } @@ -210,7 +210,7 @@ fn test_explicit_escaped() { #[derive(Template)] -#[template(source = "{{ foo }}", escape = "none")] +#[template(source = "{{ foo }}", ext = "txt")] struct UnescapedTemplate<'a> { foo: &'a str, } diff --git a/testing/tests/vars.rs b/testing/tests/vars.rs index db99a61..39a1415 100644 --- a/testing/tests/vars.rs +++ b/testing/tests/vars.rs @@ -4,7 +4,7 @@ extern crate askama; use askama::Template; #[derive(Template)] -#[template(source = "{% let v = s %}{{ v }}")] +#[template(source = "{% let v = s %}{{ v }}", ext = "txt")] struct LetTemplate<'a> { s: &'a str, } |