module Phlex::Elements
def register_void_element(method_name, tag: method_name.name.tr("_", "-"), deprecated: false)
- Api: - private
def register_void_element(method_name, tag: method_name.name.tr("_", "-"), deprecated: false) if deprecated deprecation = <<~RUBY Kernel.warn "#{deprecated}" RUBY else deprecation = "" end class_eval(<<-RUBY, __FILE__, __LINE__ + 1) # frozen_string_literal: true def #{method_name}(**attributes) #{deprecation} context = @_context buffer = context.buffer fragment = context.fragments if fragment return if fragment.length == 0 # we found all our fragments already id = attributes[:id] if !context.in_target_fragment if fragment[id] context.begin_target(id) target_found = true else return nil end end end if attributes.length > 0 # with attributes buffer << "<#{tag}" << (Phlex::ATTRIBUTE_CACHE[respond_to?(:process_attributes) ? (attributes.hash + self.class.hash) : attributes.hash] || __attributes__(**attributes)) << ">" else # without attributes buffer << "<#{tag}>" end context.end_target if target_found nil end alias_method :_#{method_name}, :#{method_name} RUBY registered_elements[method_name] = tag method_name end