diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-06 14:43:47 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-06 14:44:35 +0200 |
commit | 21885c06bfff5e8561dab1f2276716876b56763b (patch) | |
tree | 4b0115eedf99a6d87496148a651bd94ee8aa54d7 /askama_derive/src/generator.rs | |
parent | 0514e4fec7e996cfbe4b97e5d09b6eebaf14eb43 (diff) | |
download | askama-21885c06bfff5e8561dab1f2276716876b56763b.tar.gz askama-21885c06bfff5e8561dab1f2276716876b56763b.tar.bz2 askama-21885c06bfff5e8561dab1f2276716876b56763b.zip |
Allow parent templates to be specified as relative paths (fixes #26)
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 570ab06..d5ddd16 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -1,4 +1,6 @@ use parser::{self, Cond, Expr, Node, Target, WS}; +use path; +use std::path::PathBuf; use std::str; use std::collections::HashSet; use syn; @@ -471,12 +473,18 @@ pub fn generate(ast: &syn::DeriveInput, path: &str, mut nodes: Vec<Node>) -> Str if base.is_none() { gen.define_trait(path, &block_names); } - let tmpl_path = match base { - Some(Expr::StrLit(base_path)) => { base_path }, - _ => { path }, + let base_path = match base { + Some(Expr::StrLit(user_path)) => { + path::find_template_from_path(user_path, Some(path)) + }, + _ => { + let mut path_buf = PathBuf::new(); + path_buf.push(&path); + path_buf + }, }; let trait_nodes = if base.is_none() { Some(&content[..]) } else { None }; - gen.impl_trait(ast, tmpl_path, &blocks, trait_nodes); + gen.impl_trait(ast, base_path.to_str().unwrap(), &blocks, trait_nodes); gen.impl_template_for_trait(ast, base.is_some()); } else { gen.impl_template(ast, &content); |