resolve to relative path in include! by default

This commit is contained in:
Kogia-sima 2020-06-06 23:43:41 +09:00
parent cd8e3d832a
commit 64ded9616a
2 changed files with 9 additions and 14 deletions

View File

@ -38,14 +38,16 @@ impl Compiler {
pub fn compile_file(&self, template_dir: &Path, input: &Path, output: &Path) -> Result<(), Error> {
// TODO: introduce cache system
let input = if input.is_absolute() {
input.to_owned()
} else {
template_dir.join(input)
};
let input = input.canonicalize()?;
let include_handler = Arc::new(|arg: &str| -> Result<_, Error> {
let input_file = template_dir.join(arg);
let input_file = if arg.starts_with("/") {
// absolute imclude
template_dir.join(arg)
} else {
// relative include
input.parent().unwrap().join(arg)
};
Ok(self.translate_file_contents(&*input_file)?.ast)
});

View File

@ -60,13 +60,6 @@ impl<'h> VisitMut for ResolverImpl<'h> {
}
};
// TODO: support relative path
if arg.starts_with("./") || arg.starts_with("../") {
self.error = Some(make_error!(ErrorKind::Unimplemented(
"include! with relative path is not supported yet.".to_owned()
)))
}
// parse and translate the child template
let mut blk = match (*self.include_handler)(&arg) {
Ok(blk) => blk,