[−][src]Struct rocket_include_handlebars::ReloadableHandlebars
Reloadable Handlebars.
Methods
impl ReloadableHandlebars
[src]
pub fn new() -> ReloadableHandlebars
[src]
Create an instance of ReloadableHandlebars
.
pub fn register_template_file<S: Into<String>, P: Into<PathBuf>>(
&mut self,
name: S,
file_path: P
) -> Result<(), TemplateFileError>
[src]
&mut self,
name: S,
file_path: P
) -> Result<(), TemplateFileError>
Register a template from a path and it can be reloaded automatically.
pub fn unregister_template_file<S: AsRef<str>>(
&mut self,
name: S
) -> Option<PathBuf>
[src]
&mut self,
name: S
) -> Option<PathBuf>
Unregister a template from a file by a name.
pub fn reload_if_needed(&mut self) -> Result<(), TemplateFileError>
[src]
Reload templates if needed.
Methods from Deref<Target = Handlebars>
pub fn source_map_enabled(&mut self, enable: bool)
[src]
Enable handlebars template source map
Source map provides line/col reporting on error. It uses slightly more memory to maintain the data.
Default is true.
pub fn set_strict_mode(&mut self, enable: bool)
[src]
Enable 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 access a value that doesn't exist, a
RenderError
will be raised.
pub fn strict_mode(&self) -> bool
[src]
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.
pub fn register_template_string<S>(
&mut self,
name: &str,
tpl_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
[src]
&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 template.
pub fn register_partial<S>(
&mut self,
name: &str,
partial_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
[src]
&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 registered partial is just identical to template.
pub fn register_template_file<P>(
&mut self,
name: &str,
tpl_path: P
) -> Result<(), TemplateFileError> where
P: AsRef<Path>,
[src]
&mut self,
name: &str,
tpl_path: P
) -> Result<(), TemplateFileError> where
P: AsRef<Path>,
Register a template from a path
pub fn register_templates_directory<P>(
&mut self,
tpl_extension: &'static str,
dir_path: P
) -> Result<(), TemplateFileError> where
P: AsRef<Path>,
[src]
&mut self,
tpl_extension: &'static str,
dir_path: P
) -> Result<(), TemplateFileError> where
P: AsRef<Path>,
Register templates from a directory
tpl_extension
: the template file extensiondir_path
: the path of directory
Hidden files and tempfile (starts with #
) will be ignored. All registered
will use their relative name as template name. For example, when dir_path
is
templates/
and tpl_extension
is .hbs
, the file
templates/some/path/file.hbs
will be registerd as some/path/file
.
pub fn register_template_source(
&mut self,
name: &str,
tpl_source: &mut dyn Read
) -> Result<(), TemplateFileError>
[src]
&mut self,
name: &str,
tpl_source: &mut dyn Read
) -> Result<(), TemplateFileError>
Register a template from std::io::Read
source
pub fn unregister_template(&mut self, name: &str)
[src]
remove a template from the registry
pub fn register_helper(
&mut self,
name: &str,
def: Box<dyn HelperDef + 'static>
) -> Option<Box<dyn HelperDef + 'static>>
[src]
&mut self,
name: &str,
def: Box<dyn HelperDef + 'static>
) -> Option<Box<dyn HelperDef + 'static>>
register a helper
pub fn register_decorator(
&mut self,
name: &str,
def: Box<dyn DirectiveDef + 'static>
) -> Option<Box<dyn DirectiveDef + 'static>>
[src]
&mut self,
name: &str,
def: Box<dyn DirectiveDef + 'static>
) -> Option<Box<dyn DirectiveDef + 'static>>
register a decorator
pub fn register_escape_fn<F>(&mut self, escape_fn: F) where
F: 'static + Send + Sync + Fn(&str) -> String,
[src]
F: 'static + Send + Sync + Fn(&str) -> String,
Register a new escape fn to be used from now on by this registry.
pub fn unregister_escape_fn(&mut self)
[src]
Restore the default escape fn.
pub fn get_escape_fn(&self) -> &dyn Fn(&str)
[src]
Get a reference to the current escape fn.
pub fn has_template(&self, name: &str) -> bool
[src]
Return true
if a template is registered for the given name
pub fn get_template(&self, name: &str) -> Option<&Template>
[src]
Return a registered template,
pub fn get_helper(&self, name: &str) -> Option<&Box<dyn HelperDef + 'static>>
[src]
Return a registered helper
pub fn get_decorator(
&self,
name: &str
) -> Option<&Box<dyn DirectiveDef + 'static>>
[src]
&self,
name: &str
) -> Option<&Box<dyn DirectiveDef + 'static>>
Return a registered directive, aka decorator
pub fn get_templates(&self) -> &HashMap<String, Template, RandomState>
[src]
Return all templates registered
pub fn clear_templates(&mut self)
[src]
Unregister all templates
pub fn render<T>(&self, name: &str, data: &T) -> Result<String, RenderError> where
T: Serialize,
[src]
T: Serialize,
Render a registered template with some data into a string
name
is the template name you registred previouslyctx
is the data that implementsserde::Serialize
Returns rendered string or an struct with error information
pub fn render_to_write<T, W>(
&self,
name: &str,
data: &T,
writer: W
) -> Result<(), RenderError> where
T: Serialize,
W: Write,
[src]
&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
pub fn render_template<T>(
&self,
template_string: &str,
data: &T
) -> Result<String, TemplateRenderError> where
T: Serialize,
[src]
&self,
template_string: &str,
data: &T
) -> Result<String, TemplateRenderError> where
T: Serialize,
render a template string using current registry without register it
pub fn render_template_to_write<T, W>(
&self,
template_string: &str,
data: &T,
writer: W
) -> Result<(), TemplateRenderError> where
T: Serialize,
W: Write,
[src]
&self,
template_string: &str,
data: &T,
writer: W
) -> Result<(), TemplateRenderError> where
T: Serialize,
W: Write,
render a template string using current registry without register it
pub fn render_template_source_to_write<T, W>(
&self,
template_source: &mut dyn Read,
data: &T,
writer: W
) -> Result<(), TemplateRenderError> where
T: Serialize,
W: Write,
[src]
&self,
template_source: &mut dyn Read,
data: &T,
writer: W
) -> Result<(), TemplateRenderError> where
T: Serialize,
W: Write,
render a template source using current registry without register it
Trait Implementations
impl DerefMut for ReloadableHandlebars
[src]
impl Debug for ReloadableHandlebars
[src]
impl Deref for ReloadableHandlebars
[src]
type Target = Handlebars
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Auto Trait Implementations
impl Send for ReloadableHandlebars
impl Sync for ReloadableHandlebars
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Typeable for T where
T: Any,
T: Any,
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T, I> AsResult<T, I> for T where
I: Input,
I: Input,