class Phlex::HTML
def _build_attributes(attributes, buffer:)
def _build_attributes(attributes, buffer:) attributes.each do |k, v| next unless v name = case k when String then k when Symbol then k.name.tr("_", "-") else k.to_s end # Detect unsafe attribute names. Attribute names are considered unsafe if they match an event attribute or include unsafe characters. if HTML::EVENT_ATTRIBUTES[name] || name.match?(/[<>&"']/) raise ArgumentError, "Unsafe attribute name detected: #{k}." end case v when true buffer << " " << name when String buffer << " " << name << '="' << ERB::Util.html_escape(v) << '"' when Symbol buffer << " " << name << '="' << ERB::Util.html_escape(v.name) << '"' when Hash _build_attributes(v.transform_keys { "#{k}-#{_1.name.tr('_', '-')}" }, buffer: buffer) else buffer << " " << name << '="' << ERB::Util.html_escape(v.to_s) << '"' end end buffer end