add obj unzip function

This commit is contained in:
kitsunecafe 2024-02-19 18:12:07 -05:00
parent ce0e44a976
commit 7780fb4b39
2 changed files with 27 additions and 11 deletions

22
Cargo.lock generated
View file

@ -34,9 +34,9 @@ dependencies = [
[[package]]
name = "anstream"
version = "0.6.11"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
checksum = "96b09b5178381e0874812a9b157f7fe84982617e48f71f4e3235482775e5b540"
dependencies = [
"anstyle",
"anstyle-parse",
@ -82,9 +82,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.79"
version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca"
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
[[package]]
name = "autocfg"
@ -855,7 +855,7 @@ dependencies = [
[[package]]
name = "roxy_markdown_tera_rewriter"
version = "0.1.0"
source = "git+https://fem.mint.lgbt/kitsunecafe/roxy-markdown-tera-rewriter.git#54cfd04c53f06679f6cb87abb3c11f4b09f673fa"
source = "git+https://fem.mint.lgbt/kitsunecafe/roxy-markdown-tera-rewriter.git#fa6f8b1fd674fa1ea1f6d914d01b609a170f7cba"
dependencies = [
"once_cell",
"regex",
@ -865,7 +865,7 @@ dependencies = [
[[package]]
name = "roxy_syntect"
version = "0.1.0"
source = "git+https://fem.mint.lgbt/kitsunecafe/roxy-syntect.git#4a872d3642a428fc91afe3a519e9e4d1f3a6d3d0"
source = "git+https://fem.mint.lgbt/kitsunecafe/roxy-syntect.git#0ac2f94b48cf8eb7f3b45076afa681e92d2be79f"
dependencies = [
"once_cell",
"regex",
@ -876,7 +876,7 @@ dependencies = [
[[package]]
name = "roxy_tera_parser"
version = "0.1.0"
source = "git+https://fem.mint.lgbt/kitsunecafe/roxy-tera-parser.git#13868747c22d09c6cd61bebb4dbb69e299be6bdb"
source = "git+https://fem.mint.lgbt/kitsunecafe/roxy-tera-parser.git#3f1f748f7d0f028071b040df340cbd7000843f36"
dependencies = [
"once_cell",
"regex",
@ -886,9 +886,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.16"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "safemem"
@ -1406,9 +1406,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "winnow"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d90f4e0f530c4c69f62b80d839e9ef3855edc9cba471a160c4d692deed62b401"
checksum = "7a4191c47f15cc3ec71fcb4913cb83d58def65dd3787610213c649283b5ce178"
dependencies = [
"memchr",
]

View file

@ -10,6 +10,22 @@ pub fn values(value: &Value, _args: &HashMap<String, Value>) -> Result<Value> {
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);
}