Sha256: b876fe96cf0a3dfdf3199dc52af863baa61e438b41f230c2f45a07cc73e24584

Contents?: true

Size: 582 Bytes

Versions: 5

Compression:

Stored size: 582 Bytes

Contents

require 'builder'

module S33r
  # Variant of XmlMarkup which explicitly orders attributes.
  class OrderlyXmlMarkup < Builder::XmlMarkup
  
    # Override Builder _insert_attributes so attributes are ordered.
    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
s33r-0.4 lib/s33r/builder.rb
s33r-0.4.1 lib/s33r/builder.rb
s33r-0.4.2 lib/s33r/builder.rb
s33r-0.5.1 lib/s33r/builder.rb
s33r-0.5 lib/s33r/builder.rb