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
fn register_template(&mut self, name: &str, template: Template)
Register a template
fn register_template_string(&mut self, name: &str, tpl_str: String) -> Result<(), TemplateError>
Register a template string
fn register_template_file<P: AsRef<Path>>(&mut self, name: &str, tpl_path: P) -> Result<(), TemplateFileError>
Register a template from a path
fn register_template_source(&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>>
register a helper
fn register_decorator(&mut self, name: &str, def: Box<DirectiveDef + 'static>) -> Option<Box<DirectiveDef + 'static>>
register a directive
fn register_escape_fn<F: 'static + Fn(&str) -> String + Send + Sync>(&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, ctx: &T) -> Result<String, RenderError> where T: ToJson
Render a registered template with some data into a string
fn renderw(&self, name: &str, context: &Context, writer: &mut Write) -> Result<(), RenderError>
Render a registered template with some data to the std::io::Write
fn template_render<T>(&self, template_string: &str, ctx: &T) -> Result<String, TemplateRenderError> where T: ToJson
render a template string using current registry without register it
fn template_renderw(&self, template_string: &str, context: &Context, writer: &mut Write) -> Result<(), TemplateRenderError>
render a template string using current registry without register it
fn template_renderw2(&self, template_source: &mut Read, context: &Context, writer: &mut Write) -> Result<(), TemplateRenderError>
render a template source using current registry without register it