From ee9db1dbf441b0fd17058b56d39a27abf9d3e517 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 7 Sep 2017 20:42:54 +0200 Subject: Make ext attribute mandatory for source-specified templates --- askama_shared/src/input.rs | 12 ++++++++---- testing/tests/filters.rs | 2 +- testing/tests/simple.rs | 6 +++--- 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, } -- cgit