Skip to content

Commit

Permalink
(feat) block params for each block [#42]
Browse files Browse the repository at this point in the history
Signed-off-by: Ning Sun <[email protected]>
  • Loading branch information
sunng87 committed Sep 9, 2016
1 parent c8c47df commit 5b95186
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/helpers/helper_each.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ impl HelperDef for EachHelper {
}

if let Some(block_param) = h.block_param() {
// need better impl
let mut map = BTreeMap::new();
map.insert(block_param.to_string(), list[i].to_json());
local_rc.push_block_context(&map);
Expand Down Expand Up @@ -88,6 +87,18 @@ impl HelperDef for EachHelper {
}

try!(t.render(c, r, &mut local_rc));
if let Some((bp_key, bp_val)) = h.block_param_pair() {
let mut map = BTreeMap::new();
map.insert(bp_key.to_string(), k.to_json());
map.insert(bp_val.to_string(), obj.get(k).unwrap().to_json());
local_rc.push_block_context(&map);
}

try!(t.render(c, r, &mut local_rc));

if h.block_param().is_some() {
local_rc.pop_block_context();
}
}

Ok(())
Expand Down Expand Up @@ -150,7 +161,18 @@ impl HelperDef for EachHelper {
debug!("each value {:?}", new_path);
local_rc.set_path(new_path);
}

if let Some(block_param) = h.block_param() {
let mut map = BTreeMap::new();
map.insert(block_param.to_string(), value::to_value(&list[i]));
local_rc.push_block_context(&map);
}

try!(t.render(c, r, &mut local_rc));

if h.block_param().is_some() {
local_rc.pop_block_context();
}
}
Ok(())
}
Expand All @@ -173,7 +195,19 @@ impl HelperDef for EachHelper {
local_rc.set_path(new_path);
}

if let Some((bp_key, bp_val)) = h.block_param_pair() {
let mut map = BTreeMap::new();
map.insert(bp_key.to_string(), value::to_value(&k));
map.insert(bp_val.to_string(),
value::to_value(&obj.get(k).unwrap()));
local_rc.push_block_context(&map);
}

try!(t.render(c, r, &mut local_rc));

if h.block_param().is_some() {
local_rc.pop_block_context();
}
}

Ok(())
Expand Down

0 comments on commit 5b95186

Please sign in to comment.