mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Push interrupts from Continue and Break tags rather than from BlockBody (#1286)
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user