Class: Canon::PrettyPrinter::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/pretty_printer/xml.rb

Instance Method Summary collapse

Constructor Details

#initialize(indent: 2, indent_type: "space") ⇒ Xml

Returns a new instance of Xml.



8
9
10
11
# File 'lib/canon/pretty_printer/xml.rb', line 8

def initialize(indent: 2, indent_type: "space")
  @indent = indent.to_i
  @indent_type = indent_type
end

Instance Method Details

#format(xml_string) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/canon/pretty_printer/xml.rb', line 13

def format(xml_string)
  # Output parity: pretty-printed bytes are canon's product. The
  # leptris serializer matches Nokogiri byte-for-byte for space
  # and tab indentation (moxml#153/#155/#156) and runs faster
  # since moxml#158, with the #167 escaping race fixed in 0.5.28
  # — the fixture integrity suite and the CI performance gate are
  # the standing gates. Nokogiri serves the fallback engine and
  # Opal.
  if RUBY_ENGINE == "opal" || Canon::XmlBackend.moxml?
    moxml_format(xml_string)
  else
    nokogiri_format(xml_string)
  end
end