Skip to content

Commit 0c12c48

Browse files
committed
Add Serializer#self_closing_tag? private method for easier overriding in subclasses
1 parent 77458cb commit 0c12c48

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
=== master
2+
3+
* Add Serializer#self_closing_tag? private method for easier overriding in subclasses (jeremyevans)
4+
15
=== 2.6.0 (2024-06-18)
26

37
* Add Roda forme_erubi_capture_block plugin to support erubi/capture_block <%= form do %> <% end %> tags (jeremyevans)

lib/forme/transformers/serializer.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Serializer
1919
def call(tag)
2020
case tag
2121
when Tag
22-
if SELF_CLOSING.include?(tag.type)
22+
if self_closing_tag?(tag.type)
2323
"<#{tag.type}#{attr_html(tag.attr)}/>"
2424
else
2525
"#{serialize_open(tag)}#{call(tag.children)}#{serialize_close(tag)}"
@@ -79,6 +79,12 @@ def attr_html(attr)
7979
attr = attr.to_a.reject{|k,v| v.nil?}
8080
" #{attr.map{|k, v| "#{k}=\"#{attr_value(v)}\""}.sort.join(' ')}" unless attr.empty?
8181
end
82+
83+
# Return whether the tag is self closing. this can be overridden in subclasses
84+
# to make additional types self closing.
85+
def self_closing_tag?(type)
86+
SELF_CLOSING.include?(type)
87+
end
8288
end
8389

8490
# Overrides formatting of dates and times to use an American format without

0 commit comments

Comments
 (0)