1use leon::{Item, Template};
2use quote::quote;
3use syn::{parse_macro_input, LitStr};
4
5#[proc_macro]
6pub fn template(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
7 let input = parse_macro_input!(input as LitStr).value();
8
9 #[allow(clippy::unnecessary_to_owned)]
10 let items = Template::parse(&input)
11 .unwrap()
12 .items
13 .into_owned()
14 .into_iter()
15 .map(|item| match item {
16 Item::Text(text) => quote! {
17 ::leon::Item::Text(#text)
18 },
19 Item::Key(key) => quote! {
20 ::leon::Item::Key(#key)
21 },
22 });
23
24 quote! {
25 ::leon::Template::new(
26 {
27 const ITEMS: &'static [::leon::Item<'static>] = &[
28 #(#items),*
29 ];
30 ITEMS
31 },
32 ::core::option::Option::None,
33 )
34 }
35 .into()
36}