pub struct TemplateManager { /* private fields */ }Expand description
Manages template loading, caching, and rendering
Implementations§
Source§impl TemplateManager
impl TemplateManager
Sourcepub fn new<P>(template_dir: P) -> TemplateManager
pub fn new<P>(template_dir: P) -> TemplateManager
Creates a new TemplateManager instance
§Arguments
template_dir- Path to the directory containing template files
Sourcepub fn get_template_path(&self, path: &str) -> PathBuf
pub fn get_template_path(&self, path: &str) -> PathBuf
Get a full dir of a path
Sourcepub fn with_caching(self, enabled: bool) -> TemplateManager
pub fn with_caching(self, enabled: bool) -> TemplateManager
Enables or disables template caching
Sourcepub fn with_max_recursion_depth(self, depth: u32) -> TemplateManager
pub fn with_max_recursion_depth(self, depth: u32) -> TemplateManager
Set the maximum recursion depth for template inheritance
Sourcepub fn load_into_cache(&self, template_name: &str)
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.
Sourcepub fn get_from_cache(&self, template_name: &str) -> Option<Vec<Token>>
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
Sourcepub fn load_tokens(&self, template_name: &str) -> Result<Vec<Token>, String>
pub fn load_tokens(&self, template_name: &str) -> Result<Vec<Token>, String>
Load tokens from a template file, using cache if enabled
Sourcepub fn read_template_token(
&self,
template_name: &str,
) -> Result<Vec<Token>, String>
pub fn read_template_token( &self, template_name: &str, ) -> Result<Vec<Token>, String>
Tokenizes the template file
Sourcepub fn render(
&self,
template_name: &str,
data: &HashMap<String, Value>,
) -> Result<String, String>
pub fn render( &self, template_name: &str, data: &HashMap<String, Value>, ) -> Result<String, String>
Loads and renders a template by name
pub fn render_string( &self, template_str: String, data: &HashMap<String, Value>, ) -> Result<String, String>
pub fn expand_template( &self, tokens: Vec<Token>, self_dir: &str, recursion_count: &mut u32, ) -> Vec<Token>
pub fn insert_template( &self, tokens: Vec<Token>, self_dir: &str, recursion_count: &mut u32, ) -> Vec<Token>
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
impl Default for TemplateManager
Source§fn default() -> TemplateManager
fn default() -> TemplateManager
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TemplateManager
impl RefUnwindSafe for TemplateManager
impl Send for TemplateManager
impl Sync for TemplateManager
impl Unpin for TemplateManager
impl UnwindSafe for TemplateManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more