TemplateManager

Struct TemplateManager 

Source
pub struct TemplateManager { /* private fields */ }
Expand description

Manages template loading, caching, and rendering

Implementations§

Source§

impl TemplateManager

Source

pub fn new<P>(template_dir: P) -> TemplateManager
where P: AsRef<Path>,

Creates a new TemplateManager instance

§Arguments
  • template_dir - Path to the directory containing template files
Source

pub fn get_template_path(&self, path: &str) -> PathBuf

Get a full dir of a path

Source

pub fn with_caching(self, enabled: bool) -> TemplateManager

Enables or disables template caching

Source

pub fn with_max_recursion_depth(self, depth: u32) -> TemplateManager

Set the maximum recursion depth for template inheritance

Source

pub fn load_into_cache(&self, template_name: &str)

Add the template’s tokens to the cache. If it already exists, it will be replaced.

Source

pub fn get_from_cache(&self, template_name: &str) -> Option<Vec<Token>>

Get the tokenized template from the cache. If it doesn’t exist, it will returns a none

Source

pub fn load_tokens(&self, template_name: &str) -> Result<Vec<Token>, String>

Load tokens from a template file, using cache if enabled

Source

pub fn read_template_token( &self, template_name: &str, ) -> Result<Vec<Token>, String>

Tokenizes the template file

Source

pub fn render( &self, template_name: &str, data: &HashMap<String, Value>, ) -> Result<String, String>

Loads and renders a template by name

Source

pub fn render_string( &self, template_str: String, data: &HashMap<String, Value>, ) -> Result<String, String>

Source

pub fn expand_template( &self, tokens: Vec<Token>, self_dir: &str, recursion_count: &mut u32, ) -> Vec<Token>

Source

pub fn insert_template( &self, tokens: Vec<Token>, self_dir: &str, recursion_count: &mut u32, ) -> Vec<Token>

Source

pub fn extend_with_parent( &self, tokens: Vec<Token>, self_dir: &str, recursion_count: &mut u32, ) -> Result<Vec<Token>, String>

Trait Implementations§

Source§

impl Default for TemplateManager

Source§

fn default() -> TemplateManager

Returns the “default value” for a type. Read more

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V