Registry

Struct Registry 

Source
pub struct Registry<'reg> { /* private fields */ }
Expand description

Registry is the entry point for compiling and rendering templates.

A template name is always required for error messages.

Implementations§

Source§

impl<'reg> Registry<'reg>

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn set_strict(&mut self, strict: bool)

Set the strict mode.

Source

pub fn strict(&self) -> bool

Get the strict mode.

Source

pub fn set_escape(&mut self, escape: EscapeFn)

Set the escape function for rendering.

Source

pub fn escape(&self) -> &EscapeFn

The escape function to use for rendering.

Source

pub fn helpers(&self) -> &HelperRegistry<'reg>

Helper registry.

Source

pub fn helpers_mut(&mut self) -> &mut HelperRegistry<'reg>

Mutable reference to the helper registry.

Source

pub fn handlers(&self) -> &HandlerRegistry<'reg>

Event handler registry.

Source

pub fn handlers_mut(&mut self) -> &mut HandlerRegistry<'reg>

Mutable reference to the event handler registry.

Source

pub fn templates(&self) -> &Templates

Templates collection.

Source

pub fn templates_mut(&mut self) -> &mut Templates

Mutable reference to the templates.

Source

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

👎Deprecated since 0.9.29: Use get() instead.

Get a named template.

Source

pub fn get<S>(&self, name: S) -> Option<&Template>
where S: AsRef<str>,

Get a named template.

Source

pub fn remove<S>(&mut self, name: S) -> Option<Template>
where S: AsRef<str>,

Remove a named template.

Source

pub fn insert<N, C>(&mut self, name: N, content: C) -> Result<()>
where N: AsRef<str>, C: AsRef<str>,

Insert a named string template.

Source

pub fn add<P>(&mut self, name: String, file: P) -> Result<()>
where P: AsRef<Path>,

Add a named template from a file.

Requires the fs feature.

Source

pub fn load<P: AsRef<Path>>(&mut self, file: P) -> Result<()>

Load a file and use the file path as the template name.

Requires the fs feature.

Source

pub fn read_dir<P: AsRef<Path>>( &mut self, file: P, extension: &str, ) -> Result<()>

Load all the files in a target directory that match the given extension.

The generated name is the file stem; ie, the name of the file once the extension has been removed.

Requires the fs feature.

Source

pub fn compile<'a, S>( &self, template: S, options: ParserOptions, ) -> Result<Template>
where S: AsRef<str>,

Compile a string to a template.

To compile a template and add it to this registry use insert(), add(), load() or read_dir().

Source

pub fn parse<'a, S>(&self, name: &str, template: S) -> Result<Template>
where S: AsRef<str>,

Compile a string to a template using the given name.

This is a convenience function for calling compile() using parser options with the given name.

Source

pub fn lint<S>(&self, name: &str, template: S) -> Result<Vec<Error>>
where S: AsRef<str>,

Lint a template.

Source

pub fn once<T, S>(&self, name: &str, source: S, data: &T) -> Result<String>
where T: Serialize, S: AsRef<str>,

Render a template without registering it and return the result as a string.

This function buffers the template nodes before rendering.

Source

pub fn render<T>(&self, name: &str, data: &T) -> Result<String>
where T: Serialize,

Render a named template and buffer the result to a string.

The named template must exist in the templates collection.

Source

pub fn render_template<'a, T>( &self, name: &str, template: &Template, data: &T, ) -> Result<String>
where T: Serialize,

Render a compiled template without registering it and buffer the result to a string.

Source

pub fn render_to_write<T>( &self, name: &str, data: &T, writer: &mut impl Output, ) -> Result<()>
where T: Serialize,

Render a named template to a writer.

The named template must exist in the templates collection.

Auto Trait Implementations§

§

impl<'reg> Freeze for Registry<'reg>

§

impl<'reg> !RefUnwindSafe for Registry<'reg>

§

impl<'reg> Send for Registry<'reg>

§

impl<'reg> Sync for Registry<'reg>

§

impl<'reg> Unpin for Registry<'reg>

§

impl<'reg> !UnwindSafe for Registry<'reg>

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.