Class: REXML::Formatters::Pretty
- Inherits:
-
Default
- Object
- Default
- REXML::Formatters::Pretty
- Defined in:
- lib/patches.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 Method Summary collapse
Instance Method Details
#wrap(string, width) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/patches.rb', line 12 def wrap(string, width) # p("wrap(" + string.to_s + "," + width.to_s + ")") # Recursively wrap string at width. return string if string.length <= width place = string.rindex(' ', width) # Position in string with last ' ' before cutoff return string unless place # too wide, but no spaces to break return string[0,place] + "\n" + wrap(string[place+1..-1], width) end |