Struct handlebars::Handlebars
[−]
[src]
pub struct Handlebars { /* fields omitted */ }
The single entry point of your Handlebars templates
It maintains compiled templates and registered helpers.
Methods
impl Registry
[src]
fn new() -> Registry
fn source_map_enable(&mut self, enable: bool)
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.
fn register_template_string<S>(
&mut self,
name: &str,
tpl_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
&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.
fn register_partial<S>(
&mut self,
name: &str,
partial_str: S
) -> Result<(), TemplateError> where
S: AsRef<str>,
&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.
fn register_template_file<P>(
&mut self,
name: &str,
tpl_path: P
) -> Result<(), TemplateFileError> where
P: AsRef<Path>,
&mut self,
name: &str,
tpl_path: P
) -> Result<(), TemplateFileError> where
P: AsRef<Path>,
Register a template from a path
fn register_template_source(
&mut self,
name: &str,
tpl_source: &mut Read
) -> Result<(), TemplateFileError>
&mut self,
name: &str,
tpl_source: &mut Read
) -> Result<(), TemplateFileError>
Register a template from std::io::Read
source
fn unregister_template(&mut self, name: &str)
remove a template from the registry
fn register_helper(
&mut self,
name: &str,
def: Box<HelperDef + 'static>
) -> Option<Box<HelperDef + 'static>>
&mut self,
name: &str,
def: Box<HelperDef + 'static>
) -> Option<Box<HelperDef + 'static>>
register a helper
fn register_decorator(
&mut self,
name: &str,
def: Box<DirectiveDef + 'static>
) -> Option<Box<DirectiveDef + 'static>>
&mut self,
name: &str,
def: Box<DirectiveDef + 'static>
) -> Option<Box<DirectiveDef + 'static>>
register a decorator
fn register_escape_fn<F: 'static + Fn(&str) -> String + Send + Sync>(
&mut self,
escape_fn: F
)
&mut self,
escape_fn: F
)
Register a new escape fn to be used from now on by this registry.
fn unregister_escape_fn(&mut self)
Restore the default escape fn.
fn get_escape_fn(&self) -> &Fn(&str) -> String
Get a reference to the current escape fn.
fn get_template(&self, name: &str) -> Option<&Template>
Return a registered template,
fn get_helper(&self, name: &str) -> Option<&Box<HelperDef + 'static>>
Return a registered helper
fn get_decorator(&self, name: &str) -> Option<&Box<DirectiveDef + 'static>>
Return a registered directive, aka decorator
fn get_templates(&self) -> &HashMap<String, Template>
Return all templates registered
fn clear_templates(&mut self)
Unregister all templates
fn render<T>(&self, name: &str, data: &T) -> Result<String, RenderError> where
T: Serialize,
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
fn renderw<T>(
&self,
name: &str,
data: &T,
writer: &mut Write
) -> Result<(), RenderError> where
T: Serialize,
&self,
name: &str,
data: &T,
writer: &mut Write
) -> Result<(), RenderError> where
T: Serialize,
Render a registered template and write some data to the std::io::Write
fn template_render<T>(
&self,
template_string: &str,
data: &T
) -> Result<String, TemplateRenderError> where
T: Serialize,
&self,
template_string: &str,
data: &T
) -> Result<String, TemplateRenderError> where
T: Serialize,
render a template string using current registry without register it
fn template_renderw<T>(
&self,
template_string: &str,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: Serialize,
&self,
template_string: &str,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: Serialize,
render a template string using current registry without register it
fn template_renderw2<T>(
&self,
template_source: &mut Read,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: Serialize,
&self,
template_source: &mut Read,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: Serialize,
render a template source using current registry without register it