Default Block#blank? to false regardless of whether the body is blank

This commit is contained in:
Dylan Thacker-Smith
2020-09-03 11:08:17 -04:00
parent 3b486425b0
commit f0da48495c
4 changed files with 18 additions and 14 deletions

View File

@@ -4,11 +4,6 @@ module Liquid
class Block < Tag
MAX_DEPTH = 100
def initialize(tag_name, markup, options)
super
@blank = true
end
def parse(tokens)
@body = BlockBody.new
while parse_body(@body, tokens)
@@ -20,10 +15,6 @@ module Liquid
@body.render(context)
end
def blank?
@blank
end
def nodelist
@body.nodelist
end
@@ -64,8 +55,6 @@ module Liquid
parse_context.depth += 1
begin
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
@blank &&= body.blank?
return false if end_tag_name == block_delimiter
unless end_tag_name
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)

View File

@@ -21,11 +21,16 @@ module Liquid
def parse(tokens)
body = BlockBody.new
body = @blocks.last.attachment while parse_body(body, tokens)
if blank?
@blank = @blocks.all? { |condition| condition.attachment.blank? }
if @blank
@blocks.each { |condition| condition.attachment.remove_blank_strings }
end
end
def blank?
@blank
end
def nodelist
@blocks.map(&:attachment)
end

View File

@@ -62,12 +62,17 @@ module Liquid
if parse_body(@for_block, tokens)
parse_body(@else_block, tokens)
end
if blank?
@blank = @for_block.blank? && (@else_block.nil? || @else_block.blank?)
if @blank
@for_block.remove_blank_strings
@else_block&.remove_blank_strings
end
end
def blank?
@blank
end
def nodelist
@else_block ? [@for_block, @else_block] : [@for_block]
end

View File

@@ -31,11 +31,16 @@ module Liquid
def parse(tokens)
while parse_body(@blocks.last.attachment, tokens)
end
if blank?
@blank = @blocks.all? { |condition| condition.attachment.blank? }
if @blank
@blocks.each { |condition| condition.attachment.remove_blank_strings }
end
end
def blank?
@blank
end
def unknown_tag(tag, markup, tokens)
if ['elsif', 'else'].include?(tag)
push_block(tag, markup)