Class: Wunderbar::IndentedTextNode

Inherits:
TextNode show all
Defined in:
lib/wunderbar/node.rb

Constant Summary

Constants inherited from Node

Node::ESCAPE, Node::VOID

Instance Attribute Summary

Attributes inherited from Node

#attrs, #children, #name, #node, #parent, #text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TextNode

#initialize

Methods inherited from Node

#add_child, #initialize, #method_missing, #preserve_spaces?, #walk

Constructor Details

This class inherits a constructor from Wunderbar::TextNode

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Wunderbar::Node

Class Method Details

.reflow(indent, line, width, next_indent) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/wunderbar/node.rb', line 228

def self.reflow(indent, line, width, next_indent)
  return [line] unless width and indent
  line = indent + line.gsub(/\s+/, ' ').strip
  indent += next_indent

  result = []
  while line.length > width
    split = line.rindex(' ', width)
    break if not split or split <= indent.to_s.length
    result << line[0...split]
    line = "#{indent}#{line[split+1..-1]}"
  end

  result << line
end

Instance Method Details

#serialize(options, result, indent) ⇒ Object



244
245
246
247
248
249
250
251
252
253
# File 'lib/wunderbar/node.rb', line 244

def serialize(options, result, indent)
  if indent
    text = CDATANode.normalize(@text, indent)
  else
    text = @text
  end

  result.push *IndentedTextNode.reflow(indent, 
    text.to_s.gsub(/[&<>\u00A0]/,ESCAPE), options[:width], '')
end