roxy_cli 0.1.2

A command-line static site generator
use std::collections::HashMap;
use tera::{to_value, try_get_value, Map, Result, Tera, Value};

pub fn values(value: &Value, _args: &HashMap<String, Value>) -> Result<Value> {
    let arr = try_get_value!("values", "value", Map<String, Value>, value)
        .into_iter()
        .map(|(_, x)| x)
        .collect();

    Ok(to_value::<Value>(arr)?)
}

pub fn unzip(value: &Value, _args: &HashMap<String, Value>) -> Result<Value> {
    let obj: Vec<Map<String, Value>> = try_get_value!("unzip", "value", Map<String, Value>, value)
        .into_iter()
        .map(|(k, v)| {
            let mut map = Map::new();
            map.insert(0.to_string(), k.into());
            map.insert(1.to_string(), v);
            map
        })
        .collect();

    Ok(to_value::<Value>(obj.into())?)

}

pub fn register_functions(tera: &mut Tera) {
    tera.register_filter("values", values);
    tera.register_filter("unzip", unzip);
}