diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-17 15:11:04 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-17 15:11:04 +0100 |
commit | 2f75ba090f7a964624b6be4c3de42248bf3f1d90 (patch) | |
tree | cf908b2aea232c34fe6823fc86ea674b598b98df | |
parent | 2c069acd5fd6bccb4b43ce186f8d1bf7187bfe87 (diff) | |
download | askama-2f75ba090f7a964624b6be4c3de42248bf3f1d90.tar.gz askama-2f75ba090f7a964624b6be4c3de42248bf3f1d90.tar.bz2 askama-2f75ba090f7a964624b6be4c3de42248bf3f1d90.zip |
Trigger code generation debug output via template annotations
Diffstat (limited to '')
-rw-r--r-- | askama/src/lib.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/askama/src/lib.rs b/askama/src/lib.rs index b927fed..c727f48 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -20,10 +20,12 @@ pub use path::rerun_if_templates_changed; struct TemplateMeta { path: String, + print: bool, } fn get_template_meta(ast: &syn::DeriveInput) -> TemplateMeta { let mut path = None; + let mut print = false; let attr = ast.attrs.iter().find(|a| a.name() == "template").unwrap(); if let syn::MetaItem::List(_, ref inner) = attr.value { for nm_item in inner { @@ -35,6 +37,11 @@ fn get_template_meta(ast: &syn::DeriveInput) -> TemplateMeta { } else { panic!("template path must be string literal"); }, + "print" => if let &syn::Lit::Str(ref s, _) = val { + print = if s == "true" { true } else { false }; + } else { + panic!("print value must be string literal"); + }, _ => { panic!("unsupported annotation key found") } } } @@ -44,12 +51,16 @@ fn get_template_meta(ast: &syn::DeriveInput) -> TemplateMeta { if path.is_none() { panic!("template path not found in struct attributes"); } - TemplateMeta { path: path.unwrap() } + TemplateMeta { path: path.unwrap(), print: print } } pub fn build_template(ast: &syn::DeriveInput) -> String { let meta = get_template_meta(ast); let src = path::get_template_source(&meta.path); let nodes = parser::parse(&src); - generator::generate(ast, &meta.path, nodes) + let code = generator::generate(ast, &meta.path, nodes); + if meta.print { + println!("{}", code); + } + code } |