pub struct Engine { /* private fields */ }Expand description
The forge rendering engine.
Wrap Tera with:
- Custom filters:
snake_case,pascal_case,camel_case,kebab_case - Import hoisting filters:
collect_import,collect_import_priority - Import drain function:
render_imports() - Tier-aware template registry
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an engine with all forge extensions registered. No templates loaded yet.
Sourcepub fn load_dir(&mut self, dir: &Path) -> Result<(), ForgeError>
pub fn load_dir(&mut self, dir: &Path) -> Result<(), ForgeError>
Load all .jinja and .forge template files from dir recursively.
Template names are relative paths from dir with forward slashes.
Sourcepub fn load_embedded(
&mut self,
templates: &[(&str, &str)],
) -> Result<(), ForgeError>
pub fn load_embedded( &mut self, templates: &[(&str, &str)], ) -> Result<(), ForgeError>
Load templates from embedded (name, content) pairs (for binary embedding).
Sourcepub fn add_raw(&mut self, name: &str, content: &str) -> Result<(), ForgeError>
pub fn add_raw(&mut self, name: &str, content: &str) -> Result<(), ForgeError>
Add a single raw template by name and content string.
Sourcepub fn render(
&self,
name: &str,
ctx: &ForgeContext,
) -> Result<String, ForgeError>
pub fn render( &self, name: &str, ctx: &ForgeContext, ) -> Result<String, ForgeError>
Render a template by name with the given context. Resets the ImportCollector and populates slots before rendering.
Sourcepub fn render_continue(
&self,
name: &str,
ctx: &ForgeContext,
) -> Result<String, ForgeError>
pub fn render_continue( &self, name: &str, ctx: &ForgeContext, ) -> Result<String, ForgeError>
Render without resetting the ImportCollector or slots. Use when rendering multiple templates in sequence and collecting all their imports.
Sourcepub fn has_template(&self, name: &str) -> bool
pub fn has_template(&self, name: &str) -> bool
Check whether a template with this name is loaded.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Engine
impl !RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl !UnwindSafe for Engine
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