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>
Auto Trait Implementations§
impl<ApiFormat> !RefUnwindSafe for HumusEngineLoader<ApiFormat>
impl<ApiFormat> !UnwindSafe for HumusEngineLoader<ApiFormat>
impl<ApiFormat> Freeze for HumusEngineLoader<ApiFormat>where
PhantomData<ApiFormat>: Freeze,
impl<ApiFormat> Send for HumusEngineLoader<ApiFormat>where
PhantomData<ApiFormat>: Send,
impl<ApiFormat> Sync for HumusEngineLoader<ApiFormat>where
PhantomData<ApiFormat>: Sync,
impl<ApiFormat> Unpin for HumusEngineLoader<ApiFormat>where
PhantomData<ApiFormat>: Unpin,
impl<ApiFormat> UnsafeUnpin for HumusEngineLoader<ApiFormat>where
PhantomData<ApiFormat>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, T> ConvertInto<T> for Fwhere
T: ConvertFrom<F>,
impl<F, T> ConvertInto<T> for Fwhere
T: ConvertFrom<F>,
Source§fn convert_into(self) -> T
fn convert_into(self) -> T
Self to a value of type T.Source§impl<F, T> ConvertTryFrom<F> for Twhere
F: ConvertInto<T>,
impl<F, T> ConvertTryFrom<F> for Twhere
F: ConvertInto<T>,
Source§impl<F, T> ConvertTryInto<T> for Fwhere
T: ConvertTryFrom<F>,
impl<F, T> ConvertTryInto<T> for Fwhere
T: ConvertTryFrom<F>,
Source§type Error = <T as ConvertTryFrom<F>>::Error
type Error = <T as ConvertTryFrom<F>>::Error
Source§fn convert_try_into(self) -> Result<T, <T as ConvertTryFrom<F>>::Error>
fn convert_try_into(self) -> Result<T, <T as ConvertTryFrom<F>>::Error>
Self to a value of type T.impl<T> ErasedDestructor for Twhere
T: 'static,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more