File tree Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -140,16 +140,6 @@ impl<'g> Stack<'g> {
140
140
} ;
141
141
}
142
142
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
-
153
143
/// Recursively index into the stack.
154
144
pub fn get_val_by_index < ' i , I : Iterator < Item = & ' i Index > > (
155
145
& self ,
@@ -174,6 +164,15 @@ impl<'g> Stack<'g> {
174
164
} )
175
165
}
176
166
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
+
177
176
/// Sets a value in the global context.
178
177
pub fn set_global_val < S > ( & mut self , name : S , val : Value ) -> Option < Value >
179
178
where
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ mod test {
57
57
use interpreter;
58
58
use tags;
59
59
use value:: Value ;
60
+ use value:: Index ;
60
61
61
62
fn options ( ) -> LiquidOptions {
62
63
let mut options = LiquidOptions :: default ( ) ;
@@ -103,8 +104,8 @@ mod test {
103
104
104
105
let output = template. render ( & mut context) . unwrap ( ) ;
105
106
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 )
108
109
) ;
109
110
assert_eq ! ( output, "" ) ;
110
111
}
@@ -124,8 +125,8 @@ mod test {
124
125
125
126
let output = template. render ( & mut context) . unwrap ( ) ;
126
127
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 )
129
130
) ;
130
131
assert_eq ! ( output, "<p>Freestyle!</p>" ) ;
131
132
}
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ mod test {
66
66
use super :: * ;
67
67
use compiler;
68
68
use interpreter;
69
+ use value:: Index ;
69
70
70
71
fn options ( ) -> LiquidOptions {
71
72
let mut options = LiquidOptions :: default ( ) ;
@@ -95,8 +96,8 @@ mod test {
95
96
96
97
let output = template. render ( & mut ctx) . unwrap ( ) ;
97
98
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" )
100
101
) ;
101
102
assert_eq ! ( output, "" ) ;
102
103
}
You can’t perform that action at this time.
0 commit comments