Support for pretty formatting XML documents

Similar to REXML it would be nice if Oga had a way to spit out a pretty formatted XML document including correct indentation and all that.

Spec (as of June 27th, 2017)

  • to_xml on the various node types should take a **kwargs argument which is passed to XML::Generator#initialize
  • XML::Generator#initialize should take two additional keyword arguments: pretty (default false) and indent (default 4 spaces), producing the argument list initialize(root, pretty: false, indent: ' ')
  • A user should be possible to specify its own indent string in to_xml using to_xml(indent: ' ') to indent with 2 spaces or to_xml(indent: "\t") to indent with tabs
  • If pretty is true then XML is pretty printed, and for every element we descend into we add an indentation level. The easiest way is to keep track of an indent counter which is passed down into the methods called for generating the XML of elements
  • Tests can be added to spec/oga/xml/generator_spec.rb in the #to_xml describe block