gracile-core 0.1.0

Core engine for the Gracile templating language — lexer, parser, AST, and renderer
Documentation
  • Coverage
  • 24.68%
    57 out of 231 items documented4 out of 53 items with examples
  • Size
  • Source code size: 210.03 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 13.48 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • thwbh/gracile
    0 0 6
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • thwbh

gracile-core

gracile-core

The engine at the heart of Gracile. Contains the lexer, parser, AST, and renderer. Use this crate directly if you want to embed the engine into your own library or framework without the re-export layer.

[dependencies]
gracile-core = "0.1"
use gracile_core::{Engine, Value, FilterFn};
use std::collections::HashMap;

let engine = Engine::new()
    .with_strict()
    .with_template_loader(|name| {
        std::fs::read_to_string(format!("templates/{}", name))
            .map_err(|e| gracile_core::Error::RenderError {
                message: e.to_string(),
            })
    })
    .register_filter("shout", |val, _args| {
        match val {
            Value::String(s) => Ok(Value::String(format!("{}!!!", s.to_uppercase()))),
            other => Ok(other),
        }
    });

let mut ctx = HashMap::new();
ctx.insert("title".into(), Value::from("hello world"));

let output = engine.render("{title | shout}", ctx)?;
// → "HELLO WORLD!!!"

Most users should depend on the gracile crate instead, which re-exports this crate's public API under a cleaner name.