class Phlex::SGML
def __build_attributes__(attributes, buffer:)
- Api: - private
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 raise ArgumentError, "Attribute keys should be Strings or Symbols." 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::Escape.html_escape(v) << '"' when Symbol buffer << " " << name << '="' << ERB::Escape.html_escape(v.name) << '"' when Hash __build_attributes__( v.transform_keys { |subkey| case subkey when Symbol then"#{k}-#{subkey.name.tr('_', '-')}" else "#{k}-#{subkey}" end }, buffer: buffer ) when Array buffer << " " << name << '="' << ERB::Escape.html_escape(v.compact.join(" ")) << '"' when Set buffer << " " << name << '="' << ERB::Escape.html_escape(v.to_a.compact.join(" ")) << '"' else raise ArgumentError, "Element attributes must be either a Boolean, a String, a Symbol, an Array of Strings or Symbols, or a Hash with values of one of these types" end end buffer end