From 21885c06bfff5e8561dab1f2276716876b56763b Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sun, 6 Aug 2017 14:43:47 +0200 Subject: Allow parent templates to be specified as relative paths (fixes #26) --- askama_derive/src/generator.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'askama_derive/src') 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) -> 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); -- cgit