pub struct HumusEngineLoader<ApiFormat: HumusApiFormat> {
pub template_location: PathBuf,
pub extra_config_location: Option<PathBuf>,
pub tera: Tera,
/* private fields */
}Expand description
Helps loading a HumusEngine from disk.
This merges settings from a configuration file and from command line arguments and then loads both the TemplatingEngine and LanguageEngine into a working HumusEngine.
For documentation of the on disk format see the template directory documentation.
The functions doing the actual work are TemplatingEngine::load_from_directory and LanguageEngine::load_from_directory.
Example:
use lib_humus::HumusEngineLoader;
use lib_humus::crates::tera::Tera;
let template_loader = HumusEngineLoader::new(
config.template.template_location.clone(),
config.template.extra_config.clone(),
Tera::new(),
)
.cli_template_location(cli_args.template_location)
.cli_extra_config_location(cli_args.extra_config);
let templating_engine = match template_loader.load_templates() {
Ok(t) => t.into(),
Err(e) => {
println!("{e}");
::std::process::exit(1);
}
};Fields§
§template_location: PathBufThe path to the directory where the templates are.
extra_config_location: Option<PathBuf>The path to the extra configuration (relative to the current pwd, not to the templates)
tera: TeraThe empty templaing engine. It is accessible so you can add customizations before loading the templates.
Implementations§
Source§impl<ApiFormat: HumusApiFormat> HumusEngineLoader<ApiFormat>
impl<ApiFormat: HumusApiFormat> HumusEngineLoader<ApiFormat>
Sourcepub fn new(
template_location: PathBuf,
extra_config_location: Option<PathBuf>,
) -> Self
pub fn new( template_location: PathBuf, extra_config_location: Option<PathBuf>, ) -> Self
Creates a new HumusEngineLoader with minimal typing.
Sourcepub fn cli_template_location(self, location: Option<PathBuf>) -> Self
pub fn cli_template_location(self, location: Option<PathBuf>) -> Self
Overrides the template location with a new location if it is set.
Intended for processing cli-options.
Sourcepub fn cli_extra_config_location(self, location: Option<PathBuf>) -> Self
pub fn cli_extra_config_location(self, location: Option<PathBuf>) -> Self
Overrides the extra configuration location with a new location if it is set.
Intended for processing cli-options.
Sourcepub fn load_templates(
&self,
) -> Result<HumusEngine<ApiFormat>, HumusEngineLoaderError>
pub fn load_templates( &self, ) -> Result<HumusEngine<ApiFormat>, HumusEngineLoaderError>
Initialize a HumusEngine with the given templates and extra configuration.
Failure Modes:
- The
extra.tomlwas not found and the path was explicitly set. - The
extra.tomlwas found and is not valid toml. - The
extra.tomlpasses, but tera finds an error in the templates.
If extra_config_location is None no error is returned if the extra.toml
was not found as the template might not require one.
Trait Implementations§
Source§impl<ApiFormat: Clone + HumusApiFormat> Clone for HumusEngineLoader<ApiFormat>
impl<ApiFormat: Clone + HumusApiFormat> Clone for HumusEngineLoader<ApiFormat>
Source§fn clone(&self) -> HumusEngineLoader<ApiFormat>
fn clone(&self) -> HumusEngineLoader<ApiFormat>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more