Add named? method to Cycle class for checking if the cycle is named

This commit is contained in:
Marco Concetto Rudilosso
2024-07-16 15:52:25 -04:00
committed by Ian Ker-Seymer
parent 77bc56a1c2
commit d36937d17f
+6
View File
@@ -26,14 +26,20 @@ module Liquid
when NamedSyntax when NamedSyntax
@variables = variables_from_string(Regexp.last_match(2)) @variables = variables_from_string(Regexp.last_match(2))
@name = parse_expression(Regexp.last_match(1)) @name = parse_expression(Regexp.last_match(1))
@is_named = true
when SimpleSyntax when SimpleSyntax
@variables = variables_from_string(markup) @variables = variables_from_string(markup)
@name = @variables.to_s @name = @variables.to_s
@is_named = !@name.match?(/\w+:0x\h{8}/)
else else
raise SyntaxError, options[:locale].t("errors.syntax.cycle") raise SyntaxError, options[:locale].t("errors.syntax.cycle")
end end
end end
def named?
@is_named
end
def render_to_output_buffer(context, output) def render_to_output_buffer(context, output)
context.registers[:cycle] ||= {} context.registers[:cycle] ||= {}