Fixed dynatos_html::{html, html_file} not allowing arguments on their own.

This commit is contained in:
Filipe Rodrigues 2024-12-06 10:15:25 +00:00
parent 455858bf63
commit d1f59f4f81
Signed by: zenithsiz
SSH Key Fingerprint: SHA256:Mb5ppb3Sh7IarBO/sBTXLHbYEOz37hJAlslLQPPAPaU

View File

@ -6,7 +6,6 @@
// Imports
use {
dynatos_html_parser::{XHtml, XHtmlNode},
itertools::Itertools,
proc_macro::TokenStream,
std::{
fs,
@ -227,17 +226,24 @@ impl Node {
});
};
let (cons, args) = args
.into_iter()
.partition_map::<Vec<_>, Vec<_>, _, _, _>(|arg| match arg {
TextArg::Cons(text) => itertools::Either::Left(text),
TextArg::Argument(arg) => itertools::Either::Right(arg),
});
// Otherwise, we'll format a string with dynamic text
let fmt = args
.iter()
.map(|arg| match arg {
TextArg::Cons(text) => text,
TextArg::Argument(_) => "{}",
})
.collect::<String>();
let fmt = cons.into_iter().join("{}");
let args = args
.into_iter()
.map(|arg| syn::parse_str::<syn::Expr>(arg).expect("Unable to parse argument expression"))
.filter_map(|arg| match arg {
TextArg::Cons(_) => None,
TextArg::Argument(arg) => {
let arg = syn::parse_str::<syn::Expr>(arg).expect("Unable to parse argument expression");
Some(arg)
},
})
.collect::<Vec<_>>();
Self {