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>
impl<'reg> Registry<'reg>
Sourcepub fn set_strict(&mut self, strict: bool)
pub fn set_strict(&mut self, strict: bool)
Set the strict mode.
Sourcepub fn set_escape(&mut self, escape: EscapeFn)
pub fn set_escape(&mut self, escape: EscapeFn)
Set the escape function for rendering.
Sourcepub fn helpers(&self) -> &HelperRegistry<'reg>
pub fn helpers(&self) -> &HelperRegistry<'reg>
Helper registry.
Sourcepub fn helpers_mut(&mut self) -> &mut HelperRegistry<'reg>
pub fn helpers_mut(&mut self) -> &mut HelperRegistry<'reg>
Mutable reference to the helper registry.
Sourcepub fn handlers(&self) -> &HandlerRegistry<'reg>
pub fn handlers(&self) -> &HandlerRegistry<'reg>
Event handler registry.
Sourcepub fn handlers_mut(&mut self) -> &mut HandlerRegistry<'reg>
pub fn handlers_mut(&mut self) -> &mut HandlerRegistry<'reg>
Mutable reference to the event handler registry.
Sourcepub fn templates_mut(&mut self) -> &mut Templates
pub fn templates_mut(&mut self) -> &mut Templates
Mutable reference to the templates.
Sourcepub fn get_template(&self, name: &str) -> Option<&Template>
👎Deprecated since 0.9.29: Use get() instead.
pub fn get_template(&self, name: &str) -> Option<&Template>
Get a named template.
Sourcepub fn insert<N, C>(&mut self, name: N, content: C) -> Result<()>
pub fn insert<N, C>(&mut self, name: N, content: C) -> Result<()>
Insert a named string template.
Sourcepub fn add<P>(&mut self, name: String, file: P) -> Result<()>
pub fn add<P>(&mut self, name: String, file: P) -> Result<()>
Add a named template from a file.
Requires the fs feature.
Sourcepub fn load<P: AsRef<Path>>(&mut self, file: P) -> Result<()>
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.
Sourcepub fn read_dir<P: AsRef<Path>>(
&mut self,
file: P,
extension: &str,
) -> Result<()>
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.
Sourcepub fn compile<'a, S>(
&self,
template: S,
options: ParserOptions,
) -> Result<Template>
pub fn compile<'a, S>( &self, template: S, options: ParserOptions, ) -> Result<Template>
Compile a string to a template.
To compile a template and add it to this registry use insert(), add(), load() or read_dir().
Sourcepub fn parse<'a, S>(&self, name: &str, template: S) -> Result<Template>
pub fn parse<'a, S>(&self, name: &str, template: S) -> Result<Template>
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.
Sourcepub fn once<T, S>(&self, name: &str, source: S, data: &T) -> Result<String>
pub fn once<T, S>(&self, name: &str, source: S, data: &T) -> Result<String>
Render a template without registering it and return the result as a string.
This function buffers the template nodes before rendering.
Sourcepub fn render<T>(&self, name: &str, data: &T) -> Result<String>where
T: Serialize,
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.