summaryrefslogtreecommitdiff
path: root/src/eval/value.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-01-27 15:05:18 +0100
committerLaurenz <laurmaedje@gmail.com>2021-01-27 15:05:18 +0100
commit2036663ed25b5885a87eb3a80caec3fa2e258d77 (patch)
tree110ca98e4d76dc887b41c91685bb202c49730236 /src/eval/value.rs
parent2641c2d20ef5ddaf8e1dc91f4a69abfe2c170e4d (diff)
Capture variables in templates 🔍
Diffstat (limited to 'src/eval/value.rs')
-rw-r--r--src/eval/value.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/eval/value.rs b/src/eval/value.rs
index 6fa70206..6e838f6c 100644
--- a/src/eval/value.rs
+++ b/src/eval/value.rs
@@ -87,7 +87,14 @@ impl Eval for &Value {
ctx.push(ctx.make_text_node(match self {
Value::None => return,
Value::Str(s) => s.clone(),
- Value::Template(tree) => return tree.eval(ctx),
+ Value::Template(tree) => {
+ // We do not want to allow the template access to the current
+ // scopes.
+ let prev = std::mem::take(&mut ctx.scopes);
+ tree.eval(ctx);
+ ctx.scopes = prev;
+ return;
+ }
other => pretty(other),
}));
}
@@ -195,7 +202,7 @@ impl Deref for ValueFunc {
impl Pretty for ValueFunc {
fn pretty(&self, p: &mut Printer) {
- write!(p, "(function {})", self.name).unwrap();
+ p.push_str(&self.name);
}
}
@@ -515,7 +522,7 @@ mod tests {
test_pretty(Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), "#010101");
test_pretty("hello", r#""hello""#);
test_pretty(vec![Spanned::zero(Node::Strong)], "[*]");
- test_pretty(ValueFunc::new("nil", |_, _| Value::None), "(function nil)");
+ test_pretty(ValueFunc::new("nil", |_, _| Value::None), "nil");
test_pretty(ValueAny::new(1), "1");
test_pretty(Value::Error, "(error)");
}