Skip to content

Commit 28b0cc2

Browse files
charlespwdclaude
andcommitted
Derive block_form? from @Body presence instead of tracking separately
@Body is only set in reparent_as_block, so it already encodes whether the tag is in block form. Remove the redundant @block_form flag. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent afed2f2 commit 28b0cc2

3 files changed

Lines changed: 25 additions & 20 deletions

File tree

History.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Liquid Change Log
22

3+
## 5.12.0
4+
* Introduce HybridTag base class for tags that can be self-closing or block-form, with end-tag-triggered reparenting in BlockBody [CP Clermont]
5+
36
## 5.11.0
47
* Revert the Inline Snippets tag (#2001), treat its inclusion in the latest Liquid release as a bug, and allow for feedback on RFC#1916 to better support Liquid developers [Guilherme Carreiro]
58
* Rename the `:rigid` error mode to `:strict2` and display a warning when users attempt to use the `:rigid` mode [Guilherme Carreiro]

lib/liquid/block_body.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ def freeze
5252
next parse_liquid_tag(markup, parse_context)
5353
end
5454

55-
unless (tag = parse_context.environment.tag_for_name(tag_name))
56-
if try_reparent_hybrid_tag(tag_name, parse_context)
57-
parse_context.line_number = tokenizer.line_number
58-
next
59-
end
60-
# end parsing if we reach an unknown tag and let the caller decide
61-
# determine how to proceed
62-
return yield tag_name, markup
55+
tag = parse_context.environment.tag_for_name(tag_name)
56+
57+
if tag.nil? && try_reparent_hybrid_tag(tag_name, parse_context)
58+
parse_context.line_number = tokenizer.line_number
59+
next
6360
end
61+
62+
# end parsing if we reach an unknown tag and let the caller decide
63+
# determine how to proceed
64+
return yield tag_name, markup unless tag
65+
6466
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
6567
@blank &&= new_tag.blank?
6668
@nodelist << new_tag
@@ -151,15 +153,17 @@ def self.rescue_render_node(context, output, line_number, exc, blank_tag)
151153
next
152154
end
153155

154-
unless (tag = parse_context.environment.tag_for_name(tag_name))
155-
if try_reparent_hybrid_tag(tag_name, parse_context)
156-
parse_context.line_number = tokenizer.line_number
157-
next
158-
end
159-
# end parsing if we reach an unknown tag and let the caller decide
160-
# determine how to proceed
161-
return yield tag_name, markup
156+
tag = parse_context.environment.tag_for_name(tag_name)
157+
158+
if tag.nil? && try_reparent_hybrid_tag(tag_name, parse_context)
159+
parse_context.line_number = tokenizer.line_number
160+
next
162161
end
162+
163+
# end parsing if we reach an unknown tag and let the caller decide
164+
# determine how to proceed
165+
return yield tag_name, markup unless tag
166+
163167
new_tag = tag.parse(tag_name, markup, tokenizer, parse_context)
164168
@blank &&= new_tag.blank?
165169
@nodelist << new_tag

lib/liquid/hybrid_tag.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
module Liquid
44
class HybridTag < Block
55
def reparent_as_block(children, parse_context)
6-
@block_form = true
76
@body = new_body
87
@body.nodelist.concat(children)
98
@body.freeze
109
end
1110

1211
def parse(_tokens)
13-
@block_form = false
1412
end
1513

1614
def block_form?
17-
@block_form
15+
!!@body
1816
end
1917

2018
def nodelist
@@ -26,7 +24,7 @@ def blank?
2624
end
2725

2826
def render_to_output_buffer(context, output)
29-
if @block_form
27+
if block_form?
3028
render_block_form_to_output_buffer(context, output)
3129
else
3230
render_self_closing_to_output_buffer(context, output)

0 commit comments

Comments
 (0)