Struct chilli::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]
pub fn new() -> Registry
[src]
pub fn source_map_enable(&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 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_template_source(
&mut self,
name: &str,
tpl_source: &mut Read
) -> Result<(), TemplateFileError>
[src]
&mut self,
name: &str,
tpl_source: &mut 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<HelperDef + 'static>
) -> Option<Box<HelperDef + 'static>>
[src]
&mut self,
name: &str,
def: Box<HelperDef + 'static>
) -> Option<Box<HelperDef + 'static>>
register a helper
pub fn register_decorator(
&mut self,
name: &str,
def: Box<DirectiveDef + 'static>
) -> Option<Box<DirectiveDef + 'static>>
[src]
&mut self,
name: &str,
def: Box<DirectiveDef + 'static>
) -> Option<Box<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) -> &Fn(&str)
[src]
Get a reference to the current escape fn.
pub fn get_template(&self, name: &str) -> Option<&Template>
[src]
Return a registered template,
pub fn get_helper(&self, name: &str) -> Option<&Box<HelperDef + 'static>>
[src]
Return a registered helper
pub fn get_decorator(&self, name: &str) -> Option<&Box<DirectiveDef + 'static>>
[src]
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: ToJson,
[src]
T: ToJson,
Render a registered template with some data into a string
name
is the template name you registred previouslyctx
is the data that implementsToJson
of either rustc_serialize or serde_json
Returns rendered string or an struct with error information
pub fn renderw<T>(
&self,
name: &str,
data: &T,
writer: &mut Write
) -> Result<(), RenderError> where
T: ToJson,
[src]
&self,
name: &str,
data: &T,
writer: &mut Write
) -> Result<(), RenderError> where
T: ToJson,
Render a registered template and write some data to the std::io::Write
pub fn template_render<T>(
&self,
template_string: &str,
data: &T
) -> Result<String, TemplateRenderError> where
T: ToJson,
[src]
&self,
template_string: &str,
data: &T
) -> Result<String, TemplateRenderError> where
T: ToJson,
render a template string using current registry without register it
pub fn template_renderw<T>(
&self,
template_string: &str,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: ToJson,
[src]
&self,
template_string: &str,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: ToJson,
render a template string using current registry without register it
pub fn template_renderw2<T>(
&self,
template_source: &mut Read,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: ToJson,
[src]
&self,
template_source: &mut Read,
data: &T,
writer: &mut Write
) -> Result<(), TemplateRenderError> where
T: ToJson,
render a template source using current registry without register it