1
Fork 0
mirror of https://github.com/RGBCube/embd-rs synced 2025-07-27 05:27:44 +00:00

Fix importing parent files

This commit is contained in:
RGBCube 2024-01-04 13:05:19 +03:00
parent 77520c0364
commit b2be0579f8
No known key found for this signature in database

View file

@ -42,6 +42,16 @@ pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream {
.expect("Failed to get the parent of file") .expect("Failed to get the parent of file")
.join(path); .join(path);
let path = if !path.ends_with("..") {
path
} else {
path.parent().unwrap().to_path_buf()
};
let path_str = path
.to_str()
.expect("Failed to get the string representation of PathBuf");
let children = read_dir(&path, &path); let children = read_dir(&path, &path);
let children_tokens = quote! { let children_tokens = quote! {
vec![#(#children),*] vec![#(#children),*]
@ -50,7 +60,7 @@ pub fn __include_dir(input: pm1::TokenStream) -> pm1::TokenStream {
(quote! { (quote! {
::embed::Dir { ::embed::Dir {
children: #children_tokens, children: #children_tokens,
path: ::std::path::PathBuf::from(""), path: ::std::path::PathBuf::from(#path_str),
} }
}) })
.into() .into()