Skip to content

Commit 866eb0c

Browse files
committed
fix(context): Reduce scope of public API
BREAKING CHANGE: `Context::get_val` is no longer public. Use `Context::get_val_by_index` instead.
1 parent e553f8a commit 866eb0c

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

liquid-interpreter/src/context.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,6 @@ impl<'g> Stack<'g> {
140140
};
141141
}
142142

143-
/// Gets a value from the rendering context.
144-
pub fn get_val<'a>(&'a self, name: &str) -> Option<&'a Value> {
145-
for frame in self.stack.iter().rev() {
146-
if let rval @ Some(_) = frame.get(name) {
147-
return rval;
148-
}
149-
}
150-
self.globals.and_then(|g| g.get(name))
151-
}
152-
153143
/// Recursively index into the stack.
154144
pub fn get_val_by_index<'i, I: Iterator<Item = &'i Index>>(
155145
&self,
@@ -174,6 +164,15 @@ impl<'g> Stack<'g> {
174164
})
175165
}
176166

167+
fn get_val<'a>(&'a self, name: &str) -> Option<&'a Value> {
168+
for frame in self.stack.iter().rev() {
169+
if let rval @ Some(_) = frame.get(name) {
170+
return rval;
171+
}
172+
}
173+
self.globals.and_then(|g| g.get(name))
174+
}
175+
177176
/// Sets a value in the global context.
178177
pub fn set_global_val<S>(&mut self, name: S, val: Value) -> Option<Value>
179178
where

src/tags/assign_tag.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mod test {
5757
use interpreter;
5858
use tags;
5959
use value::Value;
60+
use value::Index;
6061

6162
fn options() -> LiquidOptions {
6263
let mut options = LiquidOptions::default();
@@ -103,8 +104,8 @@ mod test {
103104

104105
let output = template.render(&mut context).unwrap();
105106
assert_eq!(
106-
context.stack().get_val("freestyle"),
107-
Some(&Value::scalar(false))
107+
context.stack().get_val_by_index([Index::with_key("freestyle")].iter()).unwrap(),
108+
&Value::scalar(false)
108109
);
109110
assert_eq!(output, "");
110111
}
@@ -124,8 +125,8 @@ mod test {
124125

125126
let output = template.render(&mut context).unwrap();
126127
assert_eq!(
127-
context.stack().get_val("freestyle"),
128-
Some(&Value::scalar(true))
128+
context.stack().get_val_by_index([Index::with_key("freestyle")].iter()).unwrap(),
129+
&Value::scalar(true)
129130
);
130131
assert_eq!(output, "<p>Freestyle!</p>");
131132
}

src/tags/capture_block.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ mod test {
6666
use super::*;
6767
use compiler;
6868
use interpreter;
69+
use value::Index;
6970

7071
fn options() -> LiquidOptions {
7172
let mut options = LiquidOptions::default();
@@ -95,8 +96,8 @@ mod test {
9596

9697
let output = template.render(&mut ctx).unwrap();
9798
assert_eq!(
98-
ctx.stack().get_val("attribute_name"),
99-
Some(&Value::scalar("potato-42-color"))
99+
ctx.stack().get_val_by_index([Index::with_key("attribute_name")].iter()).unwrap(),
100+
&Value::scalar("potato-42-color")
100101
);
101102
assert_eq!(output, "");
102103
}

0 commit comments

Comments
 (0)