pub struct TemplateEngine { /* private fields */ }Expand description
Compiles templates in a specific dialect and optionally provides a registry for named fragments.
Implementations§
Source§impl TemplateEngine
impl TemplateEngine
pub fn new() -> Self
pub fn with_dialect(dialect: TemplateDialect) -> Self
pub fn dialect(&self) -> TemplateDialect
Sourcepub fn add_template<N, S>(&mut self, name: N, source: S) -> Result<()>
pub fn add_template<N, S>(&mut self, name: N, source: S) -> Result<()>
Add a named template with the specified source. If name ends with
.html then automatic escaping of html entities will be performed on
substitutions.
A source that is free of expansion markers for the active dialect is stored as a literal static template, bypassing the compiler and evaluator of the engine entirely.
Sourcepub fn get_template(&self, name: &str) -> Result<Template>
pub fn get_template(&self, name: &str) -> Result<Template>
Returns the template registered under name with
TemplateEngine::add_template.
Sourcepub async fn compile(
&self,
name: &str,
source: &str,
) -> Result<Template, CompileError>
pub async fn compile( &self, name: &str, source: &str, ) -> Result<Template, CompileError>
Compiles source as a template named name, without registering it.
The compilation is cached.
Sourcepub fn prepare_context<CTX>(&self, context: CTX) -> Result<PreparedContext>where
CTX: Serialize,
pub fn prepare_context<CTX>(&self, context: CTX) -> Result<PreparedContext>where
CTX: Serialize,
Converts context into the native form for this engine’s dialect,
producing a PreparedContext that can render more than one template
without being converted again.
Sourcepub fn prepare_context_with_alias<CTX>(
&self,
context: Arc<CTX>,
alias: &str,
) -> Result<PreparedContext>
pub fn prepare_context_with_alias<CTX>( &self, context: Arc<CTX>, alias: &str, ) -> Result<PreparedContext>
Converts context as TemplateEngine::prepare_context does, and in
addition binds the whole converted value to a global variable
named alias.
Auto Trait Implementations§
impl Freeze for TemplateEngine
impl !RefUnwindSafe for TemplateEngine
impl Send for TemplateEngine
impl Sync for TemplateEngine
impl Unpin for TemplateEngine
impl !UnwindSafe for TemplateEngine
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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