feat: can traverse stuff
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
bbe630e822
commit
06ad4515c2
@ -146,8 +146,14 @@ impl minijinja::value::Object for CuddleVariables {
|
||||
|
||||
if let Some(val) = self.0.get(key) {
|
||||
match val {
|
||||
CuddleVariable::Object(_) => todo!(),
|
||||
CuddleVariable::Array(_) => todo!(),
|
||||
CuddleVariable::Object(object) => {
|
||||
let obj = object.deref().clone();
|
||||
|
||||
return Some(minijinja::Value::from_object(obj));
|
||||
}
|
||||
CuddleVariable::Array(arr) => {
|
||||
return Some(minijinja::Value::from_object(MiniJinjaList(arr.clone())))
|
||||
}
|
||||
CuddleVariable::String(str) => {
|
||||
return Some(minijinja::Value::from_safe_string(str.to_owned()))
|
||||
}
|
||||
@ -158,3 +164,29 @@ impl minijinja::value::Object for CuddleVariables {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct MiniJinjaList(Vec<CuddleVariable>);
|
||||
|
||||
impl minijinja::value::Object for MiniJinjaList {
|
||||
fn enumerate(self: &std::sync::Arc<Self>) -> minijinja::value::Enumerator {
|
||||
minijinja::value::Enumerator::Values(
|
||||
self.0
|
||||
.iter()
|
||||
.map(|i| match i {
|
||||
CuddleVariable::Object(object) => {
|
||||
let obj = object.deref().clone();
|
||||
|
||||
minijinja::Value::from_object(obj)
|
||||
}
|
||||
CuddleVariable::Array(arr) => {
|
||||
minijinja::Value::from_object(MiniJinjaList(arr.clone()))
|
||||
}
|
||||
CuddleVariable::String(str) => {
|
||||
minijinja::Value::from_safe_string(str.to_owned())
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
vars:
|
||||
service: service
|
||||
some:
|
||||
nested:
|
||||
item: something
|
||||
array:
|
||||
- item: item
|
||||
|
||||
|
||||
cuddle/clusters:
|
||||
dev:
|
||||
|
@ -1,2 +1,4 @@
|
||||
service: service
|
||||
|
||||
something: something
|
||||
items:
|
||||
- item
|
||||
|
@ -1,3 +1,7 @@
|
||||
service: {{ vars.cuddle_vars.service }}
|
||||
|
||||
something: {{ vars.cuddle_vars.some.nested.item }}
|
||||
items:
|
||||
{%- for val in vars.cuddle_vars.array %}
|
||||
- {{val.item}}
|
||||
{%- endfor %}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user