pub struct TemplateLoader { /* private fields */ }Expand description
Where a template and the templates it names are found.
Directories are searched first, in the order given, then the registered pairs — which is how a Rust consumer supplies templates embedded in its own binary. The working directory is never searched unless it is given.
Implementations§
Source§impl TemplateLoader
impl TemplateLoader
Sourcepub fn with_directory(self, directory: impl Into<PathBuf>) -> Self
pub fn with_directory(self, directory: impl Into<PathBuf>) -> Self
Add directory to the end of the search path’s directories.
Sourcepub fn with_template(
self,
name: impl Into<String>,
source: impl Into<String>,
) -> Self
pub fn with_template( self, name: impl Into<String>, source: impl Into<String>, ) -> Self
Register a template’s source under name, searched after every directory.
Sourcepub fn load_path(&self, path: &Path) -> Result<Template, TemplateError>
pub fn load_path(&self, path: &Path) -> Result<Template, TemplateError>
Load the template at path and every template its chain names.
The file is known to its chain — and in its digest — by its file name.
§Errors
TemplateError::NotFound for a file that cannot be read or a chain name nothing
resolves; TemplateError::Malformed for a chain file that is not UTF-8, whose front
matter is refused, or whose body does not parse; TemplateError::ChainConflict for
a variable two chain files type differently; TemplateError::SearchPath for a
search path directory that is missing or is not a directory.
Sourcepub fn load_name(&self, name: &str) -> Result<Template, TemplateError>
pub fn load_name(&self, name: &str) -> Result<Template, TemplateError>
Load the template the search path resolves name to, and every template its chain
names.
§Errors
As TemplateLoader::load_path, and TemplateError::NotFound when the search
path resolves name to nothing.