pub struct ReloadableHandlebars { /* private fields */ }Expand description
Reloadable Handlebars.
Implementations
sourceimpl ReloadableHandlebars
impl ReloadableHandlebars
sourcepub fn new() -> ReloadableHandlebars
pub fn new() -> ReloadableHandlebars
Create an instance of ReloadableHandlebars.
sourcepub fn register_template_file<P: Into<PathBuf>>(
&mut self,
name: &'static str,
file_path: P
) -> Result<(), TemplateError>
pub fn register_template_file<P: Into<PathBuf>>(
&mut self,
name: &'static str,
file_path: P
) -> Result<(), TemplateError>
Register a template from a path and it can be reloaded automatically.
sourcepub fn unregister_template_file<S: AsRef<str>>(
&mut self,
name: S
) -> Option<PathBuf>
pub fn unregister_template_file<S: AsRef<str>>(
&mut self,
name: S
) -> Option<PathBuf>
Unregister a template from a file by a name.
sourcepub fn reload_if_needed(&mut self) -> Result<(), TemplateError>
pub fn reload_if_needed(&mut self) -> Result<(), TemplateError>
Reload templates if needed.
Methods from Deref<Target = Handlebars<'static>>
sourcepub fn set_strict_mode(&mut self, enabled: bool)
pub fn set_strict_mode(&mut self, enabled: bool)
Enable or disable handlebars strict mode
By default, handlebars renders empty string for value that
undefined or never exists. Since rust is a static type
language, we offer strict mode in handlebars-rust. In strict
mode, if you were to render a value that doesn’t exist, a
RenderError will be raised.
sourcepub fn strict_mode(&self) -> bool
pub fn strict_mode(&self) -> bool
Return strict mode state, default is false.
By default, handlebars renders empty string for value that
undefined or never exists. Since rust is a static type
language, we offer strict mode in handlebars-rust. In strict
mode, if you were access a value that doesn’t exist, a
RenderError will be raised.
sourcepub fn dev_mode(&self) -> bool
pub fn dev_mode(&self) -> bool
Return dev mode state, default is false
With dev mode turned on, handlebars enables a set of development friendly features, that may affect its performance.
sourcepub fn set_dev_mode(&mut self, enabled: bool)
pub fn set_dev_mode(&mut self, enabled: bool)
Enable or disable dev mode
With dev mode turned on, handlebars enables a set of development friendly features, that may affect its performance.
Note that you have to enable dev mode before adding templates to the registry. Otherwise it won’t take effect at all.
sourcepub fn set_prevent_indent(&mut self, enable: bool)
pub fn set_prevent_indent(&mut self, enable: bool)
Enable or disable indent for partial include tag {{>}}
By default handlebars keeps indent whitespaces for partial
include tag, to change this behaviour, set this toggle to true.
sourcepub fn prevent_indent(&self) -> bool
pub fn prevent_indent(&self) -> bool
Return state for prevent_indent option, default to false.
sourcepub fn register_template(&mut self, name: &str, tpl: Template)
pub fn register_template(&mut self, name: &str, tpl: Template)
Register a Template
This is infallible since the template has already been parsed and insert cannot fail. If there is an existing template with this name it will be overwritten.
Dev mode doesn’t apply for pre-compiled template because it’s lifecycle is not managed by the registry.
sourcepub fn register_template_string<S>(
&mut self,
name: &str,
tpl_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
pub fn register_template_string<S>(
&mut self,
name: &str,
tpl_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
Register a template string
Returns TemplateError if there is syntax error on parsing the template.
sourcepub fn register_partial<S>(
&mut self,
name: &str,
partial_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
pub fn register_partial<S>(
&mut self,
name: &str,
partial_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
Register a partial string
A named partial will be added to the registry. It will overwrite template with same name. Currently a registered partial is just identical to a template.
sourcepub fn register_template_file<P>(
&mut self,
name: &str,
tpl_path: P
) -> Result<(), TemplateError> where
P: AsRef<Path>,
pub fn register_template_file<P>(
&mut self,
name: &str,
tpl_path: P
) -> Result<(), TemplateError> where
P: AsRef<Path>,
Register a template from a path on file system
If dev mode is enabled, the registry will keep reading the template file from file system everytime it’s visited.
sourcepub fn unregister_template(&mut self, name: &str)
pub fn unregister_template(&mut self, name: &str)
Remove a template from the registry
sourcepub fn register_helper(
&mut self,
name: &str,
def: Box<dyn HelperDef + Send + Sync + 'reg, Global>
)
pub fn register_helper(
&mut self,
name: &str,
def: Box<dyn HelperDef + Send + Sync + 'reg, Global>
)
Register a helper
sourcepub fn register_decorator(
&mut self,
name: &str,
def: Box<dyn DecoratorDef + Send + Sync + 'reg, Global>
)
pub fn register_decorator(
&mut self,
name: &str,
def: Box<dyn DecoratorDef + Send + Sync + 'reg, Global>
)
Register a decorator
sourcepub fn register_escape_fn<F>(&mut self, escape_fn: F) where
F: 'static + Fn(&str) -> String + Send + Sync,
pub fn register_escape_fn<F>(&mut self, escape_fn: F) where
F: 'static + Fn(&str) -> String + Send + Sync,
Register a new escape fn to be used from now on by this registry.
sourcepub fn unregister_escape_fn(&mut self)
pub fn unregister_escape_fn(&mut self)
Restore the default escape fn.
sourcepub fn get_escape_fn(&self) -> &dyn Fn(&str)
pub fn get_escape_fn(&self) -> &dyn Fn(&str)
Get a reference to the current escape fn.
sourcepub fn has_template(&self, name: &str) -> bool
pub fn has_template(&self, name: &str) -> bool
Return true if a template is registered for the given name
sourcepub fn get_template(&self, name: &str) -> Option<&Template>
pub fn get_template(&self, name: &str) -> Option<&Template>
Return a registered template,
sourcepub fn get_templates(&self) -> &HashMap<String, Template, RandomState>
pub fn get_templates(&self) -> &HashMap<String, Template, RandomState>
Return all templates registered
Note that in dev mode, the template returned from this method may not reflect its latest state. This method doesn’t try to reload templates from its source.
sourcepub fn clear_templates(&mut self)
pub fn clear_templates(&mut self)
Unregister all templates
sourcepub fn render<T>(&self, name: &str, data: &T) -> Result<String, RenderError> where
T: Serialize,
pub fn render<T>(&self, name: &str, data: &T) -> Result<String, RenderError> where
T: Serialize,
Render a registered template with some data into a string
nameis the template name you registered previouslydatais the data that implementsserde::Serialize
Returns rendered string or a struct with error information
sourcepub fn render_with_context(
&self,
name: &str,
ctx: &Context
) -> Result<String, RenderError>
pub fn render_with_context(
&self,
name: &str,
ctx: &Context
) -> Result<String, RenderError>
Render a registered template with reused context
sourcepub fn render_to_write<T, W>(
&self,
name: &str,
data: &T,
writer: W
) -> Result<(), RenderError> where
T: Serialize,
W: Write,
pub fn render_to_write<T, W>(
&self,
name: &str,
data: &T,
writer: W
) -> Result<(), RenderError> where
T: Serialize,
W: Write,
Render a registered template and write some data to the std::io::Write
sourcepub fn render_template<T>(
&self,
template_string: &str,
data: &T
) -> Result<String, RenderError> where
T: Serialize,
pub fn render_template<T>(
&self,
template_string: &str,
data: &T
) -> Result<String, RenderError> where
T: Serialize,
Render a template string using current registry without registering it
sourcepub fn render_template_with_context(
&self,
template_string: &str,
ctx: &Context
) -> Result<String, RenderError>
pub fn render_template_with_context(
&self,
template_string: &str,
ctx: &Context
) -> Result<String, RenderError>
Render a template string using reused context data
sourcepub fn render_template_to_write<T, W>(
&self,
template_string: &str,
data: &T,
writer: W
) -> Result<(), RenderError> where
T: Serialize,
W: Write,
pub fn render_template_to_write<T, W>(
&self,
template_string: &str,
data: &T,
writer: W
) -> Result<(), RenderError> where
T: Serialize,
W: Write,
Render a template string using current registry without registering it
Trait Implementations
sourceimpl Debug for ReloadableHandlebars
impl Debug for ReloadableHandlebars
sourceimpl Default for ReloadableHandlebars
impl Default for ReloadableHandlebars
sourceimpl Deref for ReloadableHandlebars
impl Deref for ReloadableHandlebars
Auto Trait Implementations
impl !RefUnwindSafe for ReloadableHandlebars
impl Send for ReloadableHandlebars
impl Sync for ReloadableHandlebars
impl Unpin for ReloadableHandlebars
impl !UnwindSafe for ReloadableHandlebars
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> IntoCollection<T> for T
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self into a collection.
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
F: FnMut(T) -> U,
A: Array<Item = U>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more