Class: REXML::Formatters::Pretty

Inherits:
Default
  • Object
show all
Defined in:
lib/rexml/formatters/pretty.rb

Overview

Pretty-prints an XML document. This destroys whitespace in text nodes and will insert carriage returns and indentations.

TODO: Add an option to print attributes on new lines

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Default

#write

Constructor Details

#initialize(indentation = 2, ie_hack = false) ⇒ Pretty

Create a new pretty printer.

output

An object implementing ‘<<(String)’, to which the output will be written.

indentation

An integer greater than 0. The indentation of each level will be this number of spaces. If this is < 1, the behavior of this object is undefined. Defaults to 2.

ie_hack

If true, the printer will insert whitespace before closing empty tags, thereby allowing Internet Explorer’s XML parser to function. Defaults to false.



30
31
32
33
34
35
36
# File 'lib/rexml/formatters/pretty.rb', line 30

def initialize( indentation=2, ie_hack=false )
  @indentation = indentation
  @level = 0
  @ie_hack = ie_hack
  @width = 80
  @compact = false
end

Instance Attribute Details

#compactObject

If compact is set to true, then the formatter will attempt to use as little space as possible



14
15
16
# File 'lib/rexml/formatters/pretty.rb', line 14

def compact
  @compact
end

#widthObject

The width of a page. Used for formatting text



16
17
18
# File 'lib/rexml/formatters/pretty.rb', line 16

def width
  @width
end