pub fn load_file_recursively<P: AsRef<Path>>(origin: P) -> Result<String, Error>
Expand description
Load the given file path and recursively follow references to other files inside it, inserting the text from references.
References are either ${include("<path>")}
or ${include_indent("<path>")}
,
with the latter preserving local indentation for each new line in the referenced
file. Paths can be relative or absolute.
The function will check references for cyclic dependencies and will return a Error::CyclicDependency should it detect one.
§Example
Given the following files…
start.txt:
START
${include_indent("mid.txt")}
mid.txt:
MIDDLE 1
MIDDLE 2
${include("end.txt")}
end.txt:
END
Then after loading the start.txt
file, you’ll get all files combined.
use recursive_file_loader::load_file_recursively;
use indoc::indoc;
let path = "start.txt";
let result = load_file_recursively(&path).unwrap();
assert_eq!(&result, indoc!("
START
MIDDLE 1
MIDDLE 2
END")
);
Note that the indentation in start.txt
has been applied to everything start.txt
included.