class Phlex::Component

def _build_attributes(attributes, buffer:)

def _build_attributes(attributes, buffer:)
  attributes.each do |k, v|
    next unless v
    name = case k
    when String
      k
    when Symbol
      k.name.tr("_", "-")
    else
      k.to_s
    end
    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 << '="' << CGI.escape_html(v) << '"'
    when Symbol
      buffer << " " << name << '="' << CGI.escape_html(v.name) << '"'
    when Hash
      _build_attributes(v.transform_keys { "#{k}-#{_1}" }, buffer: buffer)
    else
      buffer << " " << name << '="' << CGI.escape_html(v.to_s) << '"'
    end
  end
  buffer
end