From e604deb4dfddb9ad9e325b488c18dd7a395846e5 Mon Sep 17 00:00:00 2001 From: mash Date: Fri, 29 Jun 2018 13:16:56 +0000 Subject: Determine path during source attribute checks --- askama_derive/src/input.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'askama_derive') diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs index be9446f..cfc8855 100644 --- a/askama_derive/src/input.rs +++ b/askama_derive/src/input.rs @@ -85,15 +85,18 @@ impl<'a> TemplateInput<'a> { } let source = source.expect("template path or source not found in attributes"); - match (&source, ext.is_some()) { + let path = match (&source, 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") } - _ => {} - } + (&Source::Path(ref path), false) => path::find_template_from_path(path, None), + (&Source::Source(_), true) => { + PathBuf::from(format!("{}.{}", ast.ident, ext.as_ref().unwrap())) + } + }; let escaping = match escaping { Some(m) => m, @@ -125,14 +128,6 @@ impl<'a> TemplateInput<'a> { _ => panic!("derive(Template) only works for struct items"), }.next(); - let path = match source { - Source::Source(_) => match ext { - Some(ref v) => PathBuf::from(format!("{}.{}", ast.ident, v)), - None => PathBuf::new(), - }, - Source::Path(ref s) => path::find_template_from_path(s, None), - }; - TemplateInput { ast, source, -- cgit