Skip to main content

Crate tsx_forge

Crate tsx_forge 

Source
Expand description

forge — 4-tier code generation engine for the tsx Framework Protocol.

§Overview

forge is built on Tera and extends it with:

  • 4-tier template hierarchyAtom → Molecule → Layout → Feature (classified automatically from template paths)
  • Import hoisting — templates call {{ "import x from 'x'" | collect_import }} and {{ render_imports() }} at the top of the file to emit a deduplicated import block.
  • Token-budget metadata — knowledge .md files carry token_estimate in frontmatter so agents can request exactly as much context as they need.
  • Framework package loading — load templates from disk, embedded bytes, or npm packages.

§Quick Start

use forge::{Engine, ForgeContext};

let mut engine = Engine::new();
engine.add_raw("hello.jinja", "Hello {{ name | pascal_case }}!").unwrap();

let ctx = ForgeContext::new().insert("name", "world");
let out = engine.render("hello.jinja", &ctx).unwrap();
assert_eq!(out, "Hello World!");

Re-exports§

pub use context::ForgeContext;
pub use engine::Engine;
pub use error::ForgeError;
pub use metadata::parse as parse_frontmatter;
pub use metadata::FrontMatter;
pub use tier::Tier;

Modules§

collector
Import hoisting for code generation templates.
context
ForgeContext — a context builder for forge template rendering.
engine
The forge Engine — a Tera wrapper with the 4-tier system, import hoisting, and framework package loading built in.
error
filters
Custom Tera filters and functions for forge.
metadata
Frontmatter parser for forge knowledge files.
provide
Provide/Inject context propagation for forge.
slots
Component slot system for forge.
tier