pub struct Engine { /* private fields */ }Expand description
Tera-backed Markdown rendering engine for the nils-cli workspace.
Engine is constructed via Engine::builder so the determinism
posture (no auto-escape, no now()) is enforced in one place.
Templates are registered as raw (name, body) pairs, which lets
consumer crates ship .md.tera assets through include_str!
without filesystem lookups at runtime.
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn builder() -> EngineBuilder
pub fn builder() -> EngineBuilder
Returns an EngineBuilder configured for deterministic
rendering. Always start engines from Engine::builder() —
Engine has no public constructor besides this builder.
Sourcepub fn register_template(
&mut self,
name: &str,
body: &str,
) -> Result<(), RenderError>
pub fn register_template( &mut self, name: &str, body: &str, ) -> Result<(), RenderError>
Register a template body under name. The body is parsed
eagerly so syntax errors surface at registration time rather
than render time. The check for now() calls is the only
content gate; everything else is delegated to Tera’s parser.
Sourcepub fn render_value(
&self,
name: &str,
view: &Value,
) -> Result<String, RenderError>
pub fn render_value( &self, name: &str, view: &Value, ) -> Result<String, RenderError>
Render a registered template against an opaque
serde_json::Value view. This is the entry point the
md-render binary will use in Sprint 3.
Sourcepub fn render<T: Serialize>(
&self,
name: &str,
view: &T,
) -> Result<String, RenderError>
pub fn render<T: Serialize>( &self, name: &str, view: &T, ) -> Result<String, RenderError>
Render a registered template against a typed view struct.
Consumers prepare a flat serde::Serialize view in Rust and
hand it to this method; the engine performs the
serde_json::to_value conversion and the Tera render in one
step.
Sourcepub fn render_str<T: Serialize>(
&mut self,
body: &str,
view: &T,
) -> Result<String, RenderError>
pub fn render_str<T: Serialize>( &mut self, body: &str, view: &T, ) -> Result<String, RenderError>
Render a literal template body without persistently
registering it. The body is checked for now() calls and
then rendered with the engine’s registered helpers and the
supplied view. This is the migration path for callers that
today use Tera::render_str directly and treat every render
as a fresh one-shot template.
Sourcepub fn register_helper<F>(&mut self, name: &str, function: F)where
F: Function + 'static,
pub fn register_helper<F>(&mut self, name: &str, function: F)where
F: Function + 'static,
Attach a domain-specific Tera function under name. This is
the consumer extension point for Task 1.4: nils-agent-runtime’s
cli_ref / script / skill_ref / state_out helpers register
here without nils-markdown knowing the consumer’s domain.