aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar mash <mashedcode@users.noreply.github.com>2018-06-29 13:16:56 +0000
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:25:27 +0200
commite604deb4dfddb9ad9e325b488c18dd7a395846e5 (patch)
tree55077888641fc30b88513274d783563308285e43 /askama_derive
parent28018e89222d0d02dbb9f662cbe8a9c190b0a9de (diff)
downloadaskama-e604deb4dfddb9ad9e325b488c18dd7a395846e5.tar.gz
askama-e604deb4dfddb9ad9e325b488c18dd7a395846e5.tar.bz2
askama-e604deb4dfddb9ad9e325b488c18dd7a395846e5.zip
Determine path during source attribute checks
Diffstat (limited to 'askama_derive')
-rw-r--r--askama_derive/src/input.rs17
1 files changed, 6 insertions, 11 deletions
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,