diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-21 14:08:33 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-21 14:08:33 +0200 |
commit | 959f5e1333effbbf52a1e2e91a7f31ee303e5cbe (patch) | |
tree | 1c880e9d7c82841da1e97db0a1919ddec63f13bb /askama_derive/src/lib.rs | |
parent | 2a6dce31eaa9efb505cc19b0fbdfe155132c4c07 (diff) | |
download | askama-959f5e1333effbbf52a1e2e91a7f31ee303e5cbe.tar.gz askama-959f5e1333effbbf52a1e2e91a7f31ee303e5cbe.tar.bz2 askama-959f5e1333effbbf52a1e2e91a7f31ee303e5cbe.zip |
Store extends path in Context
Diffstat (limited to 'askama_derive/src/lib.rs')
-rw-r--r-- | askama_derive/src/lib.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 3651e02..07ba0a6 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -91,26 +91,26 @@ fn find_used_templates(map: &mut HashMap<PathBuf, String>, path: PathBuf, source pub(crate) struct Context<'a> { nodes: &'a [Node<'a>], + extends: Option<PathBuf>, blocks: Vec<&'a Node<'a>>, macros: HashMap<&'a str, &'a Macro<'a>>, imports: HashMap<&'a str, PathBuf>, trait_name: String, - derived: bool, } impl<'a> Context<'a> { fn new<'n>(input: &'n TemplateInput, nodes: &'n [Node<'n>]) -> Context<'n> { - let mut base = None; + let mut extends = None; let mut blocks = Vec::new(); let mut macros = HashMap::new(); let mut imports = HashMap::new(); for n in nodes { match n { - Node::Extends(Expr::StrLit(path)) => match base { + Node::Extends(Expr::StrLit(path)) => match extends { Some(_) => panic!("multiple extend blocks found"), None => { - base = Some(*path); + extends = Some(path::find_template_from_path(path, Some(&input.path))); } }, def @ Node::BlockDef(_, _, _, _) => { @@ -143,19 +143,18 @@ impl<'a> Context<'a> { check_nested += 1; } + let trait_name = match extends { + Some(ref path) => trait_name_for_path(path), + None => trait_name_for_path(&input.path), + }; + Context { nodes, + extends, blocks, macros, imports, - trait_name: match base { - Some(user_path) => trait_name_for_path(&path::find_template_from_path( - user_path, - Some(&input.path), - )), - None => trait_name_for_path(&input.path), - }, - derived: base.is_some(), + trait_name, } } } |