pub struct Handlebars { /* private fields */ }Expand description
The single entry point of your Handlebars templates
It maintains compiled templates and registered helpers.
Implementations§
Source§impl Registry
impl Registry
pub fn new() -> Registry
Sourcepub fn source_map_enable(&mut self, enable: bool)
pub 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.
Sourcepub fn register_template_string<S>(
&mut self,
name: &str,
tpl_str: S,
) -> Result<(), TemplateError>
pub fn register_template_string<S>( &mut self, name: &str, tpl_str: S, ) -> Result<(), TemplateError>
Register a template string
Returns TemplateError if there is syntax error on parsing template.
Sourcepub fn register_partial<S>(
&mut self,
name: &str,
partial_str: S,
) -> Result<(), TemplateError>
pub fn register_partial<S>( &mut self, name: &str, partial_str: S, ) -> Result<(), TemplateError>
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.
Sourcepub fn register_template_file<P>(
&mut self,
name: &str,
tpl_path: P,
) -> Result<(), TemplateFileError>
pub fn register_template_file<P>( &mut self, name: &str, tpl_path: P, ) -> Result<(), TemplateFileError>
Register a template from a path
Sourcepub fn register_template_source(
&mut self,
name: &str,
tpl_source: &mut dyn Read,
) -> Result<(), TemplateFileError>
pub fn register_template_source( &mut self, name: &str, tpl_source: &mut dyn Read, ) -> Result<(), TemplateFileError>
Register a template from std::io::Read source
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>,
) -> Option<Box<dyn HelperDef>>
pub fn register_helper( &mut self, name: &str, def: Box<dyn HelperDef>, ) -> Option<Box<dyn HelperDef>>
register a helper
Sourcepub fn register_decorator(
&mut self,
name: &str,
def: Box<dyn DirectiveDef>,
) -> Option<Box<dyn DirectiveDef>>
pub fn register_decorator( &mut self, name: &str, def: Box<dyn DirectiveDef>, ) -> Option<Box<dyn DirectiveDef>>
register a decorator
Sourcepub fn register_escape_fn<F>(&mut self, escape_fn: F)
pub fn register_escape_fn<F>(&mut self, escape_fn: F)
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) -> String
pub fn get_escape_fn(&self) -> &dyn Fn(&str) -> String
Get a reference to the current escape fn.
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_decorator(&self, name: &str) -> Option<&Box<dyn DirectiveDef>>
pub fn get_decorator(&self, name: &str) -> Option<&Box<dyn DirectiveDef>>
Return a registered directive, aka decorator
Sourcepub fn get_templates(&self) -> &HashMap<String, Template>
pub fn get_templates(&self) -> &HashMap<String, Template>
Return all templates registered
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: ToJson,
pub fn render<T>(&self, name: &str, data: &T) -> Result<String, RenderError>where
T: ToJson,
Render a registered template with some data into a string
nameis the template name you registred previouslyctxis the data that implementsToJsonof either rustc_serialize or serde_json
Returns rendered string or an struct with error information
Sourcepub fn renderw<T>(
&self,
name: &str,
data: &T,
writer: &mut dyn Write,
) -> Result<(), RenderError>where
T: ToJson,
pub fn renderw<T>(
&self,
name: &str,
data: &T,
writer: &mut dyn Write,
) -> Result<(), RenderError>where
T: ToJson,
Render a registered template and write some data to the std::io::Write
Sourcepub fn template_render<T>(
&self,
template_string: &str,
data: &T,
) -> Result<String, TemplateRenderError>where
T: ToJson,
pub fn template_render<T>(
&self,
template_string: &str,
data: &T,
) -> Result<String, TemplateRenderError>where
T: ToJson,
render a template string using current registry without register it
Sourcepub fn template_renderw<T>(
&self,
template_string: &str,
data: &T,
writer: &mut dyn Write,
) -> Result<(), TemplateRenderError>where
T: ToJson,
pub fn template_renderw<T>(
&self,
template_string: &str,
data: &T,
writer: &mut dyn Write,
) -> Result<(), TemplateRenderError>where
T: ToJson,
render a template string using current registry without register it
Sourcepub fn template_renderw2<T>(
&self,
template_source: &mut dyn Read,
data: &T,
writer: &mut dyn Write,
) -> Result<(), TemplateRenderError>where
T: ToJson,
pub fn template_renderw2<T>(
&self,
template_source: &mut dyn Read,
data: &T,
writer: &mut dyn Write,
) -> Result<(), TemplateRenderError>where
T: ToJson,
render a template source using current registry without register it