Skip to main content

ggen_core/codegen_lib/
renderable.rs

1//! Trait for template rendering in code generation rules
2//!
3//! Abstracts template rendering with context bindings.
4
5use crate::codegen_lib::Result;
6use std::collections::HashMap;
7
8/// Trait for template rendering
9///
10/// Abstracts template rendering with context bindings.
11/// Implementors transform query bindings into rendered output.
12pub trait Renderable: Send + Sync {
13    /// Render template with given context bindings
14    ///
15    /// # Arguments
16    /// * `bindings` - Query variable bindings (e.g., {"className": "TestClass", ...})
17    ///
18    /// # Returns
19    /// Rendered content (typically source code)
20    fn render(&self, bindings: &HashMap<String, String>) -> Result<String>;
21
22    /// Template name for logging/auditing
23    fn name(&self) -> &str;
24
25    /// Optional: template source for debugging
26    fn source(&self) -> Option<&str> {
27        None
28    }
29}