Handlebars

Struct Handlebars 

Source
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

Source

pub fn new() -> Registry

Source

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.

Source

pub fn register_template_string<S>( &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.

Source

pub fn register_partial<S>( &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.

Source

pub fn register_template_file<P>( &mut self, name: &str, tpl_path: P, ) -> Result<(), TemplateFileError>
where P: AsRef<Path>,

Register a template from a path

Source

pub fn register_template_source( &mut self, name: &str, tpl_source: &mut dyn Read, ) -> Result<(), TemplateFileError>

Register a template from std::io::Read source

Source

pub fn unregister_template(&mut self, name: &str)

remove a template from the registry

Source

pub fn register_helper( &mut self, name: &str, def: Box<dyn HelperDef>, ) -> Option<Box<dyn HelperDef>>

register a helper

Source

pub fn register_decorator( &mut self, name: &str, def: Box<dyn DirectiveDef>, ) -> Option<Box<dyn DirectiveDef>>

register a decorator

Source

pub fn register_escape_fn<F>(&mut self, escape_fn: F)
where F: 'static + Fn(&str) -> String + Send + Sync,

Register a new escape fn to be used from now on by this registry.

Source

pub fn unregister_escape_fn(&mut self)

Restore the default escape fn.

Source

pub fn get_escape_fn(&self) -> &dyn Fn(&str) -> String

Get a reference to the current escape fn.

Source

pub fn get_template(&self, name: &str) -> Option<&Template>

Return a registered template,

Source

pub fn get_helper(&self, name: &str) -> Option<&Box<dyn HelperDef>>

Return a registered helper

Source

pub fn get_decorator(&self, name: &str) -> Option<&Box<dyn DirectiveDef>>

Return a registered directive, aka decorator

Source

pub fn get_templates(&self) -> &HashMap<String, Template>

Return all templates registered

Source

pub fn clear_templates(&mut self)

Unregister all templates

Source

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

  • name is the template name you registred previously
  • ctx is the data that implements ToJson of either rustc_serialize or serde_json

Returns rendered string or an struct with error information

Source

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

Source

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

Source

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

Source

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<T> UnsafeAny for T
where T: Any,