Fix include! implementation for Rust file

Also add tests for including Rust file
This commit is contained in:
Kogia-sima 2020-06-11 19:43:01 +09:00
parent d302f30144
commit d7a2ff8008
5 changed files with 15 additions and 1 deletions

View File

@ -0,0 +1 @@
59

View File

@ -0,0 +1 @@
<% let a = include!("includes/rust.rs"); %><%= a %>

View File

@ -0,0 +1 @@
value + 1

View File

@ -184,6 +184,17 @@ fn test_rust_macro() {
assert_render("rust_macro", RustMacro { value: Some(10) });
}
#[derive(TemplateOnce)]
#[template(path = "include_rust.stpl")]
struct IncludeRust {
value: usize,
}
#[test]
fn test_include_rust() {
assert_render("include_rust", IncludeRust { value: 58 });
}
#[cfg(unix)]
mod unix {
use super::*;

View File

@ -63,7 +63,7 @@ impl<'s, 'h> VisitMut for ResolverImpl<'s, 'h> {
let absolute_path =
self.path_stack.last().unwrap().parent().unwrap().join(arg);
let absolute_path_str = absolute_path.to_string_lossy();
em.mac.tokens = quote! { include!(#absolute_path_str) };
*i = syn::parse2(quote! { include!(#absolute_path_str) }).unwrap();
}
return;
}