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]) while (node = @nodelist[idx])
previous_output_size = output.bytesize previous_output_size = output.bytesize
case node if node.instance_of?(String)
when String
output << node output << node
when Variable elsif node.instance_of?(Variable)
render_node(context, output, node) render_node(context, output, node)
when Block else
render_node(context, node.blank? ? +'' : output, node) 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 # If we get an Interrupt that means the block must stop processing. An
# Interrupt is any command that stops block execution such as {% break %} # Interrupt is any command that stops block execution such as {% break %}
# or {% continue %} # or {% continue %}. These tags may also occur through Block or Include tags.
context.push_interrupt(node.interrupt) break if context.interrupt? # might have happened in a for-block
break
else # Other non-Block tags
render_node(context, output, node)
break if context.interrupt? # might have happened through an include
end end
idx += 1 idx += 1
+5 -2
View File
@@ -11,8 +11,11 @@ module Liquid
# {% endfor %} # {% endfor %}
# #
class Break < Tag class Break < Tag
def interrupt INTERRUPT = BreakInterrupt.new.freeze
BreakInterrupt.new
def render_to_output_buffer(context, output)
context.push_interrupt(INTERRUPT)
output
end end
end end
+5 -2
View File
@@ -11,8 +11,11 @@ module Liquid
# {% endfor %} # {% endfor %}
# #
class Continue < Tag class Continue < Tag
def interrupt INTERRUPT = ContinueInterrupt.new.freeze
ContinueInterrupt.new
def render_to_output_buffer(context, output)
context.push_interrupt(INTERRUPT)
output
end end
end end