Add end tag support (#1823)

This commit is contained in:
CP Clermont
2024-09-10 11:23:53 -04:00
committed by GitHub
parent 0b9318222b
commit 27ead517ee
10 changed files with 61 additions and 6 deletions
+7 -3
View File
@@ -34,7 +34,7 @@ module Liquid
end
# @api private
def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context)
def self.raise_unknown_tag(tag, block_name, block_delimiter, parse_context, supports_end_tag = true)
if tag == 'else'
raise SyntaxError, parse_context.locale.t(
"errors.syntax.unexpected_else",
@@ -42,7 +42,7 @@ module Liquid
)
elsif tag.start_with?('end')
raise SyntaxError, parse_context.locale.t(
"errors.syntax.invalid_delimiter",
supports_end_tag ? "errors.syntax.invalid_delimiter" : "errors.syntax.invalid_delimiter_no_end",
tag: tag,
block_name: block_name,
block_delimiter: block_delimiter,
@@ -64,6 +64,10 @@ module Liquid
@block_delimiter ||= "end#{block_name}"
end
def supports_end_tag?
true
end
private
# @api public
@@ -81,7 +85,7 @@ module Liquid
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 || (supports_end_tag? && end_tag_name == 'end')
raise_tag_never_closed(block_name) unless end_tag_name
# this tag is not registered with the system
+1 -1
View File
@@ -68,7 +68,7 @@ module Liquid
# @api private
def self.unknown_tag_in_liquid_tag(tag, parse_context)
Block.raise_unknown_tag(tag, 'liquid', '%}', parse_context)
Block.raise_unknown_tag(tag, 'liquid', '%}', parse_context, false)
end
# @api private
+2 -1
View File
@@ -14,7 +14,8 @@
if: "Syntax Error in tag 'if' - Valid syntax: if [expression]"
include: "Error in tag 'include' - Valid syntax: include '[template]' (with|for) [object|collection]"
inline_comment_invalid: "Syntax error in tag '#' - Each line of comments must be prefixed by the '#' character"
invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
invalid_delimiter: "'%{tag}' is not a valid delimiter for %{block_name} tags. use end or %{block_delimiter}"
invalid_delimiter_no_end: "'%{tag}' is not a valid delimiter for %{block_name} tags. use %{block_delimiter}"
render: "Syntax error in tag 'render' - Template name must be a quoted string"
table_row: "Syntax Error in 'table_row loop' - Valid syntax: table_row [item] in [collection] cols=3"
tag_never_closed: "'%{block_name}' tag was never closed"
+4
View File
@@ -22,6 +22,10 @@ module Liquid
def unknown_tag(_tag, _markup, _tokens)
end
def supports_end_tag?
false
end
def blank?
true
end
+4
View File
@@ -22,6 +22,10 @@ module Liquid
ensure_valid_markup(tag_name, markup, parse_context)
end
def supports_end_tag?
false
end
def parse(tokens)
@body = +''
while (token = tokens.shift)