Class: S33r::OrderlyXmlMarkup

Inherits:
Builder::XmlMarkup
  • Object
show all
Defined in:
lib/s33r/orderly_xml_markup.rb

Overview

Variant of XmlMarkup which explicitly orders attributes.

Instance Method Summary collapse

Instance Method Details

#_insert_attributes(attrs, order = []) ⇒ Object

Override Builder _insert_attributes so attributes are ordered.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/s33r/orderly_xml_markup.rb', line 8

def _insert_attributes(attrs, order=[])
  return if attrs.nil?
  order.each do |k|
    v = attrs[k]
    @target << %{ #{k}="#{_attr_value(v)}"} if v
  end
  attrs_sorted = attrs.sort { |x,y| x.to_s <=> y.to_s }
  attrs_sorted.each do |k, v|
    @target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k)
  end
end