pub struct TemplateRenderer { /* private fields */ }Expand description
Template renderer with Tera engine
Provides template rendering with custom functions for:
- Environment variable access
- Deterministic timestamps
- SHA-256 hashing
- TOML encoding
- Macro library for common TOML patterns
Implementations§
Source§impl TemplateRenderer
impl TemplateRenderer
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Create new template renderer with custom functions and macro library
Sourcepub fn with_defaults() -> Result<Self>
pub fn with_defaults() -> Result<Self>
Create renderer with default PRD v1.0 variable resolution
Initializes context with standard variables resolved via precedence: template vars → ENV → defaults
Sourcepub fn with_context(self, context: TemplateContext) -> Self
pub fn with_context(self, context: TemplateContext) -> Self
Set template context variables
Sourcepub fn with_determinism(
self,
determinism: Arc<dyn TimestampProvider + Send + Sync>,
) -> Self
pub fn with_determinism( self, determinism: Arc<dyn TimestampProvider + Send + Sync>, ) -> Self
Set determinism engine for reproducible template rendering
When configured, this freezes now_rfc3339() function and provides
seeded random generation for fake data functions.
§Arguments
engine- DeterminismEngine with optional seed and freeze_clock
§Returns
- Self with determinism enabled
§Example
use clnrm_core::template::TemplateRenderer;
use clnrm_core::determinism::{DeterminismEngine, DeterminismConfig};
let config = DeterminismConfig {
seed: Some(42),
freeze_clock: Some("2025-01-01T00:00:00Z".to_string()),
};
let engine = DeterminismEngine::new(config).unwrap();
let renderer = TemplateRenderer::new()
.unwrap()
.with_determinism(engine);Sourcepub fn merge_user_vars(&mut self, user_vars: HashMap<String, Value>)
pub fn merge_user_vars(&mut self, user_vars: HashMap<String, Value>)
Merge user-provided variables into context (respects precedence)
User variables take highest priority in the precedence chain
Sourcepub fn render_file(&mut self, path: &Path) -> Result<String>
pub fn render_file(&mut self, path: &Path) -> Result<String>
Render template file to TOML string
Sourcepub fn render_str(&mut self, template: &str, name: &str) -> Result<String>
pub fn render_str(&mut self, template: &str, name: &str) -> Result<String>
Render template string to TOML
Sourcepub fn render_to_format(
&mut self,
template: &str,
name: &str,
format: OutputFormat,
) -> Result<String>
pub fn render_to_format( &mut self, template: &str, name: &str, format: OutputFormat, ) -> Result<String>
Render template to specific output format
§Arguments
template- Template contentname- Template name for error reportingformat- Desired output format
Sourcepub fn render_template_string(
&mut self,
template: &str,
name: &str,
) -> Result<String>
pub fn render_template_string( &mut self, template: &str, name: &str, ) -> Result<String>
Render a template string with macro imports (for testing) This is a helper method that handles the add_raw_template + render pattern
Sourcepub fn render_from_glob(
&mut self,
glob_pattern: &str,
template_name: &str,
) -> Result<String>
pub fn render_from_glob( &mut self, glob_pattern: &str, template_name: &str, ) -> Result<String>
Render template from glob pattern
Useful for rendering multiple templates with shared context
Sourcepub fn enable_inheritance(self) -> Result<Self>
pub fn enable_inheritance(self) -> Result<Self>
Add template inheritance support
Enables {% extends %} and {% block %} functionality
Sourcepub fn add_template(&mut self, name: &str, content: &str) -> Result<()>
pub fn add_template(&mut self, name: &str, content: &str) -> Result<()>
Add template to the renderer
Useful for dynamic template loading and composition
Sourcepub fn template_names(&self) -> Vec<&str>
pub fn template_names(&self) -> Vec<&str>
Get available template names
Sourcepub fn has_template(&self, name: &str) -> bool
pub fn has_template(&self, name: &str) -> bool
Check if template exists
Trait Implementations§
Source§impl Clone for TemplateRenderer
impl Clone for TemplateRenderer
Source§fn clone(&self) -> TemplateRenderer
fn clone(&self) -> TemplateRenderer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more