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, #at, #initialize, #method_missing, parse_css_selector, #preserve_spaces?, #root, #search, #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



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/wunderbar/node.rb', line 322

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



338
339
340
341
342
343
344
345
346
347
# File 'lib/wunderbar/node.rb', line 338

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