mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-18 10:20:43 -07:00
Default Block#blank? to false regardless of whether the body is blank
This commit is contained in:
@@ -4,11 +4,6 @@ module Liquid
|
|||||||
class Block < Tag
|
class Block < Tag
|
||||||
MAX_DEPTH = 100
|
MAX_DEPTH = 100
|
||||||
|
|
||||||
def initialize(tag_name, markup, options)
|
|
||||||
super
|
|
||||||
@blank = true
|
|
||||||
end
|
|
||||||
|
|
||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
@body = BlockBody.new
|
@body = BlockBody.new
|
||||||
while parse_body(@body, tokens)
|
while parse_body(@body, tokens)
|
||||||
@@ -20,10 +15,6 @@ module Liquid
|
|||||||
@body.render(context)
|
@body.render(context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
|
||||||
@blank
|
|
||||||
end
|
|
||||||
|
|
||||||
def nodelist
|
def nodelist
|
||||||
@body.nodelist
|
@body.nodelist
|
||||||
end
|
end
|
||||||
@@ -64,8 +55,6 @@ module Liquid
|
|||||||
parse_context.depth += 1
|
parse_context.depth += 1
|
||||||
begin
|
begin
|
||||||
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
body.parse(tokens, parse_context) do |end_tag_name, end_tag_params|
|
||||||
@blank &&= body.blank?
|
|
||||||
|
|
||||||
return false if end_tag_name == block_delimiter
|
return false if end_tag_name == block_delimiter
|
||||||
unless end_tag_name
|
unless end_tag_name
|
||||||
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
|
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_never_closed", block_name: block_name)
|
||||||
|
|||||||
@@ -21,11 +21,16 @@ module Liquid
|
|||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
body = BlockBody.new
|
body = BlockBody.new
|
||||||
body = @blocks.last.attachment while parse_body(body, tokens)
|
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 }
|
@blocks.each { |condition| condition.attachment.remove_blank_strings }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blank?
|
||||||
|
@blank
|
||||||
|
end
|
||||||
|
|
||||||
def nodelist
|
def nodelist
|
||||||
@blocks.map(&:attachment)
|
@blocks.map(&:attachment)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -62,12 +62,17 @@ module Liquid
|
|||||||
if parse_body(@for_block, tokens)
|
if parse_body(@for_block, tokens)
|
||||||
parse_body(@else_block, tokens)
|
parse_body(@else_block, tokens)
|
||||||
end
|
end
|
||||||
if blank?
|
@blank = @for_block.blank? && (@else_block.nil? || @else_block.blank?)
|
||||||
|
if @blank
|
||||||
@for_block.remove_blank_strings
|
@for_block.remove_blank_strings
|
||||||
@else_block&.remove_blank_strings
|
@else_block&.remove_blank_strings
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blank?
|
||||||
|
@blank
|
||||||
|
end
|
||||||
|
|
||||||
def nodelist
|
def nodelist
|
||||||
@else_block ? [@for_block, @else_block] : [@for_block]
|
@else_block ? [@for_block, @else_block] : [@for_block]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,11 +31,16 @@ module Liquid
|
|||||||
def parse(tokens)
|
def parse(tokens)
|
||||||
while parse_body(@blocks.last.attachment, tokens)
|
while parse_body(@blocks.last.attachment, tokens)
|
||||||
end
|
end
|
||||||
if blank?
|
@blank = @blocks.all? { |condition| condition.attachment.blank? }
|
||||||
|
if @blank
|
||||||
@blocks.each { |condition| condition.attachment.remove_blank_strings }
|
@blocks.each { |condition| condition.attachment.remove_blank_strings }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blank?
|
||||||
|
@blank
|
||||||
|
end
|
||||||
|
|
||||||
def unknown_tag(tag, markup, tokens)
|
def unknown_tag(tag, markup, tokens)
|
||||||
if ['elsif', 'else'].include?(tag)
|
if ['elsif', 'else'].include?(tag)
|
||||||
push_block(tag, markup)
|
push_block(tag, markup)
|
||||||
|
|||||||
Reference in New Issue
Block a user