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
# File 'lib/canon/pretty_printer/xml.rb', line 13

def format(xml_string)
  # Output parity: pretty-printed bytes are canon's product. The
  # moxml serializer cannot yet match Nokogiri's output (empty
  # element expansion, declaration placement, tab indent), so the
  # Nokogiri pipeline is used whenever available — the moxml branch
  # is the Opal fallback.
  if defined?(Nokogiri)
    nokogiri_format(xml_string)
  else
    moxml_format(xml_string)
  end
end