Push interrupts from Continue and Break tags rather than from BlockBody (#1286)

This commit is contained in:
Dylan Thacker-Smith
2020-09-03 06:55:24 -04:00
committed by GitHub
parent 0740e8b431
commit b08bcf00ac
3 changed files with 15 additions and 16 deletions
+5 -12
View File
@@ -141,23 +141,16 @@ module Liquid
while (node = @nodelist[idx])
previous_output_size = output.bytesize
case node
when String
if node.instance_of?(String)
output << node
when Variable
elsif node.instance_of?(Variable)
render_node(context, output, node)
when Block
else
render_node(context, node.blank? ? +'' : output, node)
break if context.interrupt? # might have happened in a for-block
when Continue, Break
# If we get an Interrupt that means the block must stop processing. An
# Interrupt is any command that stops block execution such as {% break %}
# or {% continue %}
context.push_interrupt(node.interrupt)
break
else # Other non-Block tags
render_node(context, output, node)
break if context.interrupt? # might have happened through an include
# or {% continue %}. These tags may also occur through Block or Include tags.
break if context.interrupt? # might have happened in a for-block
end
idx += 1
+5 -2
View File
@@ -11,8 +11,11 @@ module Liquid
# {% endfor %}
#
class Break < Tag
def interrupt
BreakInterrupt.new
INTERRUPT = BreakInterrupt.new.freeze
def render_to_output_buffer(context, output)
context.push_interrupt(INTERRUPT)
output
end
end
+5 -2
View File
@@ -11,8 +11,11 @@ module Liquid
# {% endfor %}
#
class Continue < Tag
def interrupt
ContinueInterrupt.new
INTERRUPT = ContinueInterrupt.new.freeze
def render_to_output_buffer(context, output)
context.push_interrupt(INTERRUPT)
output
end
end