Skip to main content

render

Function render 

Source
pub fn render(template: &str, policy: &LoadedPolicy) -> Result<String, String>
Expand description

Fill a template: {{DEFAULT_PROFILE}}, {{CHECKPOINT_DEFAULT}} and {{POLICY_SHA}} come from the policy; any other {{TOKEN}} is an error, because a template that asks for something the policy does not carry cannot be rendered deterministically.

use majordomus_cli::providers::render;
use majordomus_cli::policy::{LoadedPolicy, Policy, ProfilesPolicy};
let policy = LoadedPolicy {
    policy: Policy {
        profiles: ProfilesPolicy { default: Some("implementation".into()), checkpoint_interval_default: Some("15m".into()) },
        ..Policy::default()
    },
    path: ".ai/repo/policy.yaml".into(),
    sha256: "0123456789abcdef0123456789abcdef".into(),
};
assert_eq!(
    render("profile {{DEFAULT_PROFILE}}, every {{CHECKPOINT_DEFAULT}}, policy {{POLICY_SHA}}\n", &policy).unwrap(),
    "profile implementation, every 15m, policy 0123456789ab\n"
);
assert!(render("{{PROFILE_TABLE}}\n", &policy).unwrap_err().contains("PROFILE_TABLE"));