Skip to content

Commit

Permalink
Add Serializer#self_closing_tag? private method for easier overriding…
Browse files Browse the repository at this point in the history
… in subclasses
  • Loading branch information
jeremyevans committed Sep 12, 2024
1 parent 77458cb commit 0c12c48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
=== master

* Add Serializer#self_closing_tag? private method for easier overriding in subclasses (jeremyevans)

=== 2.6.0 (2024-06-18)

* Add Roda forme_erubi_capture_block plugin to support erubi/capture_block <%= form do %> <% end %> tags (jeremyevans)
Expand Down
8 changes: 7 additions & 1 deletion lib/forme/transformers/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Serializer
def call(tag)
case tag
when Tag
if SELF_CLOSING.include?(tag.type)
if self_closing_tag?(tag.type)
"<#{tag.type}#{attr_html(tag.attr)}/>"
else
"#{serialize_open(tag)}#{call(tag.children)}#{serialize_close(tag)}"
Expand Down Expand Up @@ -79,6 +79,12 @@ def attr_html(attr)
attr = attr.to_a.reject{|k,v| v.nil?}
" #{attr.map{|k, v| "#{k}=\"#{attr_value(v)}\""}.sort.join(' ')}" unless attr.empty?
end

# Return whether the tag is self closing. this can be overridden in subclasses
# to make additional types self closing.
def self_closing_tag?(type)
SELF_CLOSING.include?(type)
end
end

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

0 comments on commit 0c12c48

Please sign in to comment.