mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Shortcut for for statement
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user