diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-17 15:07:35 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-17 15:07:35 +0100 |
commit | 2c069acd5fd6bccb4b43ce186f8d1bf7187bfe87 (patch) | |
tree | 12a7f35c89dbca22513f139a47985b7fa415cccd /askama_derive | |
parent | 210ed06bdb2b8042207cb91cfb84ee2e04bb6d11 (diff) | |
download | askama-2c069acd5fd6bccb4b43ce186f8d1bf7187bfe87.tar.gz askama-2c069acd5fd6bccb4b43ce186f8d1bf7187bfe87.tar.bz2 askama-2c069acd5fd6bccb4b43ce186f8d1bf7187bfe87.zip |
Move template metadata processing into askama crate
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/lib.rs | 32 |
1 files changed, 1 insertions, 31 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index fb3bb2d..4b96e17 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -4,35 +4,6 @@ extern crate syn; use proc_macro::TokenStream; -struct TemplateMeta { - path: String, -} - -fn get_path_from_attrs(attrs: &[syn::Attribute]) -> TemplateMeta { - let mut path = None; - let attr = attrs.iter().find(|a| a.name() == "template").unwrap(); - if let syn::MetaItem::List(_, ref inner) = attr.value { - for nm_item in inner { - if let &syn::NestedMetaItem::MetaItem(ref item) = nm_item { - if let &syn::MetaItem::NameValue(ref key, ref val) = item { - match key.as_ref() { - "path" => if let &syn::Lit::Str(ref s, _) = val { - path = Some(s.clone()); - } else { - panic!("template path must be string literal"); - }, - _ => { panic!("unsupported annotation key found") } - } - } - } - } - } - if path.is_none() { - panic!("template path not found in struct attributes"); - } - TemplateMeta { path: path.unwrap() } -} - #[proc_macro_derive(Template, attributes(template))] pub fn derive_template(input: TokenStream) -> TokenStream { let ast = syn::parse_derive_input(&input.to_string()).unwrap(); @@ -40,6 +11,5 @@ pub fn derive_template(input: TokenStream) -> TokenStream { syn::Body::Struct(ref data) => data, _ => panic!("#[derive(Template)] can only be used with structs"), }; - let meta = get_path_from_attrs(&ast.attrs); - askama::build_template(&meta.path, &ast).parse().unwrap() + askama::build_template(&ast).parse().unwrap() } |