Shortcut for for statement

This commit is contained in:
Mike Angell
2019-08-28 05:11:10 +10:00
parent 3ef7eead27
commit 5b3e50f7ae
2 changed files with 14 additions and 4 deletions

View File

@@ -140,6 +140,16 @@ module Liquid
@scope[key][0] = val
end
def set_level(key, val, int)
@scope[key] ||= []
@scope[key][int] = val
end
def create_level(key)
(@scope[key] ||= [nil]) << nil
@scope[key].size - 1
end
def key?(key)
self[key] != nil
end

View File

@@ -163,13 +163,12 @@ module Liquid
begin
context['forloop'.freeze] = loop_vars
level = context.create_level(@variable_name)
segment.each do |item|
context[@variable_name] = item
context.set_level(@variable_name, item, level)
result << @for_block.render(context)
loop_vars.send(:increment!)
context.unset(@variable_name)
# Handle any interrupts if they exist.
if context.interrupt?
interrupt = context.pop_interrupt
@@ -177,9 +176,10 @@ module Liquid
next if interrupt.is_a? ContinueInterrupt
end
end
context.unset(@variable_name)
context.unset('forloop'.freeze)
ensure
for_stack.pop
end
end