//! This example is based on the original mustache crate's example.
//! For an example that uses serde, see examples/serde.rs.

use std::collections::HashMap;

use mustache2::{
    Data,
    render::{RenderManager, SourceCache, provider::StaticProvider},
};

fn main() {
    // This object is required to satisfy the borrow checker, but you don't need to use it for anything else.
    let cache = SourceCache::default();
    let mut renderer = RenderManager::new(
        // You can use `FsProvider` to read files off the disk.
        StaticProvider(HashMap::from([("template", "Hello, {{name}}!\n")])),
        &cache,
    );
    let mut out = String::new();

    // Render the template, saying "Hello, Mercury!".
    if let Err(e) = renderer.render_to(
        &mut out,
        "template",
        Data::map_from([("name".into(), "Mercury".into())]),
    ) {
        renderer.display_error(e);
        return;
    }

    // Render it again, saying "Hello, Venus!".
    if let Err(e) = renderer.render_to(
        &mut out,
        "template",
        Data::map_from([("name".into(), "Venus".into())]),
    ) {
        renderer.display_error(e);
        return;
    }

    assert_eq!(out, "Hello, Mercury!\nHello, Venus!\n");
}
