Provide Block#new_body so that liquid-c can override it

This way liquid-c can return a body of a different class that wraps
a C implementation.
This commit is contained in:
Dylan Thacker-Smith
2020-09-08 13:59:48 -04:00
parent 6ca5b62112
commit bd33df09de
4 changed files with 14 additions and 8 deletions
+8 -2
View File
@@ -10,7 +10,7 @@ module Liquid
end end
def parse(tokens) def parse(tokens)
@body = BlockBody.new @body = new_body
while parse_body(@body, tokens) while parse_body(@body, tokens)
end end
end end
@@ -55,8 +55,14 @@ module Liquid
@block_delimiter ||= "end#{block_name}" @block_delimiter ||= "end#{block_name}"
end end
protected private
# @api public
def new_body
BlockBody.new
end
# @api public
def parse_body(body, tokens) def parse_body(body, tokens)
if parse_context.depth >= MAX_DEPTH if parse_context.depth >= MAX_DEPTH
raise StackLevelError, "Nesting too deep" raise StackLevelError, "Nesting too deep"
+3 -3
View File
@@ -19,7 +19,7 @@ module Liquid
end end
def parse(tokens) def parse(tokens)
body = BlockBody.new body = new_body
body = @blocks.last.attachment while parse_body(body, tokens) body = @blocks.last.attachment while parse_body(body, tokens)
if blank? if blank?
@blocks.each { |condition| condition.attachment.remove_blank_strings } @blocks.each { |condition| condition.attachment.remove_blank_strings }
@@ -59,7 +59,7 @@ module Liquid
private private
def record_when_condition(markup) def record_when_condition(markup)
body = BlockBody.new body = new_body
while markup while markup
unless markup =~ WhenSyntax unless markup =~ WhenSyntax
@@ -80,7 +80,7 @@ module Liquid
end end
block = ElseCondition.new block = ElseCondition.new
block.attach(BlockBody.new) block.attach(new_body)
@blocks << block @blocks << block
end end
+2 -2
View File
@@ -54,7 +54,7 @@ module Liquid
super super
@from = @limit = nil @from = @limit = nil
parse_with_selected_parser(markup) parse_with_selected_parser(markup)
@for_block = BlockBody.new @for_block = new_body
@else_block = nil @else_block = nil
end end
@@ -74,7 +74,7 @@ module Liquid
def unknown_tag(tag, markup, tokens) def unknown_tag(tag, markup, tokens)
return super unless tag == 'else' return super unless tag == 'else'
@else_block = BlockBody.new @else_block = new_body
end end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
+1 -1
View File
@@ -64,7 +64,7 @@ module Liquid
end end
@blocks.push(block) @blocks.push(block)
block.attach(BlockBody.new) block.attach(new_body)
end end
def lax_parse(markup) def lax_parse(markup)