Skip to content

Commit

Permalink
Merge pull request #203 from epage/for
Browse files Browse the repository at this point in the history
feat(for-block): Support iterating on Object
  • Loading branch information
epage authored Oct 4, 2018
2 parents eb1fb68 + 2469bfc commit 30646d3
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 30646d3

Please sign in to comment.