Skip to content

Commit

Permalink
feat(for-block): Support iterating on Object
Browse files Browse the repository at this point in the history
Not the fastest implementation but it will do for now.

Fixes #201
  • Loading branch information
epage committed Oct 4, 2018
1 parent eb1fb68 commit 2469bfc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tags/for_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ fn get_array(context: &Context, array_id: &Argument) -> Result<Vec<Value>> {
let array = array_id.evaluate(context)?;
match array {
Value::Array(x) => Ok(x),
Value::Object(x) => {
let x = x
.iter()
.map(|(k, v)| {
Value::Array(vec![Value::scalar(k.as_ref().to_owned()), v.to_owned()])
}).collect();
Ok(x)
}
x => Err(unexpected_value_error("array", Some(x.type_name()))),
}
}
Expand Down

0 comments on commit 2469bfc

Please sign in to comment.